CSS总结笔记+案例

news2024/9/25 12:18:21

此文章属于前端篇中的第二节CSS样式
继前期HTML标记语言

CSS总结笔记:

3.CSS样式

css,专门用来“美化”标签。

  • 基础CSS,写简单页面&看懂&改。
  • 模块、调整和修改

3.1CSS应用方法

1.在标签上

- 高度和宽度样式:
<img src="xxx" style="height:100px;" />
- 颜色样式:
<div style="color:red;">中国联通</div>

2.在head标签中写style标签

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <style>
        .c1{
            color:red;
        }
    </style>
</head>
<body>
    <h1 class='c1'>用户登录</h1>
    <form method="post" action="/login">
        <div>
            用户名:<input type="text" name="username">
        </div>
        <div>
            密码:<input type="password" name="password">
        </div>
        <input type="submit">
    </form>
</body>
</html>

3.写到文件中

.c1{
    height:100px;
}
.c2{
    color:red;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <link rel="stylesheet" href="common.css" />
</head>
<body>
   
</body>
</html>

案例:Flask中的应用(登录注册)

CSS文件:

.xx{
    color: green;
}

login.html文件(在HTML头内写CSS):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <style>
        .c1{
            color: red;
        }
        .c2{
            height: 50px;
        }
    </style>
</head>
<body>
    <h1 class="c1">用户登录</h1>
    <form method="post" action="/login">
        <div class="c2">
            用户名:<input type="text" name="username">
        </div>
        <div class="c2">
            密码:<input type="password" name="password">
        </div>
        <input type="submit">
    </form>
</body>
</html>

register.html文件(在外部引入CSS文件):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
    <link rel="stylesheet" href="/static/commons.css">
</head>
<body>
<h1 class="xx">用户注册</h1>
<div>
    用户名:<input type="text">
</div>
<div>
    密码:<input type="password">
</div>

<div>
    性别:<input type="radio"><input type="radio"></div>

<div>
    爱好:
    <input type="checkbox">篮球
    <input type="checkbox">足球
    <input type="checkbox">乒乓球
</div>

<div>
    擅长的领域:
    <select multiple>
        <option>Python</option>
        <option>C++</option>
        <option>Java</option>
    </select>
</div>

<div>
    备注:<textarea></textarea>
</div>

<div>
    <input type="button" value="button按钮">
    <input type="submit" value="button按钮">
</div>

</body>
</html>

3.2CSS选择器

  • ID选择器(id)

    #c2{
        color: gold;
    }
    <div id="c2">美国</div>
    
  • 类选择器(class)

    .c1{
        color: red;
    }
    <div class="c1">中国</div>
    
  • 标签选择器

    li{
        color: pink;
    }
    <ul>
        <li>北京</li>
        <li>上海</li>
        <li>深圳</li>
    </ul>
    
  • 属性选择器

    input[type='text']{
                border: 1px solid red;
            }
            .v1[xx="456"]{
                color: gold;
            }
    
    <div class="v1" xx="123">a</div>
    <div class="v1" xx="456">b</div>
    <div class="v1" xx="999">c</div>
    
  • 后代选择器

    无穷代:

    .yy li{
    	color: pink;
    }
    
    <div class="yy">
        <ul>
            <li>美国</li>
            <li>日本</li>
            <li>韩国</li>
        </ul>
    </div>
    

    一代:

    .yy > a{
        color: blue;
    }
    
    <div class="yy">
        <a>百度</a>
        <div>
            <a>谷歌</a>
        </div>
        <ul>
            <li>美国</li>
            <li>日本</li>
            <li>韩国</li>
        </ul>
    </div>
    

关于选择器:

使用频率多:类选择器、标签选择器、后代选择器
使用频率少:属性选择器、ID选择器

关于多个样式覆盖问题:

若样式重复,style最后一个样式为最终样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            color: red;
            border: 1px solid red;
        }
        .c2{
            font-size: 28px;
            color: green;
        }
    </style>
</head>
<body>
    <div class="c1 c2">中国联通</div>
</body>
</html>

若不想覆盖(加入! important):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            color: red !important;
            border: 1px solid red;
        }
        .c2{
            font-size: 28px;
            color: green;
        }
    </style>
</head>
<body>
    <div class="c1 c2">中国联通</div>
</body>
</html>

3.4样式

1.高度和宽度

.c1{
    height: 300px;
    width: 500px;
}

注意:宽度,支持百分比。

