100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > html文字自适应屏幕居中显示 DIV+CSS经典布局[宽度自适应][自动屏幕居中]的实现...

html文字自适应屏幕居中显示 DIV+CSS经典布局[宽度自适应][自动屏幕居中]的实现...

时间:2024-05-14 15:20:30

相关推荐

html文字自适应屏幕居中显示 DIV+CSS经典布局[宽度自适应][自动屏幕居中]的实现...

test

-->

Header

分析:

最外层的wrapper把所有内容都嵌套在里边,整体相对定位。max min已经很好的控制了最窄最宽值,但对IE没有作用。如果没有其他布局的穿插,这一层其实写在body内就可以,少一层嵌套。

#wrapper{ width:auto; border:1px solid #000; min-width:776px; max-width:1000px; text-align:left; margin-left:auto; margin-right:auto; position:relative;}

wrapper 下级的 outer header footer

其中header绝对定位,footer 相对定位;outer分别对左右有130px的外边距,这是兼容非IE的关键。

#outer{ margin-left:130px; margin-right:130px; background:silver; border-left:1px solid #000; border-right:1px solid #000; color: #000;}

#header{ position:absolute; top:0; left:0; width:100%; height:70px; line-height:70px; border-bottom:1px solid #000; overflow:hidden; background:#0ff; text-align:center; font-size:xx-large}

#footer { width:100%; clear:both; line-height:50px; border-top:1px solid #000; background:#ffc; color:#000; text-align:center; position:relative;}

outer 下级的 clearheader outerwrap right clearer

clearheader 用做填补header的空白,clearer 是一个常用的填充hack用法。

outerwrap 宽为什么是99%,而不是100%?

因为他的上层outer有边框,100%宽再加2个边框象素就会撑大,FF有明显效果。

right 的处理很经典,IE下解析为定位,FF下则为浮动。负边距的处理也刚好使用上outer留出的空白。

#clearheader{ height:72px;}

.outerwrap { float:left; width:99%;}

#right {

position:relative;

width:130px; float:right; left:1px;

margin-right:-129px;

}

* html #right { margin-right:-130px; margin-left:-3px}

.clearer{ height:1px; overflow:hidden; margin-top:-1px; clear:both;}

outerwrap 内的 centrecontent left clearer 思路与上面类似。

指定IE5.0及版本以上浏览器有效

使用expression方法实现对IE5.0及以上版本的宽度条件控制,实现自动调整宽度并居中。宽度我都固定了数值,因为如果在这里使用auto,会在调整窗口大小过程中发生div内容无法显示的问题。

body {

width:expression( documentElement.clientWidth <= 800 ? (documentElement.clientWidth == 0 ? (body.clientWidth <= 800 ? "776" : "1000") : "776px") : "1000" );

}

#wrapper {

width:expression( documentElement.clientWidth <= 800 ? (documentElement.clientWidth == 0 ? (body.clientWidth <= 800 ? "776" : "1000") : "776px") : "1000" );

}

这个例子融合了很多DIV+CSS的经典用法和定义,同时很传统和实用。

Footer

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。