【CSS】5-盒子模型

5-盒子模型

1.盒子模型的要素

(从内到外)内容,内边距,边框,外边距

2.边框样式

边框样式:
    1.border-style:边框类型,solid实现,dotted点线 dashed虚线
    2.border-width: 边框宽度
    3.border-color: 边框颜色
    4.border-radius: 边框的圆角
    
    边框样式复合写法:border: style width color;
    
    可以设置

实例:

<head>
	<meta charset="utf-8">
	<title>css边框样式</title>
	<style type="text/css">
		
		.div-style-1 {
			width: 300px;
			height: 300px;
			background-color: yellowgreen;
			
			text-align: center;
			line-height: 300px;
			color: white;
			font-size: 30px;
			font-weight: bolder;
		}
		
		#div1 {
			
			/* 边框样式 */
			border-style: dashed;
			border-width: 5px;
			border-color: black;
			border-radius: 10px;
		}
		
		#div2 {
			/* border: dotted 6px red; */
			border-top: solid 5px green;
			border-left: double 5px yellow;
			border-bottom: dotted 5px red;
			border-right: dashed 5px pink;
		}
		
		#div3:hover {
			border-bottom: solid 10px green;
		}
		
		img {
			border: solid 8px skyblue;
		}
		
	</style>
</head>
<body>
	
	<div id="div1" class="div-style-1">
		HELLO WORLD
	</div>
	
	<hr >
	
	<div id="div2" class="div-style-1">
		HELLO WORLD
	</div>
	
	<hr >
	
	<div id="div3" class="div-style-1">
		HELLO WORLD
	</div>
	
	<hr >
	
	<img src="img/spider.jpg" >
	
</body>

3.内边距和外边距

    内外边距
        1.margin:外边距
        2.padding:内边距
            注意:
                1.边距复合写法:
                    4个值:上 右 下 左
                    2个值:上下 左右
                    1个值:上下左右
                2.使用margin来居中块元素:margin:0 auto
                    注意:元素必须是块元素,必须设置宽度
                3.默认情况下,padding会撑大原来的元素,可以增加box-sizing:border-box;来改变这一特性,使得padding向内压缩。
        3.可以使用display:inline-block来使得块元素排列在一行

实例:

<style type="text/css">
			.div-style-1 {
				width: 300px;
				height: 300px;
				background-color: yellowgreen;
				
				text-align: center;
				line-height: 300px;
				color: white;
				font-size: 30px;
				font-weight: bolder;
				
				/* 
					块元素:可以设置宽高,但是不能排列在一行 
					行内元素:不可以设置宽高,但是可以排列在一行
					行内块元素:可以设置宽高,也可以排列在一行
				*/
				/* 改变元素属性:block块元素、inline行内元素、inline-block行内块元素 */
				display: inline-block;
				
				/* margin: 10px 20px 30px 40px; */
				/* margin: 10px 20px; */
				/* margin: 10px; */
				margin-top: 10px;
				margin-right: 20px;
				margin-bottom: 30px;
				margin-left: 40px;
				
			}
			
			.span-style-1 {
				background-color: gray;
				
				/* 行内元素设置宽高无效 */
				width: 300px;
				height: 300px;
			}
			
			#div5 {
				display: block;
				margin: 50px auto;
				
				border: solid 1px red;
				
				/* 内边距 */
				padding: 10px 20px 30px 40px;
			}
			
			#div6 {
				display: block;
				margin: 50px auto;
				
				border: solid 1px red;
				
				/* 设置为边框盒子,padding会向内压缩,不会撑大div */
				box-sizing: border-box;
				
				/* 内边距 */
				padding: 10px 20px 30px 40px;
			}
		</style>
	</head>
	<body>
		<div id="div1" class="div-style-1">
			HELLO WORLD
		</div><div id="div2" class="div-style-1">
			HELLO WORLD
		</div><div id="div3" class="div-style-1">
			HELLO WORLD
		</div><div id="div4" class="div-style-1">
			HELLO WORLD
		</div>
		
		<hr >
		
		<span class="span-style-1">
			HELLO HTML
		</span>
		<span class="span-style-1">
			HELLO HTML
		</span>
		<span class="span-style-1">
			HELLO HTML
		</span>
		
		<hr >
		
		<div id="div5" class="div-style-1">
			HELLO WORLD
		</div>
		
		<div id="div6" class="div-style-1">
			HELLO WORLD
		</div>
		
	</body>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JeffHan^_^

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值