2.块级和行内标签

  • 块级
  • 行内
  • css样式(既有块级又有行内标签特点):标签 -> display:inline-block
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            display: inline-block;
            height: 100px;
            width: 300px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <span class="c1">中国移动</span>
    <span class="c1">中国联通</span>
    <span class="c1">中国电信</span>
</body>
</html>

块级和行内标签的转换:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div style="display: inline-block">中国</div>
    <span style="display:block;">联通</span>
</body>
</html>

高频率:块级+块级&行内。

3.字体和颜色

  • color:颜色
  • font-size:大小
  • font-weight:加粗
  • font-family:字体格式
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            color: red;
            font-size: 18px;
            font-weight: 500;
            font-family: Microsoft YaHei UI;
        }
    </style>
</head>
<body>
    <div class="c1">中国联通</div>
    <div>中国移动</div>
</body>
</html>

4.文字对齐方式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            height: 59px;
            width: 300px;
            border: 1px solid red;
            text-align: center; /* 水平方向居中 */
            line-height: 59px; /* 垂直方向居中*/
        }
    </style>
</head>
<body>
    <div class="c1">刘备</div>
</body>
</html>

5.浮动

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <div>
    <span>左边</span>
    <span style="float: right">右边</span>
  </div>
</body>
</html>

div默认块级标签,若浮动起来自己有多宽占多宽。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .item{
            float: left;
            width: 200px;
            height: 170px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
  <div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
  </div>
</body>
</html>

如果标签浮动起来,就会脱离文档流。

解决:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .item{
            float: left;
            width: 200px;
            height: 170px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
  <div style="background-color: dodgerblue">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div style="clear: both"></div>
  </div>
</body>
</html>

6.内边距

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .outer{
            border: 1px solid red;
            height: 200px;
            width: 200px;

            padding-top: 20px;
            padding-left: 20px;
            padding-right: 20px;
        }
    </style>
</head>
<body>
    <div class="outer">
        <div style="background-color: gold">刘备</div>
        <div>
            汉景帝第十九代玄孙
        </div>
    </div>
</body>
</html>

7.外边距

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div style="height: 200px;background-color: dodgerblue"></div>
    <div style="background-color: red;height: 100px;margin-top: 10px;"></div>
</body>
</html>

案例:小米商城(导航条)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
        }
        .header{
            height: 38px;
            color: #b0b0b0;
            background: #333;
        }
        .container{
            width: 1226px;
            margin: 0 auto;
        }
        .header .menu{
            float: left;
            color: white;
            height: 38px;
        }
        .header .account{
            float: right;
            color: white;
            height: 38px;
            line-height: 38px;
        }
        .header a{
            color: #b0b0b0;
            line-height: 40px;
            display: inline-block;
            font-size: 12px;
            margin-right: 10px;
        }

    </style>
</head>
<body>

<div class="header">
    <div class="container">
        <div class="menu">
            <a>小米商城</a>
            <a>MIUI</a>
            <a>云服务</a>
            <a>有品</a>
            <a>开放平台</a>
        </div>
        <div class="account">
            <a>登录</a>
            <a>注册</a>
            <a>消息通知</a>
        </div>
        <div style="clear: both"></div>
    </div>
</div>

</body>
</html>

总结

  • body标签,默认有一个边距,造成页面四边都有白色间隙,如何去除?

    body{
    	margin: 0;
    }
    
  • 内容居中

    • 文本居中,文本会在这个区域中居中。

      <div style="width: 200px; text-align: center">刘备</div>
      
    • 区域居中,自己要有宽度 + margin-left:auto;margin-right:auto

      .container{
          width: 980px;
          margin: 0 auto;
      }
      <div class="container">xxx</div>
      
  • 父级没有高度或者宽度,被本级支撑起来。

  • 若存在浮动,一定记得加入<div style="clear: both"></div>

案例:小米商城二级菜单

1.骨架部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
        }
        .sub-header{
            height: 100px;
            background-color: #b0b0b0;
        }
        .container{
            width: 1226px;
            margin-right: auto;
            margin-left: auto;
        }
        .sub-header .ht{
            height: 88px;
        }
        .sub-header .logo{
            width: 234px;
            float: left;
        }
        .sub-header .menu-list{
            float: left;
        }
        .sub-header .search{
            float: right;
        }
    </style>
