2018-03-23 CSS樣式表

CSS樣式表
樣式表的基本結(jié)構(gòu)
<style>:樣式風(fēng)格標(biāo)簽;放在head頭部,是一個雙標(biāo)簽
屬性:type="text/css"

A:標(biāo)簽選擇器:標(biāo)簽名{屬性名:屬性值}

文本屬性:color,font-family,font-size
<style type="text/css">
p{color:red}

<html>
    <head>
        <title></title>
        <style type="text/css">
            p{color: red}
        </style>
    </head>
    <body>
        <p>段落1</p>
        床前明月光
        <p>段落2</p>
        疑是地上霜
    </body>
</html>

B:類選擇器: .類名{屬性名:屬性值}

.blue{color:blue}
.red{color:red}

<html>
    <head>
        <title></title>
        <style type="text/css">
            .blue{color: blue}
            .red{color: red}
        </style>
    </head>
    <body>
        <p class="blue">段落1</p>
        床前明月光
        <p class="red">段落2</p>
        疑是地上霜
    </body>
</html>

A和B同時設(shè)定時類>標(biāo)簽

另一種可以設(shè)置CSS樣式表運(yùn)用到HTML中,在頭部head中輸入

<html>
    <head>
        <title></title>
        <link rel="stylesheet" type="text/css" href="abc.css">
    </head>
    <body>
        <p class="blue">段落1</p>
        床前明月光
        <p class="red">段落2</p>
        疑是地上霜
    </body>
</html>

<link reel="stylesheet" href="abc.css " type="text/css">

C:id選擇器:#id

屬性:position:absolute,left,top,width,height,z-index:1(第一層)
<div>:屬性:id=''層數(shù)''

<html>
    <head>
        <title></title>
        <style type="text/css">
        #id1{
            position: absolute;
            left: 50px;
            top: 50px;
            width: 200px;
            height: 300px;
            z-index: 1;
            background-color: blue
        }
        #id2{
            position: absolute;
            left: 50px;
            top: 150px;
            width: 200px;
            height: 200px;
            z-index: 2;
            background-color: red
        }
        #id3{
            position: absolute;
            left: 50px;
            top: 250px;
            width: 200px;
            height: 100px;
            z-index: 3;
            background-color: pink
        }
        </style>
    </head>
    <body>
        <div id="id1"></div>
        <div id="id2"></div>
        <div id="id3"></div>
    </body>
</html>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容