當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。