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


HTML Style borderTopRightRadius用法及代码示例


DOM样式的borderTopRightRadius属性用于设置或返回元素右上边界的半径。

用法:

  • 获取borderTopRightRadius属性
    object.style.borderTopRightRadius
  • 设置borderTopRightRadius属性
    object.style.borderTopRightRadius = "length | percentage | 
    initial | inherit"

属性值:


  • length:用于定义固定长度单位的半径。可以使用两个值来指定四分之一椭圆的半径,第一个值是水平半径,第二个值是垂直半径。

    示例1:使用一个值指定半径。

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopRightRadius 
        </title> 
      
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopRightRadius 
        </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="changeRadius()"> 
          Change borderTopRightRadius 
        </button> 
      
        <!-- Script to change borderTopRightRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopRightRadius = '30px'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:

    在单击按钮之前:

    fixed-one-before

    单击按钮后:

    fixed-one-after

    示例2:使用两个值指定半径。

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopRightRadius 
        </title> 
      
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopRightRadius 
      </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="changeRadius()"> 
          Change borderTopRightRadius 
        </button> 
      
        <!-- Script to change borderTopRightRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopRightRadius = '10px 30px'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:

    在单击按钮之前:

    fixed-two-before


    单击按钮后:

    fixed-two-after

  • percentage:这用于以百分比为单位定义半径。可以使用两个值来指定四分之一椭圆的半径,第一个值是水平半径,它是边框的宽度的百分比,第二个值是垂直半径,是border-box的高度的百分比。

    示例3:使用一个值指定半径。

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopRightRadius 
        </title> 
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopRightRadius 
        </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="changeRadius()"> 
          Change borderTopRightRadius 
        </button> 
      
        <!-- Script to change borderTopRightRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopRightRadius = '20%'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:

    在单击按钮之前:

    percentage-one-before

    单击按钮后:

    percentage-one-after

    示例4:使用两个值指定半径。

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopRightRadius 
        </title> 
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopRightRadius 
        </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="changeRadius()"> 
          Change borderTopRightRadius 
        </button> 
      
        <!-- Script to change borderTopRightRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopRightRadius = '10% 50%'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:


    在单击按钮之前:

    percentage-two-before

    单击按钮后:

    percentage-two-after

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

    示例5:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopRightRadius 
        </title> 
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
                border-top-right-radius:20px; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopRightRadius 
        </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="changeRadius()"> 
          Change borderTopRightRadius 
        </button> 
      
        <!-- Script to change borderTopRightRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopRightRadius = 'initial'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:

    在单击按钮之前:

    initial-before

    单击按钮后:

    initial-after


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

    示例6:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
          DOM Style BorderTopRightRadius 
        </title> 
      
        <style> 
            #parent { 
                padding:10px; 
                border-style:solid; 
                /* Setting the borderTopRightRadius of the parent */ 
                border-top-right-radius:30px; 
            } 
              
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopRightRadius 
        </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="changeRadius()"> 
          Change borderTopRightRadius 
        </button> 
      
        <!-- Script to change borderTopRightRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopRightRadius = 'inherit'; 
            } 
        </script> 
    </body> 
      
    </html>

    输出:

    在单击按钮之前:

    inherit-before

    单击按钮后:

    inherit-after

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

  • 谷歌浏览器
  • Internet Explorer 9.0
  • Firefox
  • 苹果Safari
  • Opera


相关用法


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