HTML DOM 样式的 flexBasis 属性
htmlweb developmentfront end technology更新于 2024/3/14 7:40:17
HTML DOM 样式的 flexBasis 属性用于指定具有弹性显示的元素的初始大小。除 flex-basis 的 auto 值外,flexBasis 属性的优先级高于 width 值。
以下是语法 −
设置 flexBasis 属性 −
object.style.flexBasis = "number|auto|initial|inherit"
以上属性的解释如下 −
| 值 | 描述 |
|---|---|
| number | 用于指定弹性项的初始长度(百分比或任何合法长度单位)。 |
| auto | 将长度设置为等于弹性项的长度。如果未指定长度,则将根据其内容确定长度。这是默认值。 |
| initial | 将此属性设置为初始值。 |
| inherit | 继承父级属性值 |
让我们看一个 flexBasis 属性的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
#demo, #demo2{
background-color: #fff8dc;
margin: 10px;
height: 100px;
box-shadow: 0 0 0 4px brown;
display: flex;
}
#demo div {
flex-basis: 110px;
}
</style>
<script>
function changeFlexBasis() {
for(var i=1;i<3;i++){
document.getElementsByTagName("DIV")[i].style.flexBasis="200px";
}
document.getElementById("Sample").innerHTML="The flex basis value is increased to 200px";
}
</script>
</head>
<body>
<h2>Demo Heading</h2>
<div id="demo">
<div><img src="https://www.cainiaomax.com/images/home_tensor_flow.png"></div>
<div><img src="https://www.cainiaomax.com/images/home_blockchain_python.png"></div>
<div><img src="https://www.cainiaomax.com/images/multilanguage-tutorials.png"></div>
</div>
<p>Change the flex basis property for the image present inside divs by clicking the below button</p>
<button onclick="changeFlexBasis()">Change Flex Basis</button>
<p id="Sample"></p>
</body>
</html>
输出

点击"更改 Flex Basis"按钮 −

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

