gpt4 book ai didi

css - overflow-hidden-parent 中的中心图像

转载 作者:技术小花猫 更新时间:2023-10-29 10:10:53 25 4
gpt4 key购买 nike

我在 span 标签内有一张图片,该 span 具有设置的宽度和高度,并设置为溢出隐藏。所以它只显示了图像的一小部分。这可行,但可见的图像的一小部分是左上角。我希望它成为可见图像的中心。我想我需要绝对定位图像,但图像的大小可能会有所不同。有谁知道如何做我想做的事?

谢谢!

这是 HTML:

<div class="lightbox_images">
<h6>Alternate Views</h6>
<span>
<a href="http://www.kranichs.com/mothers_rings/mothers_rings_txt2.jpg" rel="lightbox[product_alternate_views]" title="This is my captions 1">
<img src="http://www.kranichs.com/mothers_rings/mothers_rings_txt2.jpg" />
</a>
</span>
<span>
<a href="https://www.kranichs.com/product_images/Simon-G@346_M_346_M.jpg" rel="lightbox[product_alternate_views]" title="This is my captions 2">
<img src="https://www.kranichs.com/product_images/Simon-G@346_M_346_M.jpg" />
</a>
</span>
<span>
<a href="http://www.kranichs.com/images/simong/sim_banner_01.jpg" rel="lightbox[product_alternate_views]" title="This is my captions 3">
<img src="http://www.kranichs.com/images/simong/sim_banner_01.jpg" />
</a>
</span>
<span>
<a href="http://www.kranichs.com/images/psu/psu_banner.jpg" rel="lightbox[product_alternate_views]" title="This is my captions 4">
<img src="http://www.kranichs.com/images/psu/psu_banner.jpg" />
</a>
</span>
</div>

这是 CSS:

.lightbox_images{
background-color:#F9F9F9;
border:1px solid #F0F0F0;
}
.lightbox_images h6{
font-family:Verdana, Arial, Helvetica, sans-serif;
color:#333333;
font-size:14px;
font-weight:bold;
font-style:italic;
text-decoration:none;
margin:0px;
}
.lightbox_images span{
padding:5px;
padding-bottom:15px;
background-color:#DFDFDF;
margin:5px;
display:inline-block;
border:1px solid #CCC;
}
.lightbox_images a{
display:inline-block;
width:60px;
height:60px;
overflow:hidden;
position:relative;
}

.lightbox_images a img{
position:absolute;
left:-50%;
top:-50%;
}

.lightbox_images span:hover{
border:1px solid #BBB;
background-color:#CFCFCF;
}

最佳答案

https://stackoverflow.com/a/14837947/2227298 中所提议通过 Billy Moat,有一个解决方案不知道图像的高度和宽度。

在这里试试:http://jsfiddle.net/LSKRy/

<div class="outer">
<div class="inner">
<img src="http://3.bp.blogspot.com/-zvTnqSbUAk8/Tm49IrDAVCI/AAAAAAAACv8/05Ood5LcjkE/s1600/Ferrari-458-Italia-Nighthawk-6.jpg" alt="" />
</div>
</div>

.outer {
width: 300px;
overflow: hidden;
}

.inner {
display: inline-block;
position: relative;
right: -50%;
}

img {
position: relative;
left: -50%;
}

关于css - overflow-hidden-parent 中的中心图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/689991/

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