css入門

整體樣式

<!DOCTYPE html>
<html>
<head lang="en">
    <title>CSS</title>
    <meta charset="utf-8">
    <style type="text/css">
    p{font-size:20px;color:blue;font-family:"隸書";}
    h1{color:red;
        font-size:50px;}
    </style>
</head>
<body>
<h1>CSS</h1>
<p>定義</p>
</body>
</html>

 

行內樣式

<!DOCTYPE html>
<html>
<head lang="en">
    <title>CSS</title>
    <meta charset="utf-8">
</head>
<body>
<h1>CSS</h1>
<p style="color:blue;font-size:33px">定義</p>
</body>
</html>

 

 

防止低版本不識別

<!DOCTYPE html>
<html>
<head lang="en">
    <title>CSS</title>
    <meta charset="utf-8">
    <style type="text/css">
        <!-- 
        p{color:blue;}
        -->
    </style>
</head>
<body>
<h1>CSS</h1>
<p style="color:blue;font-size:33px">定義</p>

<p>嵌入樣式</p>
</body>
</html>

 

外部樣式(外聯樣式)

<!DOCTYPE html>
<html>
<head lang="en">
    <title>CSS</title>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="2-1.css">
</head>
<body>
<h1>CSS</h1>
<p>定義</p>

</body>
</html>

或者

<!DOCTYPE html>
<html>
<head lang="en">
    <title>CSS</title>
    <meta charset="utf-8">
    <style type="text/css">
        @import url(2-1.css)
    </style>
</head>
<body>
<h1>CSS</h1>
<p>定義</p>

</body>
</html>

 

l外部.css文件

p{color:blue;}
h1{color:red;}

選擇類 .類名

<!DOCTYPE html>
<html>
<head lang="en">
    <title>CSS</title>
    <meta charset="utf-8">
    <style type="text/css">
        p{color:red;}
        .ss{color:orange}
    </style>
</head>
<body>
<h1>CSS</h1>
<p>定義</p>
<p class="ss">fff</p>
</body>
</html>

但是ID選擇器不能像類一樣可以 p.red  h1.red再次分類

<!DOCTYPE html>
<html>
<head lang="en">
    <title>CSS</title>
    <meta charset="utf-8">
    <style type="text/css">
        p{color:red;}
        #one{color:green}
    </style>
</head>
<body>
<h1>CSS</h1>
<p>定義</p>
<p id="ss">fff</p>
</body>
</html>

組選擇器

    <style type="text/css">
        p{color:red;}
        #one{color:green;}
        p.ss,h1.ss,#one,#tow{color:red;}
    </style>

全局選擇器

*{}

 

後代選擇器 空格選擇子類

p em{}

p.special em{}

僞類

<!DOCTYPE html>
<html>
<head lang="en">
    <title>CSS</title>
    <meta charset="utf-8">
    <style type="text/css">
        a:link{color:blue;}  未訪問
        a:visited{color:gray;}  已訪問
        a:hover{color:red;}  鼠標懸浮
        a:active{color:orange;}  已經激活(按下未鬆開)
    </style>
</head>
<body>
<h1>CSS</h1>
<p>定義</p>
<a href="http://www.baidu.com" target="_blank">baidu</a>
<p id="ss">fff</p>
</body>
</html>

css繼承與層疊

ID>類>標籤選擇器

 

a:hover{color:red !important;}

降優先級,中間不加;

 

<!DOCTYPE html>
<html>
<head lang="en">
    <title>CSS</title>
    <meta charset="utf-8">
    <style type="text/css">
        .block {
            width: 80px;
            height: 80px;
            line-height: 80px;
            text-align: center;
            border: 2px solid black;
        }
        .block:nth-child(2){
            position: absolute;
            top:20px;
            left:20px;
            width: 50%;
            height: 50%;
            border-color:red;
            z-index: 1;
        }
    </style>
</head>
<body>
    <div class="block">A</div>
    <div class="block">B</div>
    <div class="block">C</div>
</body>
</html>

項目案例


