css中如何使用border属性与display属性

原文:
css中如何使用border属性与display属性

border属性介绍#

  • border属性设置元素边框。
  • 边框3个要素如:粗细、线型、颜色。

边框线型属性值说明表如:#

属性指描述
none定义无边框。
hidden与 "none" 相同。不过应用于表时除外,对于表,hidden 用于解决边框冲突。
dotted定义点状边框。在大多数浏览器中呈现为实线。
dashed定义虚线。在大多数浏览器中呈现为实线。
solid定义实线。
double定义双线。双线的宽度等于 border-width 的值。
groove定义 3D 凹槽边框。其效果取决于 border-color 的值。
ridge定义 3D 垄状边框。其效果取决于 border-color 的值。
inset定义 3D inset 边框。其效果取决于 border-color 的值。
outset定义 3D outset 边框。其效果取决于 border-color 的值。
inherit规定应该从父元素继承边框样式。

边框方向属性值说明表如:#

属性描述
border-top设置元素上边框。
border-bottom设置元素下边框。
border-left设置元素左边框。
border-right设置元素右边框。

边框实践#

  • 实践代码:
 Copy <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>边框</title> <style> .box{ width: 200px; height: 100px; border: 1px solid red; } </style></head><body> <div class="box"> 微笑是最初的信仰 </div></body></html>
  • 结果图

  • 注意:边框颜色可以省略不写,默认为黑色。如果其他2个属性不写就不会显示边框。

  • 设置元素边框方向实践
  • 代码块

 Copy <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>边框</title> <style> .box{ width: 200px; height: 100px; border-top: 2px double red; border-bottom: 2px ridge lawngreen; border-left: 2px inset darkorange ; border-right:2px groove darkblue; } </style></head><body> <div class="box"> 微笑是最初的信仰 </div></body></html>
  • 结果图

display属性介绍#

  • display属性它是显示的意思,display属性可以将行内元素与块级元素之间相互转换,将隐藏的元素设置显示状态或将显示的元素设置隐藏状态。
  • display属性值说明表如下:
属性值描述
inline将块级元素转换为行内元素。
block作用:1、将行内元素转换为块级元素。2、将隐藏的元素设置为显示状态。
none将显示的元素设置为隐藏状态。

display属性实践#

  • 使用display属性的属性值为blockspan标签设置宽高度并且设置一个背景颜色。
  • 代码块

 Copy <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>将span标签转换为块级元素</title> <style> .box{ width: 200px; height: 100px; display: block; background-color: red; } </style></head><body> <span class="box">微笑是最初的信仰</span></body></html>
  • 结果图

  • 注意:如果行内元素使用了display: block;,就拥有了块级元素特点。

  • 使用display属性的属性值为inlineh1标签转换为行内元素。

  • 代码块

 Copy <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>将h1标签转换为行内元素</title> <style> .box{ width: 200px; height: 100px; display: inline; background-color: red; } </style></head><body> <h1 class="box">微笑是最初的信仰</h1></body></html>
  • 结果图

  • 注意:如果块级元素使用了display: inline;,就拥有了行内元素特点。

相关文章