网页制作 发布日期:2025/11/4 浏览次数:1
border属性介绍
border属性设置元素边框。3个要素如:粗细、线型、颜色。边框线型属性值说明表如:
边框方向属性值说明表如:
    
        
            属性 
            描述 
        
    
    
        
            border-top
            设置元素上边框。
        
        
            border-bottom
            设置元素下边框。
        
        
            border-left
            设置元素左边框。
        
        
            border-right
            设置元素右边框。
        
    
边框实践
实践代码:
<!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个属性不写就不会显示边框。
设置元素边框方向实践
代码块
<!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属性值说明表如下: 
display属性实践
使用display属性的属性值为block将span标签设置宽高度并且设置一个背景颜色。
代码块
<!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属性的属性值为inline将h1标签转换为行内元素。
代码块
<!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;,就拥有了行内元素特点。
总结
以上所述是小编给大家介绍的css中使用border属性与display属性的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!