gpt4 book ai didi

html - 在 div 中居中图像而不裁剪图像和 overflow hidden

转载 作者:行者123 更新时间:2023-11-28 03:33:10 26 4
gpt4 key购买 nike

我必须在每个 div 的中心设置每个图像,并 overflow hidden ,而不裁剪图像。我试过

  • margin: auto 0;
  • background-position: center;

但没有任何作用。

.main {
width: 100%;
height: 100%;
overflow: hidden;
white-space: nowrap;
}

.column {
width: 16.7% !important;
max-width: 16.4% !important;
height: 100%;
display: inline-block;
margin-right: -1px;
overflow: hidden;
position: relative;
}

.column .picture:before {
height: 100%;
transition: all .7s;
display: none;
}

.picture {
background-position: center;
height: 90%;
overflow: hidden;
transition: all .5s;
}

.column:hover .picture {
filter: blur(1.2px);
overflow: hidden;
height: 100%;
transition: all .5s;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(1px) scale(1.1, 1.1);
}

.column:hover .picture:before {
display: block;
transition: all .7s;
}

.label{
color: #E7E7E7;
font-size: 2em !important;
font-weight: 900;
line-height: 60px;
text-shadow: 3px 3px #953163;
text-align: center;
text-decoration: none;
}
<div class="main">
<div class="column">
<a href="http://link1.com/">
<img class="picture" src="https://i.imgur.com/u5vuO6M.jpg" alt="">
<div class="label"> Link 1</div>
</a>
</div>
<div class="column">
<a href="http://link2.com/">
<img class="picture" src="https://i.imgur.com/u5vuO6M.jpg" alt="">
<div class="label"> Link 2</div>
</a>
</div>
<div class="column">
<a href="http://link3.com/">
<img class="picture" src="https://i.imgur.com/u5vuO6M.jpg" alt="">
<div class="label"> Link 3</div>
</a>
</div>
</div>

enter code here

最佳答案

将图像 -50% 向左平移,并将左边距设置为 50%

要防止悬停转换移除 translateX,请将其更新为:

transform: translateX(-50%) translateZ(1px) scale(1.1, 1.1);

.main {
width: 100%;
height: 100%;
overflow: hidden;
white-space: nowrap;
}

.column {
width: 16.7% !important;
max-width: 16.4% !important;
height: 100%;
display: inline-block;
margin-right: -1px;
overflow: hidden;
position: relative;
}

.column .picture:before {
height: 100%;
transition: all .7s;
display: none;
}

.picture {
display: inline-block;
height: 90%;
transition: all .5s;
transform: translateX(-50%);
margin-left: 50%;
}

.column:hover .picture {
filter: blur(1.2px);
overflow: hidden;
height: 100%;
transition: all .5s;
-webkit-backface-visibility: hidden;
transform: translateX(-50%) translateZ(1px) scale(1.1, 1.1);
}

.column:hover .picture:before {
display: block;
transition: all .7s;
}

.label {
color: #E7E7E7;
font-size: 2em !important;
font-weight: 900;
line-height: 60px;
text-shadow: 3px 3px #953163;
text-align: center;
text-decoration: none;
}
<div class="main">
<div class="column">
<a href="http://link1.com/">
<img class="picture" src="https://i.imgur.com/u5vuO6M.jpg" alt="">
<div class="label"> Link 1</div>
</a>
</div>
<div class="column">
<a href="http://link2.com/">
<img class="picture" src="https://i.imgur.com/u5vuO6M.jpg" alt="">
<div class="label"> Link 2</div>
</a>
</div>
<div class="column">
<a href="http://link3.com/">
<img class="picture" src="https://i.imgur.com/u5vuO6M.jpg" alt="">
<div class="label"> Link 3</div>
</a>
</div>
</div>

关于html - 在 div 中居中图像而不裁剪图像和 overflow hidden ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44619426/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com