[英]CSS inline divs using media queries to make responsive
I have this CSS code: 我有这个CSS代码:
.wrap div {
border: 1px solid #f36f25;
width: 30%;
float: left;
margin:10px;
padding:5px;
}
.clear:after {
content: "";
display: table;
clear: both;
}
@media all and (max-width: 800px) {
div.wrap div {
width: 100%;
float: none;
}
}
which I'm using to display divs inline and using media queries, to make them responsive. 我用它来内联显示div并使用媒体查询来使它们响应。
As the screen gets smaller, the 3rd div displays underneath the others, how can I make it fully responsive so that they all display underneath each other at the same time. 随着屏幕变小,第3格显示在其他下方,我该如何使其完全响应,以便它们同时显示在下方。
I would also like all 3 to be width: 100%;
我还希望所有3个元素均为width: 100%;
if the screen is too wide they display more of the left side than the centre. 如果屏幕太宽,则它们显示的左侧多于中心。
Updated fiddle: http://jsfiddle.net/a8k16vts/2/ 更新的小提琴: http : //jsfiddle.net/a8k16vts/2/
I would also like to display 3 divs inline, then under those 3, one div under the first and then a larger div to fit under the second two divs. 我还要在行中显示3个div,然后在这3个下显示,在第一个下显示一个div,然后在第二个下显示一个更大的div。 Like so: http://jsfiddle.net/a8k16vts/3/ 像这样: http : //jsfiddle.net/a8k16vts/3/
demo - http://jsfiddle.net/a8k16vts/4/ 演示-http: //jsfiddle.net/a8k16vts/4/
use display:inline-block
instead of float
使用display:inline-block
而不是float
* { margin: 0; padding: 0; box-sizing: border-box; } .wrap { text-align: center; } div.wrap div { border: 1px solid #f36f25; width: 29%; display: inline-block; margin: 0 5px 0 5px; padding: 10px; text-align: left; } @media all and (max-width: 800px) { div.wrap div { width: 100%; float: none; margin: 0px; } }
<div class="wrap"> <div>testing 1</div> <div>testing 2</div> <div>testing 3</div> </div>
You want them to be in 3 columns when its in large screen? 您希望它们在大屏幕中显示在3列中吗? if so, then your margin is causing it to drop underneath. 如果是这样,那么您的保证金就会下降到下面。
drop down the margin by 5px. 将边距降低5像素。
.wrap div {
border: 1px solid #f36f25;
width: 30%;
float: left;
margin:5px;
padding:5px;
}
http://jsfiddle.net/a8k16vts/1/ http://jsfiddle.net/a8k16vts/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.