</head>
<body>
<div class="sub-header">
    <div class="container">
        <div class="ht logo">abc</div>
        <div class="ht menu-list">abc</div>
        <div class="ht search">asd</div>
        <div style="clear:both"></div>
    </div>
</div>
</body>
</html>

2.logo部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
        }
        .sub-header{
            height: 100px;
            background-color: #b0b0b0;
        }
        .container{
            width: 1226px;
            margin-right: auto;
            margin-left: auto;
        }
        .sub-header .ht{
            height: 88px;
        }
        .sub-header .logo{
            width: 234px;
            float: left;
        }
        .sub-header .logo a{
            margin-top: 22px;
            display: inline-block
        }
        .sub-header .logo a img{
            height: 56px;width: 56px;
        }
        .sub-header .menu-list{
            float: left;
        }
        .sub-header .search{
            float: right;
        }
    </style>
</head>
<body>
<div class="sub-header">
    <div class="container">
        <div class="ht logo">
            <!-- a,行内标签;默认设置为高度、边距无效。 -> 块级 -->
            <a href="https://www.mi.com/">
                <img src="/images/logo-mi2.png">
            </a>
        </div>
        <div class="ht menu-list">abc</div>
        <div class="ht search">asd</div>
        <div style="clear:both"></div>
    </div>
</div>
</body>
</html>

3.菜单部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
        }

        .sub-header{
            height: 100px;
        }

        .container{
            width: 1226px;
            margin-right: auto;
            margin-left: auto;
        }

        .sub-header .ht{
            height: 100px;
        }

        .sub-header .logo{
            width: 234px;
            float: left;
        }

        .sub-header .logo a{
            margin-top: 22px;
            display: inline-block
        }

        .sub-header .logo a img{
            height: 56px;width: 56px;
        }

        .sub-header .menu-list{
            float: left;
            line-height: 100px;
            border: 1px;
        }

        .sub-header .menu-list a{
            padding: 0 10px;
            display: inline-block;
            color: #333;
            font-size: 16px;
            /*去掉链接下划线*/
            text-decoration: none;
        }

        /*hover当鼠标悬停*/
        .sub-header .menu-list a:hover{
            color: darkorange;
        }

        .sub-header .search{
            float: right;
        }
    </style>
</head>
<body>
<div class="sub-header">
    <div class="container">
        <div class="ht logo">
            <!-- a,行内标签;默认设置为高度、边距无效。 -> 块级 -->
            <a href="https://www.mi.com/">
                <img src="/images/logo-mi2.png">
            </a>
        </div>
        <div class="ht menu-list">
            <a href="https://www.mi.com/">Xiaomi手机</a>
            <a href="https://www.mi.com/">Redmi手机</a>
            <a href="https://www.mi.com/">电视</a>
            <a href="https://www.mi.com/">笔记本</a>
            <a href="https://www.mi.com/">平板</a>
        </div>
        <div class="ht search"></div>
        <div style="clear:both"></div>
    </div>
</div>
</body>
</html>

4.顶部菜单+二级菜单

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
        }
        .header{
            height: 38px;
            color: #b0b0b0;
            background: #333;
        }
        .container{
            width: 1226px;
            margin: 0 auto;
        }
        .header .menu{
            float: left;
            color: white;
            height: 38px;
        }
        .header .account{
            float: right;
            color: white;
            height: 38px;
            line-height: 38px;

            text-decoration: none;
        }
        .header a{
            color: #b0b0b0;
            line-height: 40px;
            display: inline-block;
            font-size: 12px;
            margin-right: 10px;

            text-decoration: none;
        }
        .header .account:hover{
            color: white;
        }
        .header a:hover{
            color: white;
        }


        .sub-header{
            height: 100px;
        }

        .sub-header .ht{
            height: 100px;
        }

        .sub-header .logo{
            width: 234px;
            float: left;
        }

        .sub-header .logo a{
            margin-top: 22px;
            display: inline-block
        }

        .sub-header .logo a img{
            height: 56px;width: 56px;
        }

        .sub-header .menu-list{
            float: left;
            line-height: 100px;
            border: 1px;
        }

        .sub-header .menu-list a{
            padding: 0 10px;
            display: inline-block;
            color: #333;
            font-size: 16px;
            /*去掉链接下划线*/
            text-decoration: none;
        }

        /*hover当鼠标悬停*/
        .sub-header .menu-list a:hover{
            color: darkorange;
        }

        .sub-header .search{
            float: right;
        }

    </style>
</head>
<body>

