Krullmizter
Krullmizter

Reputation: 567

Borders to take up just element not pseudo element

I'm making a website where I would like to have some borders besides some text. And above it, some icons. What I want is for the border to only occupy the text area of the LinkedIn text, not the entire class. I've tried with position: absolute but gotten nowhere.

.contactSocial {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.facebook:before {
  display: flex;
  justify-content: center;
  content: "\f39e";
  font-family: "Font Awesome 5 Brands";
  font-weight: 900;
  color: blue;
}
 
.linkedIn {
  border-right: 2px solid green;
  border-left: 2px solid green;
}

.linkedIn:before {
 display: flex;
 justify-content: center;
 content: "\f0e1";
 font-family: "Font Awesome 5 Brands";
 font-weight: 900;
 color: blue;
}
 
.instagram:before {
  display: flex;
  justify-content: center;
  content: "\f16d";
  font-family: "Font Awesome 5 Brands";
  font-weight: 900;
  color: blue;
}
<head><link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
</head>

<div class="contactSocial">
  <div class="facebook">Facebook</div>
  <div class="linkedIn">LinkedIn</div>
  <div class="instagram">Instagram</div>
</div>

Upvotes: 1

Views: 243

Answers (3)

kukkuz
kukkuz

Reputation: 42362

If you'd change you markup, the simplest thing would be to wrap the labels into a span and apply the border to these span element - see demo below:

.contactSocial {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.facebook:before {
  display: flex;
  justify-content: center;
  content: "\f39e";
  font-family: "Font Awesome 5 Brands";
  font-weight: 900;
  color: blue;
}
 
.linkedIn span { /* CHANGED */
  border-right: 2px solid green;
  border-left: 2px solid green;
}

.linkedIn:before {
 display: flex;
 justify-content: center;
 content: "\f0e1";
 font-family: "Font Awesome 5 Brands";
 font-weight: 900;
 color: blue;
}
 
.instagram:before {
  display: flex;
  justify-content: center;
  content: "\f16d";
  font-family: "Font Awesome 5 Brands";
  font-weight: 900;
  color: blue;
}
<head><link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
</head>

<div class="contactSocial">
  <div class="facebook"><span>Facebook</span></div>
  <div class="linkedIn"><span>LinkedIn</span></div>
  <div class="instagram"><span>Instagram</span></div>
</div>

Upvotes: 2

I think you want this. If it's not, tell me.

.contactSocial {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.facebook:before {
  position: absolute;
  display: flex;
  justify-content: center;
  content: "\f39e";
  font-family: "Font Awesome 5 Brands";
  font-weight: 900;
  color: blue;
}
 
.linkedIn {
  border-right: 2px solid green;
  border-left: 2px solid green;
  position: relative;
}

.linkedIn:before {
 display: flex;
 justify-content: center;
 content: "\f0e1";
 font-family: "Font Awesome 5 Brands";
 font-weight: 900;
 color: blue;
 position: absolute;
 width: 100%;
 bottom: 90%;
}
 
.instagram:before {
  display: flex;
  justify-content: center;
  content: "\f16d";
  font-family: "Font Awesome 5 Brands";
  font-weight: 900;
  color: blue;
}
<head><link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
</head>

<div class="contactSocial">
  <div class="facebook">Facebook</div>
  <div class="linkedIn">LinkedIn</div>
  <div class="instagram">Instagram</div>
</div>

Upvotes: 0

Persijn
Persijn

Reputation: 14990

Icon and text border

Move the icons outside of the tekst element.
Then set a border on the tekst element.

.contactSocial {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.iconFacebook:before {
  display: flex;
  justify-content: center;
  content: "\f39e";
  font-family: "Font Awesome 5 Brands";
  font-weight: 900;
  color: blue;
}
.facebook {
  border: 5px solid cornflowerblue;
}
<head><link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
</head>

<div class="contactSocial">
  <div>
    <div class="iconFacebook"></div>
    <div class="facebook">Facebook</div>
  </div>
  <div class="linkedIn">LinkedIn</div>
  <div class="instagram">Instagram</div>
</div>

Upvotes: 1

Related Questions