*{
    padding: 0;
    margin:0;
}
.header{
    width: 100%;
    height: 100px;
}
.header .logo img{
    width:300px;
    height: 85px;
    margin-top: 8px;
    margin-left: 150px;
    float: left;
}
.header .menu{
    height: 100px;
    float: right;
}
.header .menu ul{
    margin-right: 50px;
}
.header .menu li{
    float: right;
    list-style-type: none;
    width: 80px;
    font-family: "微軟雅黑";
    color: #7D7D7D;
    font-size: 15px;
    line-height: 100px;
    font-weight: bold;
    text-align: center;
}
.main .pic img{
    width: 100%;
    height: 600px;
    position: relative;
}
.topLayer{
    background-color: #000000;
    opacity: 0.5;
    z-index: 1;
    position: absolute;
    top: 100px;
    width: 100%;
    height: 600px;
}
.main .btn{
    z-index: 2;
    width: 500px;
    height: 300px;
    position: absolute;
    top: 400px;
    margin-top:-150px;
    right: 50%;
    margin-right: -250px;
    text-align: center;
}
.main .btn p{
    padding-top: 100px;
    color: #ffffff;
    font-size: 45px;
    font-family: "微軟雅黑";
    font-weight: bold;
}
.main .btn button{
    margin-top: 50px;
    background-color: #F5704F;
    width: 200px;
    height: 60px;
    color: #ffffff;
    font-family: "微軟雅黑";
    font-size: 14px;
    text-align: center;
    border-radius: 8px;
}
.main .content{    
    color: #7c7d7f;
    font-size: 20px;
    font-weight: bold;
}
.main .content .top{
    width: 1000px;
    padding-top: 50px;
    margin:0 auto;
}
.main .content .top .icon{
    float: left;
    width: 33.3%;
    text-align: center;

.main .content .top .icon img{
    width:100px;
    height:100px;
}
.main .content .top .icon .des{
    padding-top: 20px;
}
.main .content .top .recept{
    padding-top: 50px;
    clear: both;
    font-size: 22px;
    text-align: center;
    color: #E19796;
    font-weight: bold;
    font-style:italic ;
}
.main .content .top .picAndDes{
    padding-top: 50px;
}
.main .content .top .picAndDes .icon2{
    float: left;
    text-align: center;
    padding: 10px;
}
.main .content .top .picAndDes .icon2 .des1{
    padding-top: 10px;
    font-size: 20px;
    font-weight: bold;
    color: #7c7d7f;
}
.main .content .top .picAndDes .icon2 .des2{
    color: #BDBDBC;
    padding-top: 10px;
}
.main .content .top .picAndDes .icon2 img{
    width: 310px;
    height: 260px;
}
.main .content .bottom {
    width: 100%;
    padding-bottom: 30px;
    background-color: #F9F9F9;
}
.main .content .bottom .bottom-content {
    width: 1000px;
    margin: 0 auto;
    margin-bottom: 50px;
}
.main .content .bottom .bottom-content .title{
    text-align: center;
    padding-top: 50px;
    font-family: "微軟雅黑";
    padding-bottom: 40px;
    font-size: 20px;
}
.main .content .bottom .bottom-content .picContent dl{
    width: 470px;
    float: left;
    margin:10px 12px 10px 12px;
}
.main .content .bottom .bottom-content .picContent dl dd{
    padding-top: 20px;
}
.main .content .bottom .bottom-content .picContent dl dt img{
    width:470px; 
    height:480px;
}
.footer{
    width: 100%;
    height: 100px;
    background-color: #292C35;
    color: #ffffff;
    text-align: center;
    line-height: 100px;
    font-family: "微軟雅黑";
    font-size: 15px;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>CSS網頁佈局</title>
    <link rel="stylesheet" href="css/index.css">
    
</head>
<body>
<!-- 頭部 -->
    <div class="header">
        <div class="logo"><img src="image/logo.png"></div>
        <div class="menu">
            <ul>
                <li>手記</li>
                <li>視頻</li>
                <li>圖片</li>
                <li>首頁</li>
            </ul>
        </div>
    </div>
    <!-- 主體 -->
    <div class="main">
        <!-- 大圖 -->
        <div class="pic">
            <img src="image/1.jpeg">
        </div>
        <!-- 遮罩層 -->
        <div class="topLayer">
            
        </div>
        <!-- 最上層的內容 -->
        <div class="btn">
                <p>MY BEAUTIFUL LIFE</p>
                <button>LOOK MORE &nbsp;&nbsp;&gt;</button>
        </div>
        <!-- 內容展示區 -->
        <div class="content">
            <!-- 上部分 -->
            <div class="top">
                <div>
                    <div class="icon weibo">
                        <img src="image/weibo.png" alt="">
                        <div class="des">MICROBLOG</div>
                    </div>
                    <div class="icon weixin">
                        <img src="image/weixin.png" alt="">
                        <div class="des">WECHAT</div>
                    </div>
                    <div class="icon qq">
                        <img src="image/qq.png" alt="">
                        <div class="des">QQ</div>
                    </div>
                </div>
                <div class="recept">
                    "I want to give good things to record down,<br>after the recall will be very beautiful."
                </div>
                <div class="picAndDes">
                    <div class="icon2 ">
                        <img src="image/03-01.jpg" alt="">
                        <div class="des1">Cool Image</div>
                        <div Class="des2">Record The Picture</div>
                    </div>
                    <div class="icon2">
                        <img src="image/03-02.jpg" alt="">
                        <div class="des1">Great Picture</div>
                        <div class="des2">Record The Picture</div>
                    </div>
                    <div class="icon2">
                        <img src="image/03-03.jpg" alt="">
                        <div class="des1">Cool Image</div>
                        <div class="des2">Record The Picture</div>
                    </div>
                </div>
            </div>
            <div style="clear:both;"></div><!-- 不加這句話的話,下面的背景會上移 -->
            <!-- 下部分 -->
            <div class="bottom"><!--包裹層 -->
                <div class="bottom-content"><!--內容層 -->
                    <div class="title">FROM THE PHOTO ALBUM</div>
                    <div class="picContent">
                        <dl>
                            <dt><img src="image/04-01.jpg"></dt>
                            <dd>
                                Life is like a book, just read more and more refined, more write more carefully. When read, mind open, all things have been indifferent to heart. Life is the precipitation.
                            </dd>
                        </dl>
                        <dl>
                            <dt><img src="image/04-02.jpg"></dt>
                            <dd>
                                Life is like a cup of tea, let people lead a person to endless aftertastes. You again good taste, it will always have a different taste, different people will have different taste more.
                            </dd>
                        </dl>
                    </div>
                    <div style="clear: both;"></div>
                </div>
                <div style="clear: both;"></div>
            </div>
        </div>
    </div>
    <!-- 底部 -->
    <div class="footer">
        © 2019   京ICP備########號
    </div>    
</body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章