<div class="header">
    <div class="container">
        <div class="menu">
            <a href="https://www.mi.com/">小米商城</a>
            <a href="https://www.mi.com/">MIUI</a>
            <a href="https://www.mi.com/">云服务</a>
            <a href="https://www.mi.com/">有品</a>
            <a href="https://www.mi.com/">开放平台</a>
        </div>
        <div class="account">
            <a href="https://www.mi.com/">登录</a>
            <a href="https://www.mi.com/">注册</a>
            <a href="https://www.mi.com/">消息通知</a>
        </div>
        <div style="clear: both"></div>
    </div>
</div>

<div class="sub-header">
    <div class="container">
        <div class="ht logo">
            <!-- a,行内标签;默认设置为高度、边距无效。 -> 块级 -->
            <a href="https://www.mi.com/">
                <img src="/images/logo-mi2.png">
            </a>
        </div>
        <div class="ht menu-list">
            <a href="https://www.mi.com/">Xiaomi手机</a>
            <a href="https://www.mi.com/">Redmi手机</a>
            <a href="https://www.mi.com/">电视</a>
            <a href="https://www.mi.com/">笔记本</a>
            <a href="https://www.mi.com/">平板</a>
        </div>
        <div class="ht search"></div>
        <div style="clear:both"></div>
    </div>
</div>

</body>
</html>

小结

  • a标签是行内标签,行内标签的高度、内外边距,默认无效。

  • 垂直方向居中

    • 文本:line-height
    • 图片:边距
  • a标签默认有下划线。(去除:text-decoration: none;

  • 鼠标放上去之后(hover)

    a:hover{
    	color: white;
    }
    

案例:小米商城推荐区域

若想还原,图片部分自行加入

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
        }

        img {
            width: 100%;
            height: 100%;
        }

        .left{
            float: left;
        }

        .header{
            height: 38px;
            color: #b0b0b0;
            background: #333;
        }
        .container{
            width: 1226px;
            margin: 0 auto;
        }
        .header .menu{
            float: left;
            color: white;
            height: 38px;
        }
        .header .account{
            float: right;
            color: white;
            height: 38px;
            line-height: 38px;

            text-decoration: none;
        }
        .header a{
            color: #b0b0b0;
            line-height: 40px;
            display: inline-block;
            font-size: 12px;
            margin-right: 10px;

            text-decoration: none;
        }
        .header .account:hover{
            color: white;
        }
        .header a:hover{
            color: white;
        }


        .sub-header{
            height: 100px;
        }

        .sub-header .ht{
            height: 100px;
        }

        .sub-header .logo{
            width: 234px;
            float: left;
        }

        .sub-header .logo a{
            margin-top: 22px;
            display: inline-block
        }

        .sub-header .logo a img{
            height: 56px;width: 56px;
        }

        .sub-header .menu-list{
            float: left;
            line-height: 100px;
            border: 1px;
        }

        .sub-header .menu-list a{
            padding: 0 10px;
            display: inline-block;
            color: #333;
            font-size: 16px;
            /*去掉链接下划线*/
            text-decoration: none;
        }

        /*hover当鼠标悬停*/
        .sub-header .menu-list a:hover{
            color: darkorange;
        }

        .sub-header .search{
            float: right;
        }

        .slider img{
            width: 1226px;
            height: 460px;
        }

        .news .channel{
            width: 228px;
            height: 164px;
            background-color: #333333;
            padding: 3px;
        }

        .news .list-item{
            width: 316px;
            height: 170px;
        }

        .news .channel .item{
            height: 86px;
            width: 76px;
            float: left;
            text-align: center;
            opacity: 0.5;
        }

        .news .channel .item img{
            height: 24px;
            width: 24px;
            display: block;
            margin: 0 auto 4px;
        }

        .news .channel .item a{
            font-size: 12px;
            display: inline-block;
            padding-top: 18px;
            color: #fff;
            text-decoration: none;
        }

        .news .channel .item a:hover{
            opacity: 1;
        }

        .news{
            margin-top: 14px;
        }



    </style>
</head>
<body>

<div class="header">
    <div class="container">
        <div class="menu">
            <a href="https://www.mi.com/">小米商城</a>
            <a href="https://www.mi.com/">MIUI</a>
            <a href="https://www.mi.com/">云服务</a>
            <a href="https://www.mi.com/">有品</a>
            <a href="https://www.mi.com/">开放平台</a>
        </div>
        <div class="account">
            <a href="https://www.mi.com/">登录</a>
            <a href="https://www.mi.com/">注册</a>
            <a href="https://www.mi.com/">消息通知</a>
        </div>
        <div style="clear: both"></div>
    </div>
