【CSS】盒子边框 ② ( 盒子边框单独指定语法 )





一、边框单独指定语法



盒子的 边框 Border , 由 四个方向 的边框组成 , 左上右下 四个 方向 上的 边框 可以单独指定样式 ,

如 : 上边框指定 4 像素 的 红色 实线 , 下边框 指定 2 像素 的 灰色 虚线 ;


边框单独指定 语法 :

  • 上边框 :

    • 上边框样式 : 通过 border-top-style 属性设置 ;
    • 上边框宽度 : 通过 border-top-width 属性设置 ;
    • 上边框颜色 : 通过 border-top-color 属性设置 ;
    • 总体写法 : 通过 border-top 属性设置 ;
  • 下边框 :

    • 下边框样式 : 通过 border-bottom-style 属性设置 ;
    • 下边框宽度 : 通过 border-bottom-width 属性设置 ;
    • 下边框颜色 : 通过 border-bottom-color 属性设置 ;
    • 总体写法 : 通过 border-bottom属性设置 ;
  • 左边框 :

    • 左边框样式 : 通过 border-left-style 属性设置 ;
    • 左边框宽度 : 通过 border-left-width 属性设置 ;
    • 左边框颜色 : 通过 border-left-color 属性设置 ;
    • 总体写法 : 通过 border-left 属性设置 ;
  • 右边框 :

    • 右边框样式 : 通过 border-right-style 属性设置 ;
    • 右边框宽度 : 通过 border-right-width 属性设置 ;
    • 右边框颜色 : 通过 border-right-color 属性设置 ;
    • 总体写法 : 通过 border-right属性设置 ;

建议使用 每个边框 的 总体写法 ;





二、代码示例




1、边框单独指定代码示例


代码示例 :

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>边框</title>
	<style>
		div {
			width: 300px;
			height: 100px;
			
			/* 上边框总体写法 */
			border-top: 4px dotted blue;
			/* 上边框总体写法 */
			border-left: 2px dashed red;
			/* 上边框总体写法 */
			border-right: 2px dotted purple;
			/* 上边框总体写法 */
			border-bottom: 2px solid orange;
		}
	</style>
</head>
<body>
	<div class="nav">
		<a href="https://blog.csdn.net/" class="blog">博客</a>
		<a href="https://download.csdn.net/">下载</a>
		<a href="https://edu.csdn.net/">学习</a>
		<a href="https://bbs.csdn.net/">社区</a>
	</div>
</body>
</html>

显示效果 :

在这里插入图片描述


2、设置表单边框代码示例


input 表单 输入框 默认效果如下 :
在这里插入图片描述

上述表单的 四个 边框 , 可以单独设置 , 可以将 上左右 三个方向的边框取消 , 将下边框的样式设置成 2 像素的红色实线 ;

		#id2 {
			border-top: none;
			border-left: none;
			border-right: none;
			border-bottom: 2px solid red;
		}

设置后 , 效果如下 :

在这里插入图片描述

还有一种更简单的写法 , 就是 先将 表单的 四个方向的边框取消 , 然后单独设置 底部边框样式 :

		#id3 {
			border: none;
			border-bottom: 2px solid red;
		}

设置的样式如下 :
在这里插入图片描述

代码示例 :

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>边框</title>
	<style>
		div {
			width: 300px;
			height: 100px;
			
			/* 上边框总体写法 */
			border-top: 4px dotted blue;
			/* 上边框总体写法 */
			border-left: 2px dashed red;
			/* 上边框总体写法 */
			border-right: 2px dotted purple;
			/* 上边框总体写法 */
			border-bottom: 2px solid orange;
		}
		
		#id2 {
			border-top: none;
			border-left: none;
			border-right: none;
			border-bottom: 2px solid red;
		}
		
		#id3 {
			border: none;
			border-bottom: 2px solid red;
		}
	</style>
</head>
<body>
	<div class="nav">
		<a href="https://blog.csdn.net/" class="blog">博客</a>
		<a href="https://download.csdn.net/">下载</a>
		<a href="https://edu.csdn.net/">学习</a>
		<a href="https://bbs.csdn.net/">社区</a>
		<br>
		用户名 : <input type="text" id="id1"/>
		<br>&emsp;码 : <input type="text" id="id2"/>
		<br>&emsp;箱 : <input type="text" id="id3"/>
	</div>
</body>
</html>

显示效果 :

在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值