css3-盒子模型、内外边距、圆角边框

目录

1.盒子模型及边框的应用

1.1 什么是盒子

1.2 什么是边框

2.内外边距及div居中

3.圆角边框及阴影


1.盒子模型及边框的应用

1.1 什么是盒子

margin:外边距

padding:内边距

border:边框

1.2 什么是边框

1)边框的粗细

2)边框的样式

3)边框的颜色

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <style>
    body{
      /*body总有一个默认的外边距*/
      margin: 0px;
    }
    #box{
      width: 300px;
      /*粗细 样式 颜色*/
      border: 1px solid skyblue;
    }
    /*标题默认也有外边距*/
    h2{
      font-size: 16px;
      background-color: #8EC5FC;
      line-height: 30px;
      color: whitesmoke;
      margin: 0px;
    }
    form{
      background: blanchedalmond;
    }
    div:nth-of-type(1) input{
      border:3px solid black;
    }
    div:nth-of-type(2) input{
      border:3px dashed palegreen;
    }
    div:nth-of-type(3) input{
      border:3px dashed lightcoral;
    }
  </style>

</head>
<body>
<div id="box">
  <h2>会员登录</h2>
  <form action="#">
    <div>
      <span>用户名:</span>
      <input type="text">
    </div>
    <div>
      <span>密码:</span>
      <input type="text">
    </div>
    <div>
      <span>邮箱:</span>
      <input type="text">
    </div>
  </form>
</div>
</body>
</html>

2.内外边距及div居中

margin-left/right/top/bottom–>表示四边,可分别设置,也可以同时设置如下

margin:0 0 0 0/*分别表示上、右、下、左;从上开始顺时针*/
/*例1:居中*/
margin:0 auto /*auto表示左右自动*/
/*例2:*/
margin:4px/*表示上、右、下、左都为4px*/
/*例3*/
margin:10px 20px 30px/*表示上为10px,左右为20px,下为30px*/

盒子的计算方式:
margin+border+padding+内容的大小

总结:
body总有一个默认的外边距 margin:0
常见操作:初始化

3.圆角边框及阴影

测试圆角边框

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            width: 50px;
            height: 50px;
            margin: 30px;
            background: paleturquoise;
            border-radius: 50px 0px 0px 0px;
        }
        img{
            border-radius: 85px;
        }
    </style>
</head>
<body>
<div></div>
<img src="images/a.PNG" alt="">
</body>
</html>

测试盒子阴影:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<!--    margin:0 auto 作用:居中
        要求:1.块元素
             2.块元素有固定的高度
-->
    <style>
        img{
            border-radius:85px ;
            /*x轴偏移量 y轴偏移量 模糊半径 颜色*/
            box-shadow:10px 10px 100px yellow ;
        }
    </style>
</head>
<body>
<div style="width: 1000px;height:1000px;display: block;text-align: center">
    <img src="images/a.PNG " alt="">
</div>

</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值