</div>

<div class="sub-header">
    <div class="container">
        <div class="ht logo">
            <!-- a,行内标签;默认设置为高度、边距无效。 -> 块级 -->
            <a href="https://www.mi.com/">
                <img src="/images/logo-mi2.png">
            </a>
        </div>
        <div class="ht menu-list">
            <a href="https://www.mi.com/">Xiaomi手机</a>
            <a href="https://www.mi.com/">Redmi手机</a>
            <a href="https://www.mi.com/">电视</a>
            <a href="https://www.mi.com/">笔记本</a>
            <a href="https://www.mi.com/">平板</a>
        </div>
        <div class="ht search"></div>
        <div style="clear:both"></div>
    </div>
</div>

<div class="slider">
    <div class="container">
        <div class="sd-img">
            <img src="/images/b1.png">
        </div>
    </div>
</div>

<div class="news">
    <div class="container">
        <div class="channel left">
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div style="clear: both"></div>
        </div>
        <div class="list-item left" style="margin-left: 14px">
            <img src="/images/list1.png" />
        </div>
        <div class="list-item left" style="margin-left: 15px">
            <img src="/images/list2.png" />
        </div>
        <div class="list-item left" style="margin-left: 15px">
            <img src="/images/list3.png" />
        </div>
        <div style="clear: both"></div>
    </div>
</div>

</body>
</html>

在这里插入图片描述

设置透明度:

.c1{
    opacity: 1;
}

CSS知识点

hover

鼠标悬停显示图片

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            font-size: 18px;
            color: gold;
        }
        .c1:hover{
            font-size: 50px;
            color: darkorange;
        }
        .c2{
            height: 300px;
            width: 500px;
            border: 1px solid red;
        }
        .c2:hover{
            border: 2px solid green;
        }

        .download{
            display: none;
        }

        .app:hover .download{
            display: block;
        }

    </style>
</head>
<body>
    <div class="c1">移动</div>
    <div class="c2">联通</div>

    <div class="app">
        <div>点击下载</div>
            <div class="download">
                <img src="/images/app.png">
            </div>
    </div>
</body>
</html>

after

c1样式后都加入content内容

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1:after{
            content: "五虎上将";
        }
    </style>
</head>
<body>
    <div class="c1">关羽</div>
    <div class="c1">张飞</div>
    <div class="c1">赵云</div>
    <div class="c1">黄忠</div>
    <div class="c1">马超</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .clearfix:after{
            content: "";
            display: block;
            clear: both;
        }
    </style>
</head>
<body>
    <div class="clearfix">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
    </div>
</body>
</html>

position

  • fixed
  • relative
  • absolute
1.fiex

固定在窗口的某个位置

案例:固定客服电话位置
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            background-color: #b0b0b0;
            height: 2000px;
            width: 1226px;
            margin: 0 auto;
        }

        .c2{
            position: fixed;
            border: 2px solid red;
            height: 64px;
            width: 64px;

            right: 10px;
            bottom: 100px;
        }
    </style>
</head>
<body>
    <div class="c1"></div>
    <div class="c2">客服电话</div>
</body>
</html>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eLO61OeU-1674037685954)(C:/Users/lq/AppData/Roaming/Typora/typora-user-images/image-20230118165015951.png)]

案例:对话框

z-index:定义position在哪一层,数值越大在越上层

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            background-color: #b0b0b0;
            height: 2000px;
            width: 1226px;
            margin: 0 auto;
        }

        .c2{
            position: fixed;
            left: 0;
            right: 0;
            margin: 0 auto;
            height: 500px;
            width: 400px;
            background-color:  white;
            top: 200px;
            z-index: 10;
        }

        .mask{
            position: fixed;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            background-color: black;
            opacity: 0.7;
            z-index: 9;
        }

    </style>
</head>
<body>
    <!--背景-->
    <div class="c1"></div>
    <!--幕布-->
    <div class="mask"></div>
    <!--对话框-->
    <div class="c2"></div>
</body>
</html>

在这里插入图片描述

2.relative和absolute

相对进行显示:

父类加上position:relative

子类加上position:absolute

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            height: 500px;
            width: 700px;
            border: 1px solid red;
            position: relative;
        }

        .c1 .c2{
            background-color: gold;
            position: absolute;
            height: 100px;
            width: 100px;
            right: 0;
        }
    </style>
