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; }