Css div后的向下箭头未居中

Css div后的向下箭头未居中,css,html,Css,Html,我刚刚做了这个div 但是在插入新的div后,div后面的箭头没有居中对齐 HTML <div id="hero_intro"> <div class="quote">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div> </div> 添加左侧:50%到#英雄(简介)css之后。父容器必须是位置:相对明显。添加左侧:50%到#英雄

我刚刚做了这个
div

但是在插入新的
div
后,div后面的箭头没有居中对齐

HTML

<div id="hero_intro">
    <div class="quote">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
</div>

添加<代码>左侧:50%
#英雄(简介)
css之后。父容器必须是
位置:相对
明显。

添加
左侧:50%
#英雄(简介)
css之后。父容器必须是
位置:相对
明显。

使其
左:50%这将使它居中,但不完全居中,因此使用
左边距:-20px即定位三角形的总宽度的1/2

注意:确保使用
position:relative,然后相应地定位元素。。也可以使用
bottom
属性,而不是
margin-top

更好的解决方案是,不管元素的高度如何,去掉
边距顶部,并指定
位置:相对到父容器


使其
左:50%这将使它居中,但不完全居中,因此使用
左边距:-20px即定位三角形的总宽度的1/2

注意:确保使用
position:relative,然后相应地定位元素。。也可以使用
bottom
属性,而不是
margin-top

更好的解决方案是,不管元素的高度如何,去掉
边距顶部,并指定
位置:相对到父容器

以下是修复方法:

其余的你可以在fiddler中找到,这里是修复程序:


其余的你可以在fiddler中找到,请在这里发布HTML/CSS。它包含在JSFIDLE链接中。请在这里发布HTML/CSS。它包含在JSFIDLE链接中
#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;
}
#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;
}
#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;
}
#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; }