1. 程式人生 > 實用技巧 >CSS美化網頁元素

CSS美化網頁元素

美化網頁元素

目錄

1. 為什麼要美化網頁

  1. 有效的傳遞頁面資訊
  2. 美化網頁,頁面漂亮,才能吸引使用者
  3. 凸顯頁面的主題
  4. 提高使用者的體驗

span標籤:重點要突出的字,使用span標籤套起來

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        #title1{
            font-size: 50px;
        }
    </style>

</head>
<body>

歡迎學習 <span id="title1">Java</span>

</body>
</html>

2.字型樣式

<!--
font-family:字型
font-size:字型大小
font-weight:字型粗細
color:字型顏色
-->
<style>
    body{
        font-family: "Times New Roman", 楷體;
        color: brown;
    }
    h1{
        font-size: 50px;
    }
    .p1{
        font-weight: bold;
    }
</style>

3. 文字樣式

  1. 顏色 color:rgb rgba

  2. 文字對齊方式 text-align= center

  3. 首行縮排 text-indent: 2em

  4. 行高 line-height:

  5. 裝飾 text-decoration:

  6. 文字圖片水平對齊 vertical-align:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <!--
    顏色:
        單詞
        RGB(Red Green Blue)
        RGBA(RGB + Alpha)RGB+透明度

    text-align:排版(水平排版)
    text-indent: 2em    段落首行縮排(2個字元)
    行高和塊的高度一致,就可以上下居中
    -->
    <style>
        h1{
            color: rgb(21, 177, 78);
            text-align: center;
        }
        .p1{
            text-indent: 2em;
            background: #6dbbbb;
            height: 300px;
            line-height: 300px;
        }
        /*下劃線*/
        .l1{
            text-decoration: underline
        }
        /*中劃線*/
        .l2{
            text-decoration: line-through;
        }
        /*上劃線*/
        .l3{
            text-decoration: overline;
        }
        /*l1去下劃線*/
        .l1{
            text-decoration: none;
        }
    </style>

</head>
<body>

<h1>
    TIL KINGDOM COME
</h1>

<p class="p1">
One... two... <br>
Steal my heart... and hold my tongue <br>
I feel my time... my time has come <br>
Let me in... unlock the door <br>
I never felt this way before <br>
And the wheels just keep on turning <br>
The drummer begins to drum <br>
I don't know which way I'm going <br>
I don't know which way I've come <br>
Hold my head... inside your hands<br>
I need someone... who understands<br>
I need someone... someone who hears<br>
For you I've waited all these years<br>
For you I'd wait... 'Til Kingdom Come<br>
Until my day... my day is done<br>
and say you'll come... and set me free<br>
just say you'll wait... you'll wait for me<br>
In your tears... and in your blood<br>
In your fire... and in your flood<br>
I hear you laugh... I heard you sing<br>
I wouldn't change a single thing<br>
And the wheels just keep on turning<br>
The drummers begin to drum<br>
I don't know which way I'm going<br>
I don't know what I've become<br>
For you I'd wait... 'Til kingdom come<br>
Until my days... my days are done<br>
Say you'll come... and set me free<br>
Just say you'll wait... you'll wait for me<br>
Just say you'll wait... you'll wait for me<br>
Just say you'll wait... you'll wait for me<br>
</p>

<p class="l1">112233</p>
<p class="l2">112233</p>
<p class="l3">112233</p>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <!--
    水平對齊 需要參照物: a, b
    -->
    <style>
        img, span{
            vertical-align: middle;
        }
        span{
            font-size: 50px;
        }
    </style>

</head>
<body>

<p>
    <img src="images/pic.jpg" alt="">
    <span>這是一張圖片</span>
</p>

</body>
</html>

4. 陰影

/*text-shadow:陰影顏色 水平偏移 垂直偏移 陰影半徑*/
#price{
    text-shadow: aqua 10px 10px 2px;
}

5. 超連結偽類

正常情況下,a:hover

/*預設的狀態*/
a{
    text-decoration: none;
    color: black;
}
/*滑鼠懸浮的狀態(只需要記住hover)*/
a:hover{
    color: orange;
    font-size: 50px;
}
/*滑鼠按住未釋放的狀態*/
a:active{
    color: green;
    font-size: 30px;
}

6. 列表

/*ul li*/
/*
list-style:
    none    去掉原點
    circle  空心圓
    decimal 數字
    square  正方形
*/
ul{
    background: gray;
}

ul li{
    height: 30px;
    list-style: none;
    text-indent: 1em;
}

7. 背景

背景顏色

背景圖片

<style>
    div{
        width: 1000px;
        height: 700px;
        border: 1px solid red;
        background-image: url("images/book_cover.jpg");
        /*預設是全部平鋪的 repeat*/
    }
    /*水平平鋪*/
    .div1{
        background-repeat: repeat-x;
    }
    /*豎直平鋪*/
    .div2{
        background-repeat: repeat-y;
    }
    /*不平鋪*/
    .div3{
        background-repeat: no-repeat;
    }
</style>

8. 漸變

background-color: #00DBDE;
background-image: linear-gradient(40deg, #00DBDE 0%, #FC00FF 100%);