時(shí)間:2022-05-29 17:48:01 | 來(lái)源:網(wǎng)絡(luò)營(yíng)銷(xiāo)
時(shí)間:2022-05-29 17:48:01 來(lái)源:網(wǎng)絡(luò)營(yíng)銷(xiāo)
這幾天,一直忙于幫公司做新的網(wǎng)站,在設(shè)計(jì)和修改新模板頁(yè)面的過(guò)程中,需要不停的調(diào)試CSS樣式,有的部分還需要重新來(lái)寫(xiě)。為了便于以后再次使用,我特意將在網(wǎng)頁(yè)制作過(guò)程中常使用的CSS代碼的使用技巧整理成文章的形式,在億企邦上跟大家分享一下,一是便于以后自己在做站的時(shí)候,使用起來(lái)比較方便;二是希望能對(duì)正在搭建網(wǎng)站的站長(zhǎng)們有所幫助。text-align:center;2、容器的水平居中
#container {3、文字的垂直居中
width:760px;
margin:0 auto;
}
<div id="container">1234567890</div>然后CSS這樣寫(xiě):
#container {height: 35px; line-height: 35px;}如果有n行文字,那么將行高設(shè)為容器高度的n分之一即可。
<div id="big">首先,將大容器的定位為relative。
<div id="small">
</div>
</div>
#big{然后,將小容器定位為absolute,再將它的左上角沿y軸下移50%,最后將它margin-top上移本身高度的50%即可。
position:relative;
height:480px;
}
#small {使用同樣的思路,也可以做出水平居中的效果。
position: absolute;
top: 50%;
height: 240px;
margin-top: -120px;
}
img {max-width: 100%}但是IE6不支持max-width,所以遇到IE6時(shí),使用IE條件注釋,將語(yǔ)句改寫(xiě)為:
img {width: 100%}6、3D按鈕的CSS代碼
#button {7、font屬性的快捷寫(xiě)法
background: #888;
border: 1px solid;
border-color: #999 #777 #777 #999;
}
body {所以:
font: font-style font-variant font-weight font-size line-height font-family;
}
body {可以被寫(xiě)成:
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: normal;
font-variant: small-caps;
font-style: italic;
line-height: 150%;
}
body {8、link狀態(tài)的設(shè)置順序
font: italic small-caps normal 13px/150% Arial, Helvetica, sans-serif;
}
a:link9、IE條件注釋
a:visited
a:hover
a:active
<!--[if IE]>還可以區(qū)分各種不同的IE版本:
<link rel="stylesheet" type="text/css" href="ie-stylesheet.css" />
< ![endif]-->
<!--[if IE 6]> - targets IE6 only -->10、IE6專用語(yǔ)句
<!--[if gt IE 6]> - targets IE7 and above -->
<!--[if lt IE 6]> - targets IE5.5 and below -->
<!--[if gte IE 6]> - targets IE6 and above -->
<!--[if lte IE 6]> - targets IE6 and below -->
/* the following rules apply only to IE6 */IE7專用語(yǔ)句則要寫(xiě)成
* html{
}
* html body{
}
* html .foo{
}
/* the following rules apply only to IE7 */IE專用語(yǔ)句方法二:
*+html .foo{
}
.element {11、CSS的優(yōu)先性
background: red; /* modern browsers */
*background: green; /* IE 7 and below */
_background: blue; /* IE6 exclusively */
}
<div id="ID" class="CLASS" style="color:black;"></div>行內(nèi)樣式是最優(yōu)先的,然后其他設(shè)置的優(yōu)先性,從低到高依次為:
div < .class < div.class < #id < div#id < #id.class < div#id.class12、IE6的min-height
.element {共有三條CSS語(yǔ)句,第一句是針對(duì)其他瀏覽器設(shè)置最小高度,第三句是針對(duì)IE設(shè)置最小高度,第二句則是讓其他瀏覽器覆蓋第三句的設(shè)置。
min-height: 500px;
height: auto !important;
height: 500px;
}
.element {_height只有IE6能讀取。
min-height: 500px
_height: 500px
}
body {font-size:62.5%;}后面統(tǒng)一采用em作為字體單位,2.4em就表示24px。
h1 {font-size: 2.4 em}14、Text-transform和Font Variant
p {text-transform: uppercase}Font Variant用于將字體變成小型的大寫(xiě)字母(即與小寫(xiě)字母等高的大寫(xiě)字母)。
p {text-transform: lowercase}
p {text-transform: capitalize}
p {font-variant: small-caps}15、CSS重置
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,form,fieldset,input,textarea,p,th,td {16、用圖片充當(dāng)列表標(biāo)志
margin:0;
padding:0;
}
table {
border-collapse:collapse;
border-spacing:0;
}
img {
border:0;
}
ol,ul {
list-style:none;
}
h1,h2,h3,h4,h5,h6 {
font-size:100%;
font-weight:normal;
}
ul {list-style: none}17、透明容器設(shè)置
ul li {
background-image: url("path-to-your-image");
background-repeat: none;
background-position: 0 0.5em;
}
.element {在這四行CSS語(yǔ)句中,第一行是IE專用的,第二行用于Firefox,第三行用于webkit核心的瀏覽器,第四行用于Opera。
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
<div class="triangle"></div>然后,將它四個(gè)邊框中的三個(gè)邊框設(shè)為透明,剩下一個(gè)設(shè)為可見(jiàn),就可以生成三角形效果:
.triangle {19、禁止自動(dòng)換行
border-color: transparent transparent green transparent;
border-style: solid;
border-width: 0px 300px 300px 300px;
height: 0px;
width: 0px;
}
h { white-space:nowrap; }20、用圖片替換文字
h1 {21、獲得焦點(diǎn)的表單元素
text-indent:-9999px;
background:url("h1-image.jpg") no-repeat;
width:200px;
height:50px;
}
input:focus { border: 2px solid green; }22、!important規(guī)則
h1 {上面這段語(yǔ)句的結(jié)果是,其他瀏覽器都顯示紅色標(biāo)題,只有IE顯示藍(lán)色標(biāo)題。
color: red !important;
color: blue;
}
<a class="tooltip" href="#">鏈接文字 <span>提示文字</span></a>CSS這樣寫(xiě):
a.tooltip {position: relative}24、固定位置的頁(yè)首
a.tooltip span {display:none; padding:5px; width:200px;}
a:hover {background:#fff;} /*background-color is a must for IE6*/
a.tooltip:hover span{display:inline; position:absolute;}
body{ margin:0;padding:100px 0 0 0;}IE6的另一種寫(xiě)法(用于固定位置的頁(yè)腳):
div#header{
position:absolute;
top:0;
left:0;
width:100%;
height:<length>;
}
@media screen{
body>div#header{position: fixed;}
}
* html body{overflow:hidden;}
* html div#content{height:100%;overflow:auto;}
* html #footer {25、在IE6中設(shè)置PNG圖片的透明效果
position:absolute;
top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight?document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop))+'px');
}
.classname {26、各類(lèi)瀏覽器的專用語(yǔ)句
background: url(image.png);
_background: none;
_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader
(src='image.png', sizingMethod='crop');
}
/* IE6 and below */27、容器的水平和垂直居中
* html #uno { color: red }
/* IE7 */
*:first-child+html #dos { color: red }
/* IE7, FF, Saf, Opera */
html>body #tres { color: red }
/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }
/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }
/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: red }
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho { color: red }
/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
#diez { color: red }
}
/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
#veintiseis { color: red }
}
/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece { color: red }
/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red }
/* Everything but IE6-8 */
:root *> #quince { color: red }
/* IE7 */
*+html #dieciocho { color: red }
/* Firefox only. 1+ */
#veinticuatro, x:-moz-any-link { color: red }
/* Firefox 3.0+ */
#veinticinco, x:-moz-any-link, x:default { color: red }
/***** Attribute Hacks ******/
/* IE6 */
#once { _color: blue }
/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }
/* Everything but IE6 */
#diecisiete { color/**/: blue }
/* IE6, IE7, IE8 */
#diecinueve { color: blue/9; }
/* IE7, IE8 */
#veinte { color/*/**/: blue/9; }
/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */
<figure class='logo'>CSS代碼如下:
<span></span>
<img class='photo'/>
</figure>
.logo {28、CSS陰影
display: block;
text-align: center;
display: block;
text-align: center;
vertical-align: middle;
border: 4px solid #dddddd;
padding: 4px;
height: 74px;
width: 74px;
}
.logo * {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.logo .photo {
height: auto;
width: auto;
max-width: 100%;
max-height: 100%;
}
.shadow {內(nèi)陰影:
-moz-box-shadow: 5px 5px 5px #ccc;
-webkit-box-shadow: 5px 5px 5px #ccc;
box-shadow: 5px 5px 5px #ccc;
}
.shadow {29、取消IE文本框的滾動(dòng)條
-moz-box-shadow:inset 0 0 10px #000000;
-webkit-box-shadow:inset 0 0 10px #000000;
box-shadow:inset 0 0 10px #000000;
}
textarea { overflow: auto; }30、圖片預(yù)加載
關(guān)鍵詞:技巧,使用
客戶&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
客戶&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2022 保留一切法律許可權(quán)利。