当前位置:主页>网站运营> 文章内容

经典的css技巧

来源: | 作者: | 2008-09-04 | 收藏 推荐 投稿

使用 line-height 垂直居中

line-height:24px;

字串9

使用固定宽度的容器并且需要一行垂直居中时,使用 line-height 即可(高度与父层容器一致),更多的垂直居中总结可以看这里。

字串3

清除容器浮动 字串2

#main {
    overflow:hidden;
}

字串6

期前也提到过这样的问题,更多信息可以看这里。

字串3

不让链接折行 字串2

a {
    white-space:nowrap;
} 字串9

上面的设定就能避免链接折行,不过个人建议长链接会有相应的这行(有关换行方面的讨论,参看圆心的记录)。 字串7

始终让 Firefox 显示滚动条

字串7

html {
    overflow:-moz-scrollbars-vertical;
} 字串3

更多的 Mozilla/Firefox 私有 CSS 属性可以参考这里。需跨浏览器的支持,也可以使用 字串4

body, html {
    min-height:101%;
} 字串1

使块元素水平居中

字串1

margin:0 auto;

字串2

其实就是 字串8

margin-left: auto;
margin-right: auto;

字串5

这个技巧基本上所有的 CSS 教科书都会有说明,别忘记给它加上个宽度。Exploer 下也可以使用

字串4

body{
    text-align: center;
} 字串3

然后定义内层容器

字串2

text-align: left;

字串9

恢复。 字串2

隐藏 Exploer textarea 的滚动条

字串2

textarea {
    overflow:auto;
} 字串5

Exploer 默认情况下 textarea 会有垂直滚动条(不要问我为什么)。 字串7

设置打印分页

字串1

h2 {
    page-break-before:always;
}

字串1

page-break-before 属性能设置打印网页时的分页。

字串3

删除链接上的虚线框

字串5

a:active, a:focus {
    outline:none;
} 字串2

Firefox 默认会在链接获得焦点(或者点击时)加上条虚线框,使用上面的属性可以删除。 字串5

最简单的 CSS 重置

字串3

* {
   margin: 0; padding: 0
}

字串4

如果想“复杂”,参考YUI 的做法(还有这里)。原文留言中也有用户说了他们的观点

字串4

I have to agree with Niall Doherty, * {margin: 0px; padding: 0px;}
basically means "traverse every css element and give it these
attributes". That is a very unnecessary strain on the server and
a bad semantic practice, as you have to give some elements
padding/margin again, after stripping them. 字串8

 

字串3



评论列表

用户名: 新注册) 密码: 匿名评论