可读性CSS代码编写的小技巧

2020-05-08 08:29:39易采站长站整理

1

2

3

4

5

6

7

8

<div id="wrapper">

<div id="header"> </div>

<div id="body">

<div id="content"> </div>

<div id="sidebar"> </div>

</div>

<div id="footer"> </div>

</div>

1

2

3

4

5

6

#wrapper{ width:960px; margin:0 auto; }

#header{ float:left; width:960px; height:116px; }

h1#logo{ float:left; width:188px; }

#menu{ float:right; width:100%; text-align:right; }

#menu li{ padding:15px; color:#fff; display:inline; }

#menu li a{ color:#fff; text-decoration:none; }

6. 首先定义显示属性

通常,在我的项目中,我的 CSS 版面是基于浮动的。这是我的方式。。。相对与定位来说,我更喜欢浮动。

总之,我认为首先声明 float,width 和 height 这 3 个属性是个好的方式。这样,就可以从CSS 规则中靠前的定义获得显示版式。基于这 3 个属性,也可以帮助你可视化整个网站结构。本文由软件开发网jb51.net整理发布!转载请注明出处,谢谢!

1

2

3

4

5

6

7

8

9

10

#wrapper{ width:960px; margin:0 auto; }

#header { float:left; width:960px; height:116px; }

h1#logo{ float:left; width:188px; height:61px; }

#search{ float:right; width:270px; }

#SearchBox{ float:left; width:180px; height:28px; }

#SearchBtn{ float:left; width:80px; height:28px; }

#body{ float:left; }

#content{ float:left; width:600px; }

#sidebar{ float:right; width:300px;}

#footer{ float:left; width:960px; }

总结

这几个步骤不会产生完美的可读性 CSS 代码,可以肯定的是它们可以让你的生活简单些。尝试下并告诉我你的想法。干杯!