最有用的CSS技巧

记得上个月Dejan Cancarevic才为我们介绍了一篇CSS好文“10 best CSS hacks”,想不到他又为我们贡献了一篇力作:Most used CSS tricks,感谢DC。本文章延用了上篇文章的风格,另外还为每个tips添加了效果图,让大家有了更直观的感觉。tips列表如下:

[size=large][b]1. Rounded corners without images[/b][/size]
<div id=”container”>
<b class=”rtop”>
<b class=”r1″></b> <b class=”r2″></b> <b class=”r3″></b> <b class=”r4″></b>
</b>
<!–content goes here –>
<b class=”rbottom”>
<b class=”r4″></b> <b class=”r3″></b> <b class=”r2″></b> <b class=”r1″></b>
</b>
</div>

.rtop, .rbottom{display:block}
.rtop *, .rbottom *{display: block; height: 1px; overflow: hidden}
.r1{margin: 0 5px}
.r2{margin: 0 3px}
.r3{margin: 0 2px}
.r4{margin: 0 1px; height: 2px}

[img]http://stylizedweb.com/examples/rounded1.gif[/img]

[size=large][b]2. Style your order list[/b][/size]
<ol>
<li>
<p>This is line one</p>
</li>
<li>
<p>Here is line two</p>
</li>
<li>
<p>And last line</p>
</li>
</ol>

ol {
font: italic 1em Georgia, Times, serif;
color: #999999;
}

ol p {
font: normal .8em Arial, Helvetica, sans-serif;
color: #000000;
}

[img]http://stylizedweb.com/examples/order.gif[/img]

[size=large][b]3. Tableless forms[/b][/size]

<form>
<label for=”name”>Name</label>
<input id=”name” name=”name”><br>
<label for=”address”>Address</label>
<input id=”address” name=”address”><br>
<label for=”city”>City</label>
<input id=”city” name=”city”><br>
</form>

label,input {
display: block;
width: 150px;
float: left;
margin-bottom: 10px;
}

label {
text-align: right;
width: 75px;
padding-right: 20px;
}

br {
clear: left;
}

[img]http://stylizedweb.com/examples/form.gif[/img]

[size=large][b]4. Double blockquote[/b][/size]
blockquote:first-letter {
background: url(images/open-quote.gif) no-repeat left top;
padding-left: 18px;
font: italic 1.4em Georgia, “Times New Roman”, Times, serif;
}

[img]http://stylizedweb.com/examples/double.gif[/img]

[size=large][b]5. Gradient text effect[/b][/size]
<h1><span></span>CSS Gradient Text</h1>

h1 {
font: bold 330%/100% “Lucida Grande”;
position: relative;
color: #464646;
}
h1 span {
background: url(gradient.png) repeat-x;
position: absolute;
display: block;
width: 100%;
height: 31px;
}

<!–[if lt IE 7]>
<style>
h1 span {
background: none;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’gradient.png’, sizingMethod=’scale’);
}
</style>
<![endif]–>


[size=large][b]6. Vertical centering with line-height[/b][/size]
div{
height:100px;
}
div *{
margin:0;
}
div p{
line-height:100px;
}

<p>Content here</p>

[img]http://stylizedweb.com/examples/verticalcenter.gif[/img]

[size=large][b]7. Rounded corners with images[/b][/size]
<div class=”roundcont”>
<div class=”roundtop”>
<img src=”tl.gif” alt=”"
width=”15″ height=”15″ class=”corner”
style=”display: none” />
</div>

CONTENT

<div class=”roundbottom”>
<img src=”bl.gif” alt=”"
width=”15″ height=”15″ class=”corner”
style=”display: none” />
</div>
</div>

.roundcont {
width: 250px;
background-color: #f90;
color: #fff;
}

.roundcont p {
margin: 0 10px;
}

.roundtop {
background: url(tr.gif) no-repeat top right;
}

.roundbottom {
background: url(br.gif) no-repeat top right;
}

img.corner {
width: 15px;
height: 15px;
border: none;
display: block !important;
}

[img]http://stylizedweb.com/examples/rounded2.gif[/img]

[size=large][b]8. Multiple class name[/b][/size]
<img src=”image.gif” class=”class1 class2″ alt=”" />

.class1 { border:2px solid #666; }
.class2 {
padding:2px;
background:#ff0;
}


[size=large][b]9. Center horizontally[/b][/size]
<div id=”contatiner”></div>

#container {
margin:0px auto;
}

[img]http://stylizedweb.com/examples/horisontal.gif[/img]

[size=large][b]10. CSS Drop Caps[/b][/size]
<p class=”introduction”> This paragraph has the class “introduction”. If your browser supports the pseudo-class “first-letter”, the first letter will be a drop-cap. </p>

p.introduction:first-letter {
font-size : 300%;
font-weight : bold;
float : left;
width : 1em;
}

[img]http://stylizedweb.com/examples/drop.gif[/img]

[size=large][b]11. Prevent line breaks in links, oversized content to brake[/b][/size]
a{
white-space:nowrap;
}

#main{
overflow:hidden;
}


[size=large][b]12. Show firefox scrollbar, remove textarea scrollbar in IE[/b][/size]
html{
overflow:-moz-scrollbars-vertical;
}

textarea{
overflow:auto;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值