1
我正在嘗試對齊頁面底部的圖像。該div是100%的高度,但垂直對齊:底部似乎沒有工作。無法獲取圖像垂直對齊底部
HTML:
<div class="container-fluid">
<div class="row" id="bg">
<div class="col-md-6 col-lg-6 col-sm-12 col-xs-12" id="pic">
<div class="leftlayer-gradient hidden-md hidden-lg text-center">
<img src="https://imageog.flaticon.com/icons/png/512/3/3907.png" class="down-image">
</div>
</div>
</div>
CSS:
#pic {
background-image:url("left.jpeg");
background-size: cover;
background-position: right;
}
.leftlayer-gradient {
background: -webkit-linear-gradient(top, rgba(0,0,0,0) 70%, rgba(0,0,0,0.5)); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(bottom, rgba(0,0,0,0) 70%, rgba(0,0,0,0.5)); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(bottom, rgba(0,0,0,0) 70%, rgba(0,0,0,0.5)); /* For Firefox 3.6 to 15 */
background: linear-gradient(to bottom, rgba(0,0,0,0) 70%, rgba(0,0,0,0.5)); /* Standard syntax (must be last) */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.down-image {
height: 8vh;
vertical-align: bottom;
border: 0;
}
這一工作的感謝。我注意到圖像實際上偏離了中心。我是否需要將其寬度補償一半? –
@EdShee你需要使用[居中](https://css-tricks.com/centering-css-complete-guide/)... –