HTML DOM 样式 borderRadius 属性
htmldomweb developmentfront end technology更新于 2024/3/9 21:32:17
HTML DOM 样式 borderRadius 属性用于为元素的四边添加圆角。使用此属性,我们可以设置和获取边框半径属性,例如 borderTopLeftRadius、borderTopRightRadius、borderBottomRightRadius 和 borderBottomLeftRadius。
以下是语法 −
设置 borderRadius 属性:
object.style.borderRadius = "1-4 length|% / 1-4 length|%|initial|inherit"
属性值解释如下 −
| 值 | 描述 |
|---|---|
| length | 用于定义边框形状。 |
| % | 用于定义边框形状的百分比。 |
| initial | 用于将此属性设置为初始值。 |
| inherit | 用于继承父级属性值 |
让我们看一个 borderRadius 属性的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
#DIV1{
height: 100px;
width: 200px;
border: 10px groove orange;
padding: 10px;
border-radius: 1px 1px 1px 1px;
}
</style>
<script>
function changeBorderRadius(){
document.getElementById("DIV1").style.borderRadius="45px 45px 45px 45px";
document.getElementById("Sample").innerHTML="The border radius for the four borders of the above div are now increased";
}
</script>
</head>
<body>
<div id="DIV1">SOME SAMPLE TEXT</div>
<p>Increase the above div border radius size by clicking the below button</p>
<button onclick="changeBorderRadius()">Change Border Radius</button>
<p id="Sample"></p>
</body>
</html>
输出

点击"更改边框半径"按钮 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

