我正在使用Font Awesome库。我想将箭头图标水平居中。DIV必须采用绝对定位。
我使用了以下代码,但它并不起作用:
我使用了以下代码,但它并不起作用:
.arrow {
left: 0;
right: 0;
}
.arrow {
left: 0;
right: 0;
}
width:100%
.home .center {
position: absolute;
bottom: 0;
top:30px;
text-align: center;
width:100%;
}
更新的演示代码
.home {
margin: 0 auto;
height: 100%;
width: 100%;
position: relative;
margin: 0 auto;
max-width: 960px;
}
.home .center {
position: absolute;
width: 100%;
bottom: 0;
top:30px;
text-align: center;
}
HTML代码:
<div class="home">
<div class="center">
<a class="arrow fa fa-long-arrow-down fa-3x" href="#"></a>
</div>
</div>
.home {
margin: 0 auto;
height: 100%;
width: 100%;
position: relative;
margin: 0 auto;
max-width: 960px;
}
.home .center {
position: absolute;
bottom: 0;
top:30px;
text-align: center;
}
.arrow {
}
position: fix;
嗯?!我想你的意思是 fixed
。 - Hashem Qolami这应该可以工作,请尝试。
.home {
margin: 0 auto;
height: 100%;
width: 100%;
position: absolute;
margin: 0 auto;
max-width: 960px;
}
.center {
position: relative;
bottom: 0;
top:30px;
text-align: center;
}
.arrow
left: 0;
right: 0;
我刚刚把你的CSS换上去了,它工作得很好。
.home {
margin: 0 auto;
}
.home .center {
margin: 0 auto;
text-align: center;
}
.arrow
margin: 0 auto;
}
干杯!
left: 0; right: 0;
移动到绝对定位的父级 div 中。 - Hashem Qolamidiv
为绝对定位,请给它一个适当的宽度。从技术上讲,箭头已经居中了,因为您已经给父级div
设置了text-align:center;
。 - bzeamanabsolute
定位的 div,而是它的内容。 - Hashem Qolami