我嘗試使用方形圖像製作響應式網格,但第一個方形圖像需要是其他方形圖像的兩倍。我可以用jQuery做到這一點,但我想用css修復它,如果可能的話。Div與奇數像素的圖像比例?
網格 這是一個網格的例子。紅色正方形是的div內的圖像:
我認爲這會工作
我想這將是簡單的方式: 如果每個div有20%的寬度,第一項應該有40%。所有div的高度都是自動的,因爲所有圖像都是500 x 500像素。因此,高度可以縮放兩倍是合乎邏輯的。
令我驚訝的是它不適用於所有屏幕尺寸。在一些屏幕上,第一個div是1像素到大。示例:當第一個圖像的高度爲533px時,第一個圖像旁邊的圖像的高度爲266 px。這意味着第一個圖像是1像素到大(266 x 2 = 532)。所以圖像的第三行出錯了。
下面是在線網格示例:http://bit.ly/LKdKMj將瀏覽器縮小到較小的大小,您可以看到圖像的行爲。
有人知道爲什麼這不起作用嗎?
我在下面添加了HTML和CSS。
非常感謝,
Wnd中
HTML:
<div class="container">
<header id="header">
</header>
<nav id="leftmenu">
</nav>
<section id="content">
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
<article class="item">
<img src="img/item.jpg" alt=""/>
</article>
</section>
</div>
CSS:
html, body{margin: 0; padding: 0;}
#header{
width: 100%;
height: 100px;
background: #222;
}
#leftmenu{
height: 1000px;
width: 20%;
float: left;
background: #505050;
}
#content{
width: 80%;
float: left;
}
#content .item{
float: left;
padding: 0px;
margin: 0px;
}
#content .item img{
width: 100%;
display: block;
height: auto;
}
/*GRID*/
@media only screen and (max-width: 2700px) {
#content .item:first-child{width: 25%;}
#content .item{width: 12.5%;}
}
@media only screen and (max-width: 1920px) {
#content .item:first-child{width: 40%;}
#content .item{width: 20%;}
}
@media only screen and (max-width: 1400px) {
#content .item:first-child{width: 50%;}
#content .item{width: 25%;}
}
@media only screen and (max-width: 1024px) {
#content .item:first-child{width: 66.66666%;}
#content .item{width: 33.33333%;}
}
@media only screen and (max-width: 720px) {
#content .item:first-child{width: 66.66666%;}
#content .item{width: 33.33333%;}
}
@media only screen and (max-width: 520px) {
#content .item, #content .item:first-child{width: 50%;}
}
感謝您的回答。那個竅門對我來說不起作用。這意味着圖像不會填滿屏幕,所以總是有空間可見。除此之外,我嘗試了你的解決方案,但它仍然沒有擴展正確的方式。我認爲它必須處理奇數和偶數像素或什麼的。你的解決方案的例子:[鏈接] http://bit.ly/1cYrs4b [/鏈接] – ElBrm
好吧,你是對的,那是一個有趣的問題,然後id喜歡看到答案! – user2211216
我也是,我希望有! – ElBrm