</head>
<body>
    <div class="c1">
        <div class="c2"></div>
    </div>
</body>
</html>

在这里插入图片描述

案例:在相对位置添加二维码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
        }

        img {
            width: 100%;
            height: 100%;
        }

        .left{
            float: left;
        }

        .header{
            height: 38px;
            color: #b0b0b0;
            background: #333;
        }
        .container{
            width: 1226px;
            margin: 0 auto;
        }
        .header .menu{
            float: left;
            color: white;
            height: 38px;
        }
        .header .account{
            float: right;
            color: white;
            height: 38px;
            line-height: 38px;

            text-decoration: none;
        }
        .header a{
            color: #b0b0b0;
            line-height: 40px;
            display: inline-block;
            font-size: 12px;
            margin-right: 10px;

            text-decoration: none;
        }
        .header .account:hover{
            color: white;
        }
        .header a:hover{
            color: white;
        }


        .sub-header{
            height: 100px;
        }

        .sub-header .ht{
            height: 100px;
        }

        .sub-header .logo{
            width: 234px;
            float: left;
        }

        .sub-header .logo a{
            margin-top: 22px;
            display: inline-block
        }

        .sub-header .logo a img{
            height: 56px;width: 56px;
        }

        .sub-header .menu-list{
            float: left;
            line-height: 100px;
            border: 1px;
        }

        .sub-header .menu-list a{
            padding: 0 10px;
            display: inline-block;
            color: #333;
            font-size: 16px;
            /*去掉链接下划线*/
            text-decoration: none;
        }

        /*hover当鼠标悬停*/
        .sub-header .menu-list a:hover{
            color: darkorange;
        }

        .sub-header .search{
            float: right;
        }

        .slider img{
            width: 1226px;
            height: 460px;
        }

        .news .channel{
            width: 228px;
            height: 164px;
            background-color: #333333;
            padding: 3px;
        }

        .news .list-item{
            width: 316px;
            height: 170px;
        }

        .news .channel .item{
            height: 86px;
            width: 76px;
            float: left;
            text-align: center;
            opacity: 0.5;
        }

        .news .channel .item img{
            height: 24px;
            width: 24px;
            display: block;
            margin: 0 auto 4px;
        }

        .news .channel .item a{
            font-size: 12px;
            display: inline-block;
            padding-top: 18px;
            color: #fff;
            text-decoration: none;
        }

        .news .channel .item a:hover{
            opacity: 1;
        }

        .news{
            margin-top: 14px;
        }

        .app{
            position: relative;
        }

        .app .download{
            position: absolute;
            width: 100px;
            display: none;
        }

        .app:hover .download{
            display: block;
        }

    </style>
</head>
<body>

<div class="header">
    <div class="container">
        <div class="menu">
            <a href="https://www.mi.com/">小米商城</a>
            <a href="https://www.mi.com/">MIUI</a>
            <a href="https://www.mi.com/">云服务</a>
            <a href="https://www.mi.com/">有品</a>
            <a href="https://www.mi.com/">开放平台</a>
            <a href="https://www.mi.com/" class="app">App下载
            <div class="download">
                <img src="images/app.png">
            </div>
            </a>
        </div>
        <div class="account">
            <a href="https://www.mi.com/">登录</a>
            <a href="https://www.mi.com/">注册</a>
            <a href="https://www.mi.com/">消息通知</a>
        </div>
        <div style="clear: both"></div>
    </div>
</div>

<div class="sub-header">
    <div class="container">
        <div class="ht logo">
            <!-- a,行内标签;默认设置为高度、边距无效。 -> 块级 -->
            <a href="https://www.mi.com/">
                <img src="/images/logo-mi2.png">
            </a>
        </div>
        <div class="ht menu-list">
            <a href="https://www.mi.com/">Xiaomi手机</a>
            <a href="https://www.mi.com/">Redmi手机</a>
            <a href="https://www.mi.com/">电视</a>
            <a href="https://www.mi.com/">笔记本</a>
            <a href="https://www.mi.com/">平板</a>
        </div>
        <div class="ht search"></div>
        <div style="clear:both"></div>
    </div>
</div>

<div class="slider">
    <div class="container">
        <div class="sd-img">
            <img src="/images/b1.png">
        </div>
    </div>
</div>

