美文网首页
【第64天】浮动,定位

【第64天】浮动,定位

作者: 36140820cbfd | 来源:发表于2019-09-28 20:46 被阅读0次

1 浮动的副作用

清除浮动

html代码

代码块
<body>
<div class="clearfix">
    <div class="c c1"></div>
    <div class="c c2"></div>
</div>

<div class="c3"></div>
</body>

css代码

代码块
 body {
            margin: 0;
        }

        .c {
            height: 100px;
            width: 100px;
        }

        .c1 {
            background-color: red;
            float: left;
        }

        .c2 {
            background-color: green;
            float: right;
        }

        .c3 {
            height: 200px;
            width: 100%;
            background-color: blue;
        }
        .clearfix:after {
            content: "";
            clear: both;
            display: block;
        }

2绝对定位,相对定位,固定定位

定位

html

代码块
<body>

<div class="c c1"></div>
<div class="c c2">
    <div class="cc "></div>
</div>
<div class="c c3"></div>
<div class="ccc">top</div>
</body>

css

代码块
body {
            margin: 0;
        }
        .c {
            height: 100px;
            width: 100px;
        }
        .c1 {
            background-color: red;
        }
        .c2 {
            background-color: green;
            /*position: relative;*/
            /*left: 100px*/
        }
        .c3 {
            background-color: blue;
        }
        .cc {
            height: 200px;
            width: 200px;
            background-color: black;
            position: absolute;
            top: 100px;
            left: 100px
        }
        .ccc {
            height: 50px;
            width: 50px;
            background-color: lawngreen;
            color: white;
            position: fixed;
            right: 50px;
            bottom: 50px;

3 利用z-index显示遮罩层和浮层

html代码

代码块
<body>

<div class="cover"></div>
<div class="yingying"></div>
</body>

css

代码块
<!--遮罩层-->
        .cover {   
            position: fixed;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background-color: rgba(0,23,128,0.1);
            z-index: 999;
        }
        
        <!--显示层-->
        .yingying {
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -100px;
            margin-left: -200px;
            width: 400px;
            height: 200px;
            background-color: white;
            z-index: 1000;
        }

4 透明度的例子

透明度

html

代码块
<body>

<div class="c1">c1</div>
<hr>
<div class="c2">c2</div>
</body>

css

代码块
 .c1 {
            height: 200px;
            width: 200px;
            background-color: red;
            opacity: 0.4;    <!--针对的是整体,包括文字-->
        }

.c2 {
            height: 200px;
            width: 200px;
            background-color: rgba(255,0,0,0.4);
        }
别跑,点个赞再走

相关文章

  • css定位

    CSS 定位 (Positioning) 属性允许你对元素进行定位。 CSS 定位和浮动 CSS 为定位和浮动提供...

  • CSS 定位

    CSS 定位 (Positioning) 属性允许你对元素进行定位。 CSS 定位和浮动 CSS 为定位和浮动提供...

  • CSS 定位 (Positioning)

    CSS 定位 (Positioning) 属性允许你对元素进行定位。 CSS 定位和浮动 CSS 为定位和浮动提供...

  • 定位及浮动

    定位# 元素定位: 浮动###### eg:######

  • 【第64天】浮动,定位

    1 浮动的副作用 html代码 css代码 2绝对定位,相对定位,固定定位 html css 3 利用z-inde...

  • CSS定位

    CSS定位(Positioning)允许你对元素进行定位。 CSS 定位和浮动 CSS 为定位和浮动提供了一些属性...

  • 浮动&定位

    浮动元素有什么特征?对父容器、其他浮动元素、普通元素、文字分别有什么影响?浮动元素脱离文档流,在当前行的左边或是右...

  • 浮动&定位

    关于浮动 浮动元素会脱离正常的文档流,按照其外边距指定的位置相对于它的上一个块级元素(或父元素)显示浮动元素后面的...

  • 浮动、定位

    1 . 文档流的概念指什么,有哪种方式可以让元素脱离文档流 CSS普通流/文档流(normal flow)是元素按...

  • 浮动定位

    浮动元素 浮动元素的特征其框可以左右移动(根据float属性值而定),直到它的外边缘碰到包含框或者另一个浮动元素的...

网友评论

      本文标题:【第64天】浮动,定位

      本文链接:https://www.haomeiwen.com/subject/yzewyctx.html