CSS常见样式

基本语法

1.语法结构:
选择器
{
属性:属性值;
属性:属性值;
}
2.控制字体:
设置字号----font-size:12px;
设置颜色----color:英文单词;
设置字体----font-family:“宋体”;
设置粗细----font-weight:bold;
设置行高----line-height:150%,1.5em,20px;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS常见样式</title>
    <style>
        p
        {
            font-size: large;
            color: red;
            font-family: "宋体";
            line-height: 300%;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <p>这是一个p标签</p>
    
</body>
</html>

3.样式的特点:
(1)继承性:页面中子元素将会继承父元素的样式
(2)层叠性:子元素与父元素同时存在,子元素会覆盖掉父元素的样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>样式的特点</title>
    <style>
        body
        {
            color: red;

        }
    </style>
</head>
<body>
    <p>这是一个段落</p>
</body>
</html>

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>样式的特点</title>
    <style>
        body
        {
            color: red;

        }
        p
        {
            color: blue;
        }
    </style>
</head>
<body>
    <p>这是一个段落</p>
</body>
</html>

在这里插入图片描述4.控制文本
text-align----文本对齐方式:left,right,center

标签含义
text-indent设置文本的缩进:2em(可以取负数)
text-align文本对齐方式:left,right,center
text-transform文本的大小写
text-decoration超链接下划线
list-style无序列表前方序号形状

5.案例:导航栏样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>导航栏</title>
    <style>
        *
        {
            margin: 0;/*外对其*/
            padding: 0;/*内对其*/
        }
        .nav/*盒子标签*/
        {
            border: 1px solod black;
            width: 1080px;
            height: 60px;
            background-image: url(../img/bg.jpg);  /*background-color: black;*/
        }
        li
        {
            /* border: 1px solid black; */
            width: 120px;
            height: 60px;
            float: left;
            list-style: none;
            text-indent: 2em;
           
        }
        a/*注意就近原则!有些需要写在"a"标签里,有些需要写在"li"里*/
        {
            color: white;
            font-size: 18px;
            font-family: "宋体";
            line-height: 60px;
            text-decoration: double;
            /* text-indent: 2em; */

        }
        li:hover
        {
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="nav">
        <ul>
            <li><a href="#">游戏一</a></li>
            <li><a href="#">游戏二</a></li>
            <li><a href="#">游戏三</a></li>
            <li><a href="#">游戏四</a></li>
            <li><a href="#">游戏五</a></li>
            <li><a href="#">游戏六</a></li>
            <li><a href="#">游戏七</a></li>
            <li><a href="#">游戏八</a></li>
            <li><a href="#">游戏九</a></li>
        </ul>
    </div>
  
</body>
</html>

在这里插入图片描述

6.案例:商品展示

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品展示</title>
    <style>
        *
        {
            margin: 0;
            padding: 0;
        }
        .container
        {
            /* border: 1px solid black; */
            width: 1200px;
            height: 2000px;
            margin: 0 auto;
        }
        .goods
        {
            border: 1px solid white;
            width: 250px;
            height: 400px;
            float: left;
            margin:  10px;
        }
        .goods:hover
        {
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="goods">
            <img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
            <div style="/*border: 1px solid black;*/  height: 30px;">
                <span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
                <span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
            </div>
            <p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
            <div style="/*border: 1px solid black;*/   height: 30px; line-height: 40px;">
                <span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
                <span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
            </div>
        </div>
        <div class="goods">
            <img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
            <div style="/*border: 1px solid black;*/  height: 30px;">
                <span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
                <span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
            </div>
            <p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
            <div style="/*border: 1px solid black;*/   height: 30px; line-height: 40px;">
                <span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
                <span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
            </div>
        </div>
        <div class="goods">
            <img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
            <div style="/*border: 1px solid black;*/  height: 30px;">
                <span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
                <span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
            </div>
            <p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
            <div style="/*border: 1px solid black;*/   height: 30px; line-height: 40px;">
                <span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
                <span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
            </div>
        </div>
        <div class="goods">
            <img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
            <div style="/*border: 1px solid black;*/  height: 30px;">
                <span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
                <span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
            </div>
            <p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
            <div style="/*border: 1px solid black;*/   height: 30px; line-height: 40px;">
                <span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
                <span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
            </div>
        </div>
        <div class="goods">
            <img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
            <div style="/*border: 1px solid black;*/  height: 30px;">
                <span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
                <span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
            </div>
            <p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
            <div style="/*border: 1px solid black;*/   height: 30px; line-height: 40px;">
                <span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
                <span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
            </div>
        </div>
        <div class="goods">
            <img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
            <div style="/*border: 1px solid black;*/  height: 30px;">
                <span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
                <span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
            </div>
            <p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
            <div style="/*border: 1px solid black;*/   height: 30px; line-height: 40px;">
                <span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
                <span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
            </div>
        </div>
        <div class="goods">
            <img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
            <div style="/*border: 1px solid black;*/  height: 30px;">
                <span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
                <span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
            </div>
            <p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
            <div style="/*border: 1px solid black;*/   height: 30px; line-height: 40px;">
                <span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
                <span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
            </div>
        </div>
        <div class="goods">
            <img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
            <div style="/*border: 1px solid black;*/  height: 30px;">
                <span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
                <span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
            </div>
            <p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
            <div style="/*border: 1px solid black;*/   height: 30px; line-height: 40px;">
                <span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
                <span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
            </div>
        </div>

    </div>
</body>
</html>

在这里插入图片描述
(其中有许多标签是笔记里没有写的,需要读者有一定的自学能力去"W3school"网站自行搜索学习,另外,因时间仓促和作者水平有限等原因,导致代码编写复杂不便观看,请读者见谅。)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值