Reputation: 371
I've just made this div
But the arrow after the div
is not center aligned, once I insert the new div
inside
HTML
<div id="hero_intro">
<div class="quote">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
</div>
CSS
#hero_intro {
background: #f18c22;
height: 150px;
text-align: center;
color:#fff;
z-index: 5000;
font-size: 32px;
}
#hero_intro:after {
content:'';
position: absolute;
width: 0;
height: 0;
margin-top: 150px;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #f18c22;
}
#hero_intro .quote {
width: 80%;
margin-top: 30px;
display: inline-block;
text-align: center;
line-height: 1.2em;
color:#fff;
}
Upvotes: 1
Views: 1500
Reputation: 157324
Make it left: 50%;
which will make it center but not center exactly, so use margin-left: -20px;
i.e 1/2 of total width
of the absolute
positioned triangle.
#hero_intro:after {
content: '';
position: absolute;
width: 0;
height: 0;
margin-top: 150px;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #f18c22;
left: 50%; /*Add these*/
margin-left: -20px;
}
Note: Make sure you use
position: relative;
for the parent container and thenposition
the element accordingly.. Also usebottom
attribute instead ofmargin-top
Better Solution, regardless of height
of your element, getting rid of margin-top
and assigning position: relative;
to the parent container.
#hero_intro {
background: #f18c22;
height: 150px;
text-align: center;
color:#fff;
z-index: 5000;
font-size: 32px;
position: relative;
}
#hero_intro:after {
content:'';
position: absolute;
width: 0;
height: 0;
bottom: -20px;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #f18c22;
left: 50%;
margin-left: -20px;
}
#hero_intro .quote {
width: 80%;
margin-top: 30px;
display: inline-block;
text-align: center;
line-height: 1.2em;
color:#fff;
}
Upvotes: 2
Reputation: 566
here is the fix: http://jsfiddle.net/K5qdc/3/
#hero_intro{
background: #f18c22 ;
height: 150px;
text-align: center;
color:#fff;
z-index: 5000;
font-size: 32px; }
#hero_intro:after {
content: '';
position: absolute;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #f18c22;
bottom: 28px;
left:0;
margin: 0 auto;
right:0; }
the rest you can find it in fiddler
Upvotes: 0
Reputation: 9512
Add left: 50%;
to #hero_intro:after
css. The parent container has to be position: relative
obviously.
Upvotes: 2