当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML Style borderTopStyle用法及代码示例


DOM样式borderTopStyle属性用于设置或返回元素的顶部边框样式。

用法:

  • 获取borderTopStyleProperty
    object.style.borderTopStyle
  • 设置borderTopStyleProperty
    object.style.borderTopStyle = "none | hidden | dotted | dashed |
    solid | double | groove |ridge | inset | outset | initial | 
    inherit"

属性值:


影响
none 没有创建边框。这是默认值。
hidden 视觉上与“无”相同,不同之处在于它有助于解决表格元素中的边界冲突。
dotted 点用作边界。
dashed 虚线用作边框。
solid 一条实线用作边框。
double 两行用作边框。
groove 显示3D带凹槽的边框。效果取决于border-color值。
ridge 显示3D脊状边框。效果取决于border-color值。
inset 显示3D插入边框。效果取决于border-color值。
outset 显示3D起始边框。效果取决于border-color值。
initial 将属性设置为其初始值。
inherit 将属性设置为从其父项继承。

下面的示例演示了这些值:

示例1:使用none值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green"> 
      GeeksforGeeks 
    </h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the  
      style of the border on the top</p> 
    
    <div class="item"> 
      GeeksforGeeks 
    </div> 
    
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'none'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:
none-before

单击按钮后:
none-after

示例2:使用隐藏值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the 
      style of the border on the top</p> 
    <div class="item">GeeksforGeeks</div>  
    
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'hidden'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:

none-before

单击按钮后:


hidden-after

示例3:使用点分值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the  
      style of the border on the top</p> 
    
    <div class="item">GeeksforGeeks</div> 
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'dotted'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:

none-before

单击按钮后:

dotted-after

示例4:使用虚线值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the 
      style of the border on the top</p> 
    <div class="item">GeeksforGeeks</div> 
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'dashed'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:


none-before

单击按钮后:

dashed-after

示例5:使用固定值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px dotted green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the  
      style of the border on the top</p> 
    <div class="item">GeeksforGeeks</div> 
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'solid'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:

solid-before

单击按钮后:

solid-after

示例6:使用double值。


<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the style 
      of the border on the top</p> 
    <div class="item">GeeksforGeeks</div> 
    
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'double'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:

none-before

单击按钮后:

double-after

示例7:使用凹槽值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the style 
      of the border on the top</p> 
    <div class="item">GeeksforGeeks</div> 
    
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'groove'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:

none-before

单击按钮后:


groove-after

示例8:使用山脊值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the style  
      of the border on the top</p> 
    <div class="item">GeeksforGeeks</div> 
    
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'ridge'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:

none-before

单击按钮后:

ridge-after

示例9:使用插入值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the style 
      of the border on the top</p> 
    <div class="item">GeeksforGeeks</div> 
    
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'inset'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:


none-before

单击按钮后:

inset-after

示例10:使用起始值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px inset green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the style 
      of the border on the top</p> 
    <div class="item">GeeksforGeeks</div> 
    
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'outset'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:

outset-before

单击按钮后:

outset-after

示例11:使用初始值。


<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the style 
      of the border on the top</p> 
    <div class="item">GeeksforGeeks</div> 
    
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'initial'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:

none-before

单击按钮后:

initial-after

示例12:使用继承值。

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <title> 
        DOM Style borderTopStyle Property 
    </title> 
    <style> 
        #parent { 
            border-top-style:dotted; 
            padding:10px; 
        } 
          
        .item { 
            height:50px; 
            padding:10px; 
            border:15px solid green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green">GeeksforGeeks</h1> 
    <b>DOM Style borderTopStyle Property</b> 
    <p>Click on the button to change the style 
      of the border on the top</p> 
    <div id="parent"> 
        <div class="item">GeeksforGeeks</div> 
    </div> 
  
    <button onclick="changeBorderTopStyle()"> 
      Change style 
    </button> 
  
    <script> 
        function changeBorderTopStyle() { 
            elem = document.querySelector('.item'); 
  
            // Setting the border style 
            elem.style.borderTopStyle = 'inherit'; 
        } 
    </script> 
</body> 
  
</html>

输出:

在单击按钮之前:

inherit-before

单击按钮后:

inherit-after

支持的浏览器:borderTopStyle属性支持的浏览器如下:

  • 谷歌浏览器
  • IE浏览器
  • Firefox
  • Opera
  • 苹果Safari


相关用法


注:本文由纯净天空筛选整理自sayantanm19大神的英文原创作品 HTML | DOM Style borderTopStyle Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。