美文网首页
盒模型和边框圆角

盒模型和边框圆角

作者: 小透明进击战 | 来源:发表于2019-06-24 17:49 被阅读0次
盒模型

box-sizing

  • 盒子模型width=border+padding+contentwidth(内容的宽)
    height=border+padding+contentheight(内容的高)
    因为网页如果加了浮动,当某一个元素添加padding或者border,超出了父盒子的宽度,就会造成其他子盒子往下溢出, 这种就容易影响整个页面布局。所以css3出现了盒模型,解决了这个问题。
  • 盒模型有两个关键属性,分别是content-box和border-box。
  • content-box,说明设定的宽度就是内容的宽度。
    +border-box,说明设定的宽度是整个盒子的宽度,就是如果你添加padding,盒子宽度依旧是这么大,只是内容宽度会被压缩变小。
边框圆角

border-radius的圆角大小随着半径越大,圆角越大

image.png
  • 安卓小机器人案例
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>安卓机器人</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .android {
            width: 500px;
            height: 500px;
            border: 1px solid red;
            margin: 50px auto;
        }
        .an_head {
            width: 250px;
            height: 125px;
            border-radius: 125px 125px 0 0;
            background-color: darkgreen;
            margin: 10px auto;
            position: relative;
        }
        /*眼睛使用伪元素*/
        .an_head::before,.an_head::after {
            content: "";
            /*行内元素转换成块级元素,方法有三,display,float,position*/
            position: absolute;
            width: 20px;
            height: 20px;
            border-radius: 10px;
            background-color: #fff;
            top: 70px;

        }
        .an_head::before {
            left: 70px;
        }
        .an_head::after {
            right: 70px;
        }
        .an_body {
            width: 250px;
            height: 250px;
            background-color: darkgreen;
            border-radius: 0 0 20px 20px;
            position: relative;
            margin: 0 auto;
        }
        .an_body::before,.an_body::after {
            content: "";
            width: 30px;
            height: 180px;
            border-radius: 10px;
            background-color: darkgreen;
            position: absolute;

            top: 20px;
        }
        .an_body::before {
            left: -40px;
        }
        .an_body::after {
            right: -40px;
        }
        .an_footer {
            width: 250px;
            height: 100px;
            margin: 0 auto;
            position: relative;
        }
        .an_footer::before,.an_footer::after {
            content: "";
            position: absolute;
            top: 0;
            background-color: darkgreen;
            width: 30px;
            height: 100px;
            border-radius: 0 0 10px 10px;

        }
        .an_footer::before {
            left: 50px;
        }
        .an_footer::after {
            right: 50px;

        }

    </style>
</head>
<body>
<div class="android">
    <div class="an_head"></div>
    <div class="an_body"></div>
    <div class="an_footer"></div>
</div>

</body>
</html>

相关文章

  • 盒模型和边框圆角

    盒模型 box-sizing 盒子模型width=border+padding+contentwidth(内容的宽...

  • CSS3

    一些最重要CSS3模块如下:选择器 盒模型 背景和边框 边框 添加圆角元素:border-radius:25p...

  • 任务九问答题

    一、盒模型包括哪些属性 盒模型包括元素本身的width和height,元素与边框之间的距离padding,边框的大...

  • css3新特性总结

    一、圆角边框 二、多背景图 三、颜色和透明度(由原来的rgb到现在的rgba) 四、多列布局和弹性盒模型 disp...

  • W3C盒模型与IE盒模型的区别

    W3C盒模型和IE盒模型的区别 IE盒模型:width(宽度)=padding+border(边框)+conten...

  • 任务9-1

    1.盒模型包括哪些属性? 盒模型包括:边距、边框、填充和实际内容; margin:清除边框区域,无背景颜色,是完全...

  • CSS3

    重要的八个模块 选择器 盒模型 背景&边框 文字特效 2D/3D转换 动画 多列布局 用户界面 边框 圆角:bor...

  • CSS盒模型详解

    盒模型基本概念 盒模型本质是一个盒子,包括边距,边框,填充,和实际内容。 标准盒模型和IE盒模型 不同在于高度和宽...

  • 理解盒模型

    1:怎么理解盒模型 ? 解: 标准模型 和 IE盒模型. 由外边距margin、内边距padding、边框bord...

  • 标准盒模型和怪异盒模型的区别

    css盒模型本质是一个盒子,它由边距、边框、填充和实际内容组成。盒模型能够让我们在其他元素和周边元素边框之间的空间...

网友评论

      本文标题:盒模型和边框圆角

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