10. CSS 排版

1、标准流(文档流/普通流)

  • 默认排版
  • CSS的元素分为块级、行内、行内块级
  • 块级是垂直排版,行内、行内块级是水平排班
  • display属性
    • inline 行内
    • inline-block 行内块级
    • block块级

2、浮动排版 float属性

  • 水平排版,只能设置元素左对齐或者右对齐
  • margin:0 auto 无效
  • 不区分块级、行内、行内块级元素

3、浮动元素脱标

 .box1{
            width: 100px;
            height: 100px;
            background-color: red;
            float: left;
        }
        .box2{
            width: 150px;
            height: 150px;
            background-color: burlywood;
        }
  • 标准排版会盖住浮动排版

4、隔墙法

  • 外墙法 clear: both
<head>
    <meta charset="UTF-8">
    <title>隔墙法-外墙法</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box1{
            background-color: antiquewhite;
        }
        .box2{
            background-color: darkgrey;
        }
        .box1 p{
            width: 100px;
            background-color: blue;
        }
        .box2 p{
            width: 100px;
            background-color: magenta;
        }
        p{
            float: left;
        }
        .wall{
            clear: both;
            height: 20px;
            background-color: aquamarine;
        }
    </style>
</head>
<body>
    <div class="box1">
        <p>我是文字1</p>
        <p>我是文字2</p>
        <p>我是文字3</p>
    </div>
    <div class="wall"></div>
    <div class="box2">
        <p>我是文字4</p>
        <p>我是文字5</p>
        <p>我是文字6</p>
    </div>
</body>
  • 内墙法
<body>
    <div class="box1">
        <p>我是文字1</p>
        <p>我是文字2</p>
        <p>我是文字3</p>
        <div class="wall"></div>
    </div>
    <div class="box2">
        <p>我是文字4</p>
        <p>我是文字5</p>
        <p>我是文字6</p>
    </div>
</body>

5、overflow:hidden

  • 超出标签的范围的内容裁剪掉,
  • 也可以清除浮动
  • 让里面的盒子设置margin-top之后,外面的盒子不被顶下来
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 本文是针对刚学编程的小白,都是一些基础知识,如果想了解更多深层一点的东西,欢迎移步本人博客!! 博客地址 点击跳转...
    西巴撸阅读 626评论 0 0
  • 一 外部式css样式 (也可称为外联式)就是把css代码写一个单独的外部文件中,这个css样式文件以“.css...
    KunMitnic阅读 1,080评论 0 1
  • 一、在什么场景下会出现外边距合并?如何合并?如何不让相邻元素外边距合并?给个父子外边距合并的范例 在CSS当中,相...
    dengpan阅读 665评论 0 0
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,004评论 1 92
  • 本课来自http://www.imooc.com/learn/9请不要用作商业用途。 HTML5 HTML介绍 H...
    PYLON阅读 3,426评论 0 5

友情链接更多精彩内容