css盒子模型

2019-03-01 22:41|来源: 网路

盒子模型解决页面的布局问题


块级标签: 占的是一行.

行内标签: 占行内的一部分. 不能嵌套 块级标签.


块级: div p ol

行内: span font a


示例:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    块级标签<div>块级标签</div>块级标签<br>
    行内标签<span>行内标签</span>行内标签
</body>
</html>


div嵌套

padding: 内边距, 注意,内边距会改变自身的宽高.

margin:外边距

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
    div{
        border-color: red;
        border-width: 1px;
        border-style: solid;
    }
    #one{
        width: 200px;
        height: 300px;
        padding-left: 100px;
    }
  #two{
        width: 100px;
        height: 100px;
        margin-left: 100px;
    }
</style>
</head>
<body>
    <div id="one" >
        <div id="two" >
        </div>
    </div>
</body>
</html>


内外边距的复合属性

padding: 10px 30px 50px 80px;
1个属性时: 4个方向.
2个属性时: 第一个属性决定上下 第2个决定左右
3个属性时: 上   左右  下
4个属性时: 上 右 下 左(顺时针)


整理于网络


相关问答

更多