简体   繁体   English

使浏览器自动固定布局的最佳方法

[英]the best pratice to make a browser auto-fixed layout

For example,I want to make a layout like this: 例如,我想要这样的布局:

在此处输入图片说明

The 'header' can have a fixed height(for example:200px) “标题”可以具有固定的高度(例如:200px)

The 'menu' div in the left can have a fix width (for example:300px). 左侧的“菜单” div可以具有固定宽度(例如:300px)。

Now,I want the main div in the right can take all the width and height of the rest space. 现在,我希望右侧的主div可以占用休息空间的所有宽度和高度。

Also,if user resize the browser,the size of the main div should resized accordingly,in a word,I do not want the scroll bar show in anytime. 另外,如果用户调整浏览器的大小,则主div的大小应相应地调整大小,总之,我不想随时显示滚动条。

Using javascript is the common manner,but it may difficult. 使用javascript是常见的方式,但可能会很困难。

For example,use this(pseudo code): 例如,使用以下(伪代码):

window.onresize=function(){
 main.style.width=document.clientWidth-left.style.width;
}

But how about the border of the elemnt? 但是边界的边界又如何呢?

main.style.width=document.clientWidth-left.style.width-left.style.borderLeftWidth-left.style.borderRightWidth-......;

But in different browser,the 'element.style.width' may contain or not contain the width of the browser. 但是在不同的浏览器中,“ element.style.width”可能包含或不包含浏览器的宽度。

So I wonder if there is any idea I can avoid to use the js caculate? 所以我想知道是否有可以避免使用js的想法?

Use CSS and take a look at columns with equal height . 使用CSS并查看具有相同高度的列 If you want to never have scrolls on browser resize, then I recommend using absolute positioning . 如果您不希望浏览器调整大小,那么建议您使用绝对定位 But that's not native to web-development and design. 但这不是Web开发和设计的本能。

This use CSS is very easy. 这种使用CSS非常容易。

HTML: HTML:

<div class="header">header</div>
<div class="content">
    <div class="menu">menu</div>
    <div class="main">main</div>
</div>
<div class="footer">footer</div>

CSS: CSS:

.header {
  height: 200px;
}
.content {
   overflow: hidden;
 }
.menu {
  float: left;
  width: 300px;
}
.main {
  overflow: hidden;
  *zoom: 1; /* IE6/7 */
  padding-bottom: 99999px;
  margin-bottom: -99999px;
}

This is my best shot: 这是我最好的镜头:

http://jsfiddle.net/t4TV2/ http://jsfiddle.net/t4TV2/

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

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