The flex-basis CSS property sets the flex-basis longhand, which specifies the flex basis: the initial main size of the flex item, before free space is distributed according to the flex factors.
object.style.flexBasis = "value"; <'flex-basis'> = content | <'width'> content Indicates an automatic size based on the flex item's content.
<'width'> = auto | <length-percentage> | min-content | max-content | fit-content( <length-percentage> ) auto Automatically specified by the user agent.
<length-percentage> =
<length> |
<percentage> <length> Specifies the length using a number followed by a unit of measurement.
<percentage> Specifies the percentage using a number followed by a percent sign (%).
min-content Represents the largest min-content contribution of the items occupying the track.
max-content Represents the largest max-content contribution of the items occupying the track.
fit-content() Represents the formula max(minimum, min(limit, max-content)), where minimum represents an auto minimum (which is often, but not always, equal to a min-content minimum), and limit is the track sizing function passed as an argument to fit-content(). This is essentially calculated as the smaller of minmax(auto, max-content) and minmax(auto, limit).
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: flex;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
flex-basis: content;
}
</style>
</head>
<body>
<div class="myclass">
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: flex;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
flex-basis: 100px;
}
</style>
</head>
<body>
<div class="myclass">
<div>length</div>
<div>length</div>
<div>length</div>
<div>length</div>
<div>length</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: flex;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
flex-basis: max-content;
}
</style>
</head>
<body>
<div class="myclass">
<div>max-content</div>
<div>max-content</div>
<div>max-content</div>
<div>max-content</div>
<div>max-content</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: flex;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
flex-basis: min-content;
}
</style>
</head>
<body>
<div class="myclass">
<div>min-content</div>
<div>min-content</div>
<div>min-content</div>
<div>min-content</div>
<div>min-content</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: flex;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
flex-basis: 20%;
}
</style>
</head>
<body>
<div class="myclass">
<div>percentage</div>
<div>percentage</div>
<div>percentage</div>
<div>percentage</div>
<div>percentage</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: flex;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
</style>
</head>
<body>
<button onmouseover="myfunction(innerHTML)">initial</button>
<button onmouseover="myfunction(innerHTML)">auto</button>
<button onmouseover="myfunction(innerHTML)">content</button>
<button onmouseover="myfunction(value)" value="100px">length</button>
<button onmouseover="myfunction(innerHTML)">max-content</button>
<button onmouseover="myfunction(innerHTML)">min-content</button>
<button onmouseover="myfunction(value)" value="20%">percentage</button>
<div class="myclass">
<div>flex-basis</div>
<div>flex-basis</div>
<div>flex-basis</div>
<div>flex-basis</div>
<div>flex-basis</div>
</div>
<script>
function myfunction(myparameter)
{
const myelements = document.querySelectorAll(".myclass > div");
for(let myelement of myelements)
{
myelement.style.flexBasis = myparameter;
}
}
</script>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: flex;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
</style>
</head>
<body>
<button>initial</button>
<button>auto</button>
<button>content</button>
<button value="100px">length</button>
<button>max-content</button>
<button>min-content</button>
<button value="20%">percentage</button>
<div class="myclass">
<div>flex-basis</div>
<div>flex-basis</div>
<div>flex-basis</div>
<div>flex-basis</div>
<div>flex-basis</div>
</div>
<script>
function myfunction(myparameter)
{
const myelements = document.querySelectorAll(".myclass > div");
for(let myelement of myelements)
{
myelement.style.flexBasis = myparameter;
}
}
const myelements = document.querySelectorAll("button");
for(let myelement of myelements)
{
let myargument = myelement.innerHTML;
if(myelement.value)
{
myargument = myelement.value;
}
myelement.addEventListener("mouseover", function(){myfunction(myargument)});
}
</script>
</body>
</html>