<div class="news">
    <div class="container">
        <div class="channel left">
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>
            <div class="item">
                <a href="https://www.mi.com/">
                    <img src="/images/c1.png" >
                    <span>保障服务</span>
                </a>
            </div>

            <div style="clear: both"></div>
        </div>
        <div class="list-item left" style="margin-left: 14px">
            <img src="/images/list1.png" />
        </div>
        <div class="list-item left" style="margin-left: 15px">
            <img src="/images/list2.png" />
        </div>
        <div class="list-item left" style="margin-left: 15px">
            <img src="/images/list3.png" />
        </div>
        <div style="clear: both"></div>
    </div>
</div>

</body>
</html>

边框

  • border:1px 1像素边框
  • solid red 实心红色
  • dotted red 虚线红色
  • border-left 指定边框

背景色

  • background-color

总结

以上是CSS常用功能

在开发过程中会用到BootSrap模板

模板:

  • 模板基本使用逻辑
  • 模板+自己的CSS

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/170725.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

linux基本功系列之alias命令实战

本文目录 文章目录前言&#x1f680;&#x1f680;&#x1f680;一. alias命令介绍二. 语法格式及常用选项三. 参考案例3.1 查看系统已经存在的别名3.2 设置别名的操作3.3 取消别名3.4 alias的全局生效和当前用户生效四. 使用命令的注意事项总结前言&#x1f680;&#x1f680;…

行云洞见 | 为什么说云端IDE代表未来趋势?

原文作者&#xff1a;行云创新解决方案架构师 李楠 预知未来最可靠的方法是了解历史&#xff0c;让我们简单回顾下IDE的发展史。 所谓IDE&#xff0c;即集成开发环境&#xff0c;是软件开发人员在他们用于编程的计算机本地安装的应用程序。伴随着计算机编程语言从第一代机器语…

【NI Multisim 14.0虚拟仪器设计——放置虚拟仪器仪表(万用表)】

目录 序言 &#x1f34d;放置虚拟仪器仪表 &#x1f349;万用表 序言 NI Multisim最突出的特点之一就是用户界面友好。它可以使电路设计者方便、快捷地使用虚拟元器件和仪器、仪表进行电路设计和仿真。 首先启动NI Multisim 14.0&#xff0c;打开如图所示的启动界面&#x…

【虹科分享】虹科ATEasy软件,您的测试执行和开发专家!

测试和执行专家 虹科ATEasy是功能测试&#xff0c;自动测试系统&#xff0c;数据采集&#xff0c;过程控制和仪表系统的测试执行和快速应用开发框架。虹科ATEasy提供开发&#xff0c;部署和维护软件组件的所有必要工具&#xff0c;包括仪器驱动程序&#xff0c;测试程序&#x…

SGA与PGA的区别

前几天有被别人问到什么是SGA和PGA&#xff0c;说实在的&#xff0c;之前一直搞分布式&#xff0c;已经基本把单机里面的这两个概念忘记的差不多了&#xff0c;不过当时还是根据自己的一点数据库经验说了点七七八八&#xff0c;后来网上查了一下相关说明&#xff0c;发现自己的…

现货黄金与白银现货的区别

黄金与白银同为贵金属&#xff0c;二者均在人类货币史上担当过货币的功能&#xff0c;而现货黄金与白银现货作为其最重要的金融衍生品&#xff0c;都具备良好的收益性、流动性和的可操作性&#xff0c;都是比较理想的投资产品。那么和现货黄金和白银现货的区别在哪里呢?小编认…

C++初学者学习笔记

面向对象的程序设计 初步理解 相比较于面向过程的程序设计来说有更多的封装的函数可以使用&#xff0c;相比较来说会比较方便。但是如何去设计整个程序的思路也是需要一定的训练的。 C 简介 C 是一种静态类型的、编译式的、通用的、大小写敏感的、不规则的编程语言&#xf…

linux系统目录结构

在 Linux 或 Unix 操作系统中&#xff0c;所有的文件和目录都被组织成以一个根节点开始的倒置的树状结构。 文件系统的最顶层是由根目录开始的&#xff0c;系统使用 / 来表示根目录。在根目录之下的既可以是目录&#xff0c;也可以是文件&#xff0c;而每一个目录中又可以包含…

【荐书】C程序设计语言(第二版)

“在大多数人眼中&#xff0c;我是个一事无成、乖僻古怪、令人作呕的人。我毫无社会地位可言&#xff0c;也永远不会有。总之&#xff0c;我是底层人中的底层人。好吧&#xff0c;就算这些看法都完全正确&#xff0c;我也想有那么一天&#xff0c;通过我的作品向他们展示&#…

