gpt4 book ai didi

CSS div 位置在缩放浏览器时变得困惑

转载 作者:太空宇宙 更新时间:2023-11-04 03:21:56 25 4
gpt4 key购买 nike

我正在为基于网格图像布局的 Facebook 应用程序开发一个网站。下面的代码对我来说工作正常,但是当我缩放我的浏览器时,一切都变得一团糟。具有 100% 缩放 View 的浏览器有效。如果可能,请帮我找到一些其他代码或修复以下代码。

<style>
div.img {
margin: 5px;
padding: 5px;
border: 1px solid #0000ff;
height: auto;
width: auto;
float: left;
text-align: center;
}

div.img img {
display: inline;
margin: 5px;
border: 1px solid #ffffff;
}

div.img a:hover img {
border: 1px solid #0000ff;
}

div.desc {
text-align: center;
font-weight: normal;
width: 120px;
margin: 5px;
}
</style>

HTML:

<div class="img">
<a target="_blank" href="klematis_big.htm"><img src="image1.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis2_big.htm"><img src="image2.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis3_big.htm"><img src="image3.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis4_big.htm"><img src="image4.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>

最佳答案

我更新了 Sdghasemi 的 fiddle 。为没有宽度计算功能的旧浏览器添加回退并将图像宽度设置为 100% 并稍微清理 Html(关闭图像标签等)图像从容器div 流出的原因是HTML 中的width 和height 属性。我现在将它设置为 100% 的容器。由于边框,意味着 100% -2px。与图像标题相同。

<div class="img">
<a target="_blank" href="klematis_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>

<div class="img">
<a target="_blank" href="klematis2_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>

<div class="img">
<a target="_blank" href="klematis3_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>

<div class="img">
<a target="_blank" href="klematis4_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>

CSS:

div.img {
margin: 5px;
padding: 5px;
border: 1px solid #0000ff;
height: auto;
width: 24%;
width: calc(25% - 22px);
float: left;
display: block;
overflow: hidden;
text-align: center;
font-size: 100%;
}

div.img a:hover img {
border: 1px solid #0000ff;
}

div.img img{
width: 99%;
width: calc(100% - 2px);
border: 1px solid #fff;
}

div.desc {
text-align: center;
font-weight: normal;
width: 100%;
width: calc(100% - 10px);
margin: 5px;
}

http://jsfiddle.net/or2ua75e/5/

关于CSS div 位置在缩放浏览器时变得困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27752734/

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