Html+Css

CSS 初识

2018-11-25  本文已影响0人  roy_pub

CSS 用来设置HTML外观显示样式。

样式表

<head>
    <style type="text/css">
        p {
            color: red;
            font-size: 25;
        }
    </style>
</head>
    <p style="color: pink; font-size: 25px;">Hello World CSS</p>
<head>
    <link href="css file path" type="text/css" rel="stylesheet">
</head>

基础选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        p {
            color: red;
            font-size: 25;
        }
    </style>
</head>
<body>

<p>Hello World</p>
<p>CSS</p>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        span {
            font-size: 100px;
        }

        .g {
            color: deepskyblue;
        }

        .o {
            color: red;
        }

        .oo {
            color: orange;
        }

        .l {
            color: green;
        }
    </style>
</head>
<body>
    <span class="g">G</span>
    <span class="o">o</span>
    <span class="oo">o</span>
    <span class="g">g</span>
    <span class="l">l</span>
    <span class="o">e</span>
</body>
</html>

多类名选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        .green {
            color: green;
        }

        .font {
            font-size: 50px;
        }
    </style>
</head>
<body>
  <div class="green font">Hello World!</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        #green {
            color: green;
        }
    </style>
</head>
<body>
  <div id="green">Hello World!</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        * {
            color: green;
        }
    </style>
</head>
<body>
    <div>Hello World!</div>
    <div>How are you</div>
</body>
</html>

复合选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        div p {
            color: cyan;
        }
    </style>
</head>
<body>
    <div>
        <p>Hello World</p>
    </div>
    <div>Hello World</div>
    <p>Hello World</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        div a {
            color: cyan;
        }

    </style>
</head>
<body>
    <div>
        <a href="#">AliBaBa</a>
        <ul>
            <li>
                <a href="#">AliPay</a>
            </li>
        </ul>
    </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        div > a {
            color: cyan;
        }

    </style>
</head>
<body>
    <div>
        <a href="#">AliBaBa</a>
        <ul>
            <li>
                <a href="#">AliPay</a>
            </li>
        </ul>
    </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        div.red {
            color: cyan;
        }
    </style>
</head>
<body>
    <div>Hello world</div>
    <div class="red">Hello world</div>
    <p>Hello world</p>
    <p class="red">Hello world</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        div,span {
            color: cyan;
        }
    </style>
</head>
<body>
    <div>Hello world</div>
    <p>Hello world</p>
    <span>Hello world</span>
</body>
</html>

伪类选择器

伪类选择器用于向某些选择器添加特殊的效果,如如给链接添加效果。伪类选择器使用":"
链接伪类选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <style type="text/css">
        a {
            font-size: 20px;
            font-weight: 400;
        }

        a:link {
            color: gray;
        }

        a:visited {
            color: red;
        }

        a:hover {
            color: green;
        }

        a:active {
            color: cyan;
        }

    </style>
</head>
<body>
    <a href="#">Baidu</a>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读