0

I am trying to replicate the effect where a text is surrounded by the centered border with padding around it. Example. Despite trying to use the same method as above site, the border covers the text; I must be doing something wrong which I cannot spot.

I will appreciate your help.

.header {
  color:black;
  font-size:3rem;
  line-height:1.5;
}

 .header p {
  width:75%;
  position: relative;
  text-transform: uppercase;
  text-align:center;
}

 .header p::before {
  display:block;
  content:'';
  width:100%;
  position: absolute;
  background:#000;
  height:3px;
  top:50%;
}

 .header p > span{
  padding:0 1rem; 
  display:inline-block;
  max-width:75%;
  position: relative;
}
<div class="header">
   <p><span>Work</span></p>
</div>

This is the result I want to get.

enter image description here

Jun Jung
  • 405
  • 5
  • 19

2 Answers2

1

added

.header p {
      position: relative;
      text-transform: uppercase;
      text-align: center;
      display: inline-block;
      padding: 40px;
      border: 3px solid black;
      margin-left: 50%;
      transform: translatex(-50%);
    }

removed :before css, removed width used display: inline-block and used padding to give space between the text and the border. and used margin and transform property to bring it in the center

.header {
  color:black;
  font-size:3rem;
  line-height:1.5;
}

 .header p {
  position: relative;
  text-transform: uppercase;
  text-align: center;
  display: inline-block;
  padding: 40px;
  border: 3px solid black;
  margin-left: 50%;
  transform: translatex(-50%);
}

 /*.header p::before {
  display:block;
  content:'';
  width:100%;
  position: absolute;
  background:#000;
  height:3px;
  top:50%;
}*/

 .header p > span{
  padding:0 1rem; 
  display:inline-block;
  max-width:75%;
  position: relative;
}
<div class="header">
  <p><span>Work</span></p>
 </div>
Xenio Gracias
  • 2,728
  • 1
  • 9
  • 16
  • Sorry maybe I did not clearly stated what I wanted as English is my second language. Could you check the updated post? – Jun Jung Feb 22 '19 at 05:34
1

you just need background color on span

.header {
  color:black;
  font-size:3rem;
  line-height:1.5;
}

 .header p {
  width:75%;
  position: relative;
  text-transform: uppercase;
  text-align:center;
}
.header p::before {
  display:block;
  content:'';
  width:100%;
  position: absolute;
  background:#000;
  height:3px;
  top:50%;
z-index:0;
}

 .header p > span{
  padding:0 1rem; 
  display:inline-block;
  max-width:75%;
  position: relative; 
  background-color:#fff;
z-index:1;
}
<div class="header">
  <p><span>Work</span></p>
 </div>
Piyush Verma
  • 285
  • 1
  • 8