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


HTML Style borderTopWidth用法及代码示例


HTML DOM中的Style borderTopWidth属性用于设置或返回元素顶部边框的宽度。

用法:

  • 获取borderTopWidth属性
    object.style.borderTopWidth
  • 设置borderTopWidth属性
    object.style.borderTopWidth = "thin | medium | thick | length |
    initial | inherit"

属性值:


  1. thin:这用于定义细边框。

    例:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopWidth 
        </title> 
      
        <style> 
            .elem { 
                border-style:solid; 
                padding:10px; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopWidth 
        </b> 
        <p class="elem"> 
          GeeksforGeeks is a computer science 
          portal with a huge variety of well  
          written and explained computer  
          science and programming articles, 
          quizzes and interview questions. 
        </p> 
        <button onclick="changeWidth()"> 
          Change borderTopWidth 
        </button> 
      
        <!-- Script to change borderTopWidth -->
        <script> 
            function changeWidth() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopWidth = 'thin'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:

    在单击按钮之前:

    thin-before

    单击按钮后:

    thin-after

  2. medium:这用于定义中等顶部边框。这是默认值。

    例:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopWidth 
        </title> 
        <style> 
            .elem { 
                border:thick solid; 
                padding:10px; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopWidth 
      </b> 
        <p class="elem"> 
          GeeksforGeeks is a computer  
          science portal with a huge  
          variety of well written and  
          explained computer science 
          and programming articles, 
          quizzes and interview questions. 
        </p> 
        <button onclick="changeWidth()"> 
          Change borderTopWidth 
        </button> 
      
        <!-- Script to change borderTopWidth -->
        <script> 
            function changeWidth() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopWidth = 'medium'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:

    在单击按钮之前:

    medium-before


    单击按钮后:

    medium-after

  3. thick:这用于定义粗大的顶部边框。

    示例3:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopWidth 
        </title> 
      
        <style> 
            .elem { 
                border-style:solid; 
                padding:10px; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopWidth 
      </b> 
        <p class="elem"> 
          GeeksforGeeks is a computer  
          science portal with a huge  
          variety of well written and 
          explained computer science  
          and programming articles,  
          quizzes and interview questions. 
        </p> 
        <button onclick="changeWidth()"> 
          Change borderTopWidth 
        </button> 
      
        <!-- Script to change borderTopWidth -->
        <script> 
            function changeWidth() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopWidth = 'thick'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:

    在单击按钮之前:

    thick-before

    单击按钮后:

    thick-after

  4. length:这用于以长度单位定义顶部边框宽度。

    示例4:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopWidth 
        </title> 
      
        <style> 
            .elem { 
                border-style:solid; 
                padding:10px; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
      </h1> 
        <b> 
          DOM Style BorderTopWidth 
        </b> 
        <p class="elem"> 
          GeeksforGeeks is a computer science 
          portal with a huge variety of well  
          written and explained computer science 
          and programming articles, quizzes and 
          interview questions. 
        </p> 
        <button onclick="changeWidth()"> 
          Change borderTopWidth 
        </button> 
      
        <!-- Script to change borderTopWidth -->
        <script> 
            function changeWidth() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopWidth = '10px'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:


    在单击按钮之前:
    length-before

    单击按钮后:
    length-after

  5. initial:这用于将此属性设置为其默认值。

    示例5:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopWidth 
        </title> 
      
        <style> 
            .elem { 
                border-style:solid; 
                padding:10px; 
                border-top-width:2px; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopWidth 
        </b> 
        <p class="elem"> 
          GeeksforGeeks is a computer science 
          portal with a huge variety of well  
          written and explained computer  
          science and programming articles, 
          quizzes and interview questions. 
        </p> 
        <button onclick="changeWidth()"> 
          Change borderTopWidth 
        </button> 
      
        <!-- Script to change borderTopWidth -->
        <script> 
            function changeWidth() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopWidth = 'initial'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:

    在单击按钮之前:

    initial-before

    单击按钮后:

    initial-after

  6. inherit:这将从其父项继承该属性。

    示例6:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopWidth 
        </title> 
      
        <style> 
            #parent { 
                padding:10px; 
                border-style:solid; 
                /* Setting the borderTopWidth 
                 of the parent */ 
                border-top-width:15px; 
            } 
              
            .elem { 
                border-style:solid; 
                padding:10px; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopWidth 
        </b> 
        <br> 
        <br> 
        <div id="parent"> 
            <p class="elem"> 
              GeeksforGeeks is a computer science  
              portal with a huge variety of well  
              written and explained computer science 
              and programming articles, quizzes and 
              interview questions. 
            </p> 
        </div> 
        <br> 
        <button onclick="changeWidth()"> 
          Change borderTopWidth 
        </button> 
      
        <!-- Script to change borderTopWidth -->
        <script> 
            function changeWidth() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopWidth = 'inherit'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:


    在单击按钮之前:

    inherit-before

    单击按钮后:

    inherit-after

  7. 支持的浏览器:borderTopWidth属性支持的浏览器如下:

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


相关用法


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