Reputation: 5953
I am trying to find creative ways to do page-headers, because the typical ones are boring, in my opinion.
Here is what I found:
Are those two separated <hr />
elements with a <span class="glyphicon glyphicon-star></span>
in between?
I have tried but can't figure out how to do it so that it is dynamic. I don't want to have to adjust the css if the <h1>
is longer than About (in the pic).
Here is what I have:
HTML:
<div class="container">
<h1 class="text-center">About</h1>
<hr class="new-hr" />
<span class="glyphicon glyphicon-star"></span>
<hr class="new-hr"/>
</div>
CSS:
.new-hr{
width: 20%
}
I have also created a codepen.
Can someone help me recreate this?
Any help is appreciated.
Upvotes: 2
Views: 3405
Reputation: 122135
You can first create h1
element with span
that will have star inside it. And to add lines you can use :after
and :before
pseudo-elements on span
h1 {
font-size: 20px;
display: inline-flex;
flex-direction: column;
margin: 10px 35px;
}
h1 > span {
font-size: 20px;
display: flex;
align-items: center;
justify-content: center;
}
span:after, span:before {
content: '';
background: black;
height: 1px;
flex: 0 0 60%;
margin: 0 10px;
}
<h1>ABOUT<span>★</span></h1><br>
<h1>LOREM IPSUM<span>★</span></h1>
You can also do this without Flexbox
using position: absolute
to position pseudo-elements.
h1 {
font-size: 20px;
text-align: center;
margin: 10px 35px;
display: inline-block;
}
h1 > span {
font-size: 20px;
position: relative;
display: block;
}
span:after, span:before {
content: '';
background: black;
height: 1px;
width: 50%;
position: absolute;
top: 50%;
transform: translateY(-50%);
}
span:before {
left: -15px;
}
span:after {
right: -15px;
}
<h1>ABOUT<span>★</span></h1><br>
<h1>LOREM IPSUM<span>★</span></h1>
Upvotes: 1
Reputation: 31
Im not sure if this is the best approach, but this should work.
<div class="container">
<div class ="text-center">
<h1 class="text">About</h1>
<div class="icon">
<span class="glyphicon glyphicon-star"></span>
</div>
</div>
</div>
.text-center{
background: #6DD286;
padding: 1px 10px 10px;
color: #fff;
position: relative;
}
.text {
border-bottom: 3px solid #fff;
padding-bottom: 10px;
}
.icon {
background: #6DD286;
position: absolute;
bottom: 10px;
margin-left: 50%;
transform: translateX(-100%);
padding: 0 5px;
}
Upvotes: 0
Reputation: 22959
You could give the heading a border, then add the star as a pseudoelement and position it in the center of the border...
body {
background-color: lightgreen !important;
}
.border {
display: table;
margin: 10px auto;
border-bottom: 5px solid #FFF;
position: relative;
padding: 15px 20px;
color: #FFF;
text-transform: uppercase;
}
.border::after {
position: absolute;
font-family: "Glyphicons Halflings";
content: "\e006";
width: 28px;
left: 0;
right: 0;
bottom: -18px;
margin: auto;
font-size: 20px;
color: #FFF;
background: lightgreen;
padding: 5px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<h1 class="text-center border">About</h1>
</div>
Upvotes: 0
Reputation: 351
I did something exactly like this for the KTSW radio station (demo) using an hr
, hr::after
and a background image.
Here is a Fiddle and an embedded example below.
body {
background: white;
}
hr {
background: #ebebeb;
margin: 5rem 0;
position: initial;
margin: 2rem 0;
height: 1px;
border: 0px solid #fff;
}
hr:after {
background: url(http://txstate.edu/prospectiveflash/ktsw/boombox-hr.jpg) no-repeat top center;
content: "";
display: block;
height: 40px;
position: relative;
top: -20px;
background-size: 80px;
}
<div class="separator">
<hr>
</div>
Upvotes: 0
Reputation: 8698
How about this:
Put a div
with a bottom border, and the set the span containing the star to position:relative and move it down over the div.
body {background: #fff;}
.underline {
width: 100%;
border-bottom: 4px solid #000;
text-align: center;
position: relative;
}
.underline span {
position: relative;
top: 15px;
padding: 0 10px;
background: #fff;
font-size:25px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="underline">
<span>
<i class="fa fa-star" aria-hidden="true"></i>
</span>
</div>
Upvotes: 1