简体   繁体   English

如何使我的网页固定布局?

[英]How can I make my web page fixed-layout?

Here's the sample/jsFiddle: http://jsfiddle.net/antonpug/ub7xW/ 这是示例/ jsFiddle: http : //jsfiddle.net/antonpug/ub7xW/

Basically, you can't see it in the jsFiddle, I don't think, but it is two columns when it is full screen, however, when you make the screen smaller, it collapses down to just one column - I can't figure out where in my CSS it is doing that! 基本上,您不会在jsFiddle中看到它,但是全屏显示时它是两列,但是,当您缩小屏幕时,它会折叠成只有一列-我不能找出我的CSS在哪里做!

This causes it: 这导致它:

.column {
    display: inline-block;
    width:600px;
    margin:15px;
}

The inline-block will cause them to sit next to each other if your wrapper is 1200px or more, but otherwise it won't. 如果wrapper的像素为1200px或更高,则inline-block将使它们彼此相邻放置,否则不会这样做。 Set a min-width if you don't want it to wrap. 如果不想包装,请设置最小宽度。

#wrapper {
    min-width: 1200px; /*might need a bit more for margins*/
    margin:25px;
}

If you do want the columns next to each other you must specify a width under your body selector. 如果确实希望各列彼此相邻,则必须在body选择器下指定一个宽度。

Something like 就像是

body {width:1500px;}

This forces the body to overflow the screen and place the columns next to each other. 这会迫使身体溢出屏幕,并使各列彼此相邻。 Otherwise, the width of the screen (or "viewing area") sets the width for the body selector because it's default is width:auto . 否则,屏幕的宽度(或“查看区域”)将设置body选择器的width ,因为它的默认值为width:auto

change css to 更改为

#wrapper {
  margin: 25px auto;
  width: 80%;
}

and

.column {
  display: inline-block;
  width: 46%;
  margin: 15px;
  float: left;
}

It's pretty straight forward: 这很简单:

.column {
    display: inline-block;
    width:600px;
    margin:15px;
}

You have 2 DIVs both with ".column". 您有2个DIV都带有“ .column”。 These DIVs have a static width of 600px. 这些DIV的静态宽度为600px。 They will float next to each other as long as there's space for them (ie. 1200px container) 只要有足够的空间,它们就会彼此相邻漂浮(即1200px容器)

They collapse because the page is too small for them. 它们折叠是因为页面对他们来说太小了。

If you're looking to keep 2-columns, you need to set the width to a % like so: 如果要保留2列,则需要将宽度设置为%,如下所示:

.column{
    ...
    width: 40%;
}

you will have to do some adjustments for your margins as well, depending on what you're looking for. 您还必须根据所需内容对边距进行一些调整。

If you want to keep 2 columns until a certain size, you can set a min-width on your wrapper element so you columns won't get too small: 如果要保留2列直到一定大小,可以在wrapper元素上设置最小宽度,这样列就不会太小:

.wrapper{
    min-width:600px;
}

You can then run a media query for smaller screen sizes so you can collapse your columns into one for things like mobile phones. 然后,您可以针对较小的屏幕尺寸运行媒体查询,以便将诸如手机之类的列折叠为一列。

change the column's css to this and it should be fine. 将列的CSS更改为此,应该没问题。

.column {
    display: inline-block;
    margin:15px;
    width:40%;
}

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

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