CSS-浮动与Flex

标准流

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>标准流title>
head>
<body>
    <h3>标准流h3>
    标准流也叫文档流,指的是标签在页面中默认的排布规则例如: 块元素独占一行,行内元素可以一行显示多个。<br>
    <img src="./img/标准流.png" alt="">
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>
        .div1 {
     
            width: 100px;
            height: 100px;
            background-color: brown;
            float: left;
        }
        .div2 {
     
            width: 200px;
            height: 200px;
            background-color: orange;
        }
    style>
head>
<body>
    <h3>浮动h3>
    <strong>作用:strong>让块元素水平排列。<br>
    <strong>属性名:strong>float <br>
    <strong>特点:strong>顶对其;具有行内块特点;浮动的盒子会脱标。<br>
    <strong>属性值:strong>
    <ul>
        <li>left 左对齐li>
        <li>right 右对齐li>
    ul><br><hr>
    <strong>两个float: left;strong><br>
    <img src="./img/浮动1.png" alt=""><br>

    <strong>一个float: left,一个float: right;strong><br>
    <img src="./img/浮动2.png" lang="100px" width="500px"><br>

    <strong>div1一个float: left,另一个吴strong><br>
    <img src="./img/浮动3.png" alt=""><br>

    <div class="div1">这是div标签1div>
    <div class="div2">这是div标签2div>
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>
        * {
     
            margin: 0;
            padding: 0;
        }

        li {
     
            list-style: none;
        }

        .product {
     
            margin: 50px auto;
            width: 1226px;
            height: 628px;
            background-color: pink;
        }

        .product .left {
     
            width: 234px;
            height: 628px;
            background-color: skyblue;
            float: left;
        }

        .product .right {
     
            width: 978px;
            height: 628px;
            background-color: red;
            float: right;
        }
        .product .right li {
     
            width: 234px;
            height: 300px;
            background-color: orange;
            float: left;
            margin-bottom: 14px;
            margin-right: 14px;
        }
        /* 两种方法 */
        /* .product .right li:nth-child(4n) {
            margin-right: 0px;
        } */
    style>
head>
<body>
    <h3>浮动-产品区域布局h3>
    <strong>细节:strong>浮动宽度不够,浮动的盒子会掉下来<br>
    <div class="product">
        <div class="left">div>
        <div class="right">
            <ul>
                <li>li>
                <li>li>
                <li>li>
                <li style="margin-right: 0px;">li>
                <li>li>
                <li>li>
                <li>li>
                <li style="margin-right: 0px;">li>
            ul>
        div>
    div>
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>
        .top {
     
            margin: 10px auto;
            width: 1200px;
            /* height: 300px; */
            background-color: pink;
        }
        .top .left {
     
            float: left;
            width: 200px;
            height: 300px;
            background-color: skyblue;
        }
        .top .right {
     
            float: right;
            width: 950px;
            height: 300px;
            background-color: orange;
        }
        .bottom {
     
            height: 100px;
            background-color: brown;
        }
    style>
head>
<body>
    <h3>清除浮动h3>
    <strong>场景:strong>浮动元素会脱标,如果父级没有高度,子级无法撑开父级高度(可能导致页面布局错乱) <br>
    <strong>解决方法: strong>清除浮动(清除浮动带来的影响) <br>
    <strong>正常:strong><br>
    <img src="./img/清除浮动1.png" width="600px" height="300px"><br>
    <strong>没有高:strong><br>
    <img src="./img/清除浮动2.png" width="600px" height="300px"><br>
    <br><hr>
    <div class="top">
        <div class="left">div>
        <div class="right">div>
    div>
    <div class="bottom">div>
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>
        .top {
     
            margin: 10px auto;
            width: 1200px;
            /* height: 300px; */
            background-color: pink;
        }
        .top .left {
     
            float: left;
            width: 200px;
            height: 300px;
            background-color

你可能感兴趣的:(web,css,前端,html)