【发布时间】:2017-10-01 14:29:42
【问题描述】:
我有一个页面here 有一个垂直和水平居中的图像。
body {
margin: 0px;
height: 100%;
}
#background {
z-index: -1000;
position: absolute;
height: 100%;
width: 100%;
overflow: hidden;
}
#background-img {
width: calc(100% + 200px);
height: calc(100% + 200px);
margin-left: -100px;
margin-top: -100px;
filter: blur(50px);
}
#body-container {
height: 100%;
display: table;
width: 100%;
}
#display {
display: table-cell;
height: 100%;
margin: 0 auto;
height: auto;
position: relative;
vertical-align: middle;
}
#display-img {
max-width: 100%;
border-style: solid;
border-color: transparent;
border-width: 33px;
display: block;
text-align: center;
overflow: hidden;
opacity: .5;
/* height: 50px;*/
}
#display-img-placeholder {
max-width: 100%;
border-style: solid;
border-color: white;
border-width: 33px;
display: block;
text-align: center;
/*
width: 930px;
max-width: calc(100% - 66px);
margin: 0 auto;
*/
filter: contrast(1.5);
/* position: relative;*/
position: absolute;
z-index: -1;
}
#display-img-placeholder img {
width: 100%;
opacity: 0;
}
#display-img img {
width: 100%;
}
#img-container {
max-width: calc(100% - 66px);
/*
border-style: solid;
border-color: white;
border-width: 33px;
*/
display: block;
text-align: center;
width: 930px;
max-width: calc(100% - 66px);
margin: 0 auto;
position: relative;
}
<div id="background">
<img id="background-img" src="http://iamwasserman.com/Portfolio/hoh.jpg">
</div>
<div id="body-container">
<div id="display">
<div id="img-container">
<div id="display-img-placeholder">
<img src="http://iamwasserman.com/Portfolio/hoh.jpg">
</div>
<div id="display-img">
<img src="http://iamwasserman.com/Portfolio/hoh.jpg">
</div>
</div>
<h3 id="time-stamp"></h3>
<div id="dots">
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
</div>
</div>
我需要一种在不影响定位的情况下裁剪图像底部 15% 的方法(因此它必须保持相同的大小,但使底部透明)。我尝试在其周围放置一个容器 <div> 并更改高度,但随后它会更改图像的垂直位置。关于如何做到这一点的想法?
【问题讨论】:
-
发布您的 html 和 css 代码
-
您可以添加一个与此图像底部重叠的 div,并将图像的宽度设置为容器 div 的 100%。这将给出图像底部被移除的外观,当它位于 div 后面时。
-
@MehdiKarimi 都在那个链接上
-
在问题中保留代码仍然会有所帮助,因为我猜 SO 的停留时间比这个演示站点要长 ;) – 还可以考虑添加限制你做事的约束和 还要说出原因。
-
您需要在此处发布您的标记,而不是第三方网站,明天可能会改变或消失,对未来没有任何帮助。 stackoverflow.com/help/mcve