C++模板(函数模板,类模板)的基本使用与非类型模板参数与模板的特化

C模板模板初阶泛型编程函数模板函数模板概念函数模板格式函数模板的原理函数模板的实例化隐式实例化显式实例化&#xff1a;在函数名后的<>中指定模板参数的实际类型模板参数的匹配原则类模板类模板的定义格式类模板的实例化模板进阶非类型模板参数模板的特化概念函数模板…

【TypeScript】TS与Vue

TypeScript与Vue 文章目录TypeScript与VuedefineProps与TypescriptdefineEmits与Typescriptref与Typescriptreactive与Typescriptcomputed与Typescript事件处理与TypescriptTemplate Ref与Typescript可选链操作符非空断言参考链接&#xff1a;https://vuejs.org/guide/typescri…

【OpenGL学习】texture

纹理 一、什么是纹理&#xff1f; 引用百度百科的定义&#xff1a; 计算机图形学中的纹理既包括通常意义上物体表面的纹理即使物体表面呈现凹凸不平的沟纹&#xff0c;同时也包括在物体的光滑表面上的彩色图案&#xff0c;通常我们更多地称之为花纹。对于花纹而言&#xff0c…

ES6 课程概述⑦

文章目录Vuex_State安装使用State在 Vue 组件中获得 Vuex 状态mapState 辅助函数Vuex_Getter通过属性访问通过方法访问mapGetters 辅助函数Vuex_Mutation在组件中提交 Mutation提交载荷&#xff08;Payload&#xff09;对象风格的提交方式使用常量替代 Mutation 事件类型Mutati…

Spring Boot(五十六):基于Redis的搜索栏热搜功能

1 功能要求 使用SpringBoot和redis实现一个简单的热搜功能&#xff0c;具备以下功能&#xff1a; 搜索栏展示当前登陆的个人用户的搜索历史记录&#xff0c;删除个人历史记录用户在搜索栏输入某字符&#xff0c;则将该字符记录下来 以zset格式存储的redis中&#xff0c;记录该…

Flink DataSet API和DataStream API 对于WordCount的演示

文章目录准备工作Flink DataSet APIFlink DataStream API结论准备工作 pom依赖 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-insta…

如何多人配音一个作品?这3招帮你快速实现

大家平时喜欢听书吗&#xff1f;听书是一种既能释放双眼&#xff0c;又能降低压力的放松方式。那么大家平时在听书的时候&#xff0c;有没有碰到过一些多人配音的小说&#xff1f;大家有好奇过这样的小说是怎么来的吗&#xff1f;今天&#xff0c;教大家多人配音怎么制作的&…

请问想考软考,零基础的话,哪个证书最好考呢

可以直接考中级&#xff0c;软考中级中也有适合零基础报考的&#xff0c;中级的含金量也比初级的高&#xff0c;初级的用途不太大&#xff0c;建议直接中级。 系统集成项目管理工程师&#xff0c;软考中级比较热门的一个科目&#xff0c;零基础的也适合相比较容易通过。 软考…

Fisher确切概率基本原理详解

Fisher确切概率 基本原理 比较两组有效率是否有差异。 在周边合计不变的情况下&#xff0c;计算实际频率变动时的Pi&#xff08;概率&#xff09;。然后计算累积概率&#xff0c;依据检验水平做推断。 累积概率的计算 以a从小到大的概率排序 左侧概率&#xff1a;现有样本…

【SpringCloud17】SpringCloud Alibaba入门简介

1.为什么会出现SpringCloud Alibaba Spring Cloud Netflix项目进入维护模式官网 1.1 什么是维护模式 将模块置于维护模式&#xff0c;意味着 Spring Cloud 团队将不会再向模块添加新功能。我们将修复 block 级别的 bug 以及安全问题&#xff0c;我们也会考虑并审查社区的小型 …

shell处理多盘跑fio(minimal)的结果脚本编写

作为一个专业测试storage的测试人员&#xff0c;除了对服务器&#xff0c;硬盘熟悉之外&#xff0c;还要对测试工具fio特别熟悉才行。如果在OEM或者专门的HDD&SSD厂家测试&#xff0c;会经常看到测试脚本里边&#xff0c;开发喜欢用fio minimal 模式&#xff0c;这样解析lo…