简体   繁体   English

简单的3列响应式布局

[英]simple 3 Column responsive layout

I have a simple three column layout that I cannot seem to get working. 我有一个简单的三列布局,我似乎无法工作。 This will probably be super easy for most of you but for some reason I cannot get it working. 对于你们大多数人来说这可能是非常容易的,但由于某种原因,我无法让它发挥作用。

<div>min-width</div><div>stay in center</div><div>min-width</div>

here is the jsfiddle - http://jsfiddle.net/x7Atq/ 这里是jsfiddle - http://jsfiddle.net/x7Atq/

the fiddle looks like crap but basically the left / right column should size down to the min-width then start shrinking the middle down and all the containers should stay 30px margin between each other...right now when it hits min-width the second / middle container moves over the first container as the browser window is resized, I need the box to stay put, just keep getting smaller...as if the two sides were to smush in on the middle container 小提琴看起来像垃圾,但基本上左/右列的大小应该缩小到最小宽度然后开始缩小中间向下并且所有容器应该保持彼此之间30px的边距...现在当它达到最小宽度时/中间容器移动到第一个容器,因为浏览器窗口调整大小,我需要保持盒子,只是继续变小...好像双方都要在中间容器上漱口

trying to do this with just css so no third party anything if possible, I know of things like the perfect three column layout and bootsrap but I feel like there has to be a pure css solution for this?! 尝试用css做这个,所以如果可能没有第三方任何东西,我知道完美的三列布局和靴子的东西,但我觉得必须有一个纯粹的CSS解决方案吗?!

I'd advice you to use the css display: table and display: table-cell wich are widely underused. 我建议你使用css display: tabledisplay: table-cell它们被广泛使用。 Here's you working simplified fiddle: http://jsfiddle.net/u5nR2/1/ 这是你工作的简化小提琴: http//jsfiddle.net/u5nR2/1/

HTML: HTML:

<div class="container">
    <div class="one">
        <div>one</div>
    </div>
    <div class="two">
        <div>two</div>
    </div>
    <div class="three">
        <div>three</div>
    </div>
</div>

CSS CSS

html, body{height:100%;}

.container{
    width:100%;
    height:100%;
    display: table;
}
div > div {
  display: table-cell;
}
.one {width:15%; background:#ccc}
.two {width: 60%; background:#cba}
.three {width: 25%; background:#ca8}

This does allow you to have width in % 这允许你有宽度 %

There are some syntax issues in your CSS, for example display:float:left; CSS中存在一些语法问题,例如display:float:left; won't do anything. 不会做任何事情。 Also, you can't have a fixed margin and widths defined in percentage as you wouldn't know if that much space is even left on the screen or not. 此外,您不能以百分比定义固定的边距和宽度,因为您不知道屏幕上是否留有那么多空间。

Is this the result that you wanted - http://jsfiddle.net/x7Atq/7/ 这是你想要的结果 - http://jsfiddle.net/x7Atq/7/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM