The justify-self property for CSS justifies the box (as the alignment subject) within its containing block (as the alignment container) along the inline/row/main axis of the alignment container.
object.style.justifySelf = "value"; <'justify-self'> = auto | normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ] auto Automatically specified by the user agent.
normal Represents the default alignment for the layout mode.
stretch If the combined size of the alignment subjects is less than the size of the alignment container, any auto-sized alignment subjects have their size increased equally (not proportionally), while still respecting the constraints imposed by max-height/max-width (or equivalent functionality), so that the combined size exactly fills the alignment container.
<baseline-position> = [ first | last ]? baseline first baseline Specifies participation in first-baseline alignment: aligns the alignment baseline of the box's first baseline set with the corresponding baseline of its baseline-sharing group.
last baseline Specifies participation in last-baseline alignment: aligns the alignment baseline of the box's last baseline set with the corresponding baseline of its baseline-sharing group.
baseline Computes to first baseline.
<overflow-position> = unsafe | safe unsafe Regardless of the relative sizes of the alignment subject and alignment container, the given alignment value is honored.
safe If the size of the alignment subject overflows the alignment container, the alignment subject is instead aligned as if the alignment mode were start.
<self-position> = center | start | end | self-start | self-end | flex-start | flex-end center Centers the alignment subject within its alignment container.
start Aligns the alignment subject to be flush with the alignment container's start edge in the appropriate axis.
end Aligns the alignment subject to be flush with the alignment container's end edge in the appropriate axis.
self-start Aligns the alignment subject to be flush with the edge of the alignment container corresponding to the alignment subject's start side in the appropriate axis.
self-end Aligns the alignment subject to be flush with the edge of the alignment container corresponding to the alignment subject's end side in the appropriate axis.
flex-start Aligns the alignment subject to be flush with the edge of the alignment container corresponding to the flex container's main-start or cross-start side, as appropriate. Only used in flex layout.
flex-end Aligns the alignment subject to be flush with the edge of the alignment container corresponding to the flex container's main-end or cross-end side, as appropriate. Only used in flex layout.
left Aligns the alignment subject to be flush with the alignment container's line-left or physical left edge, whichever is in the appropriate axis.
right Aligns the alignment subject to be flush with the alignment container's line-right or physical right edge, whichever is in the appropriate axis.
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: normal;
}
</style>
</head>
<body>
<div class="myclass">
<div>normal</div>
<div>normal</div>
<div>normal</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: stretch;
}
</style>
</head>
<body>
<div class="myclass">
<div>stretch</div>
<div>stretch</div>
<div>stretch</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: first baseline;
}
</style>
</head>
<body>
<div class="myclass">
<div>first baseline</div>
<div>first baseline</div>
<div>first baseline</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: last baseline;
}
</style>
</head>
<body>
<div class="myclass">
<div>last baseline</div>
<div>last baseline</div>
<div>last baseline</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: baseline;
}
</style>
</head>
<body>
<div class="myclass">
<div>baseline</div>
<div>baseline</div>
<div>baseline</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 0;
grid-auto-flow: column;
grid-auto-rows: 0;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: unsafe center;
}
</style>
</head>
<body>
<div class="myclass">
<div>unsafe</div>
<div>unsafe</div>
<div>unsafe</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 0;
grid-auto-flow: column;
grid-auto-rows: 0;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: safe center;
}
</style>
</head>
<body>
<div class="myclass">
<div>safe</div>
<div>safe</div>
<div>safe</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: center;
}
</style>
</head>
<body>
<div class="myclass">
<div>center</div>
<div>center</div>
<div>center</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: start;
}
</style>
</head>
<body>
<div class="myclass">
<div>start</div>
<div>start</div>
<div>start</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: end;
}
</style>
</head>
<body>
<div class="myclass">
<div>end</div>
<div>end</div>
<div>end</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: self-start;
}
</style>
</head>
<body>
<div class="myclass">
<div>self-start</div>
<div>self-start</div>
<div>self-start</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: self-end;
}
</style>
</head>
<body>
<div class="myclass">
<div>self-end</div>
<div>self-end</div>
<div>self-end</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: flex-start;
}
</style>
</head>
<body>
<div class="myclass">
<div>flex-start</div>
<div>flex-start</div>
<div>flex-start</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: flex-end;
}
</style>
</head>
<body>
<div class="myclass">
<div>flex-end</div>
<div>flex-end</div>
<div>flex-end</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: left;
}
</style>
</head>
<body>
<div class="myclass">
<div>left</div>
<div>left</div>
<div>left</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
justify-self: right;
}
</style>
</head>
<body>
<div class="myclass">
<div>right</div>
<div>right</div>
<div>right</div>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
.myclass
{
display: grid;
grid-auto-columns: 100px;
grid-auto-flow: column;
grid-auto-rows: 100px;
justify-content: center;
justify-items: center;
width: 100%;
}
.myclass > div
{
background-image: linear-gradient(135deg, white, lightgray);
}
.myclass > div:nth-of-type(1)
{
background-image: linear-gradient(135deg, white, yellow);
}
</style>
</head>
<body>
<button>initial</button><br>
<button>auto</button>
<button>normal</button>
<button>stretch</button><br>
<button>first baseline</button>
<button>last baseline</button>
<button>baseline</button><br>
<button value="unsafe center">unsafe</button>
<button value="safe center">safe</button><br>
<button>center</button>
<button>start</button>
<button>end</button>
<button>self-start</button>
<button>self-end</button>
<button>flex-start</button>
<button>flex-end</button><br>
<button>left</button>
<button>right</button>
<div class="myclass">
<div>justify-self</div>
<div>justify-self</div>
<div>justify-self</div>
</div>
<script>
function myfunction(myparameter)
{
const mytarget = myparameter.target;
const myproperty = mytarget.value || mytarget.innerHTML;
const mystyle = document.querySelector(".myclass").style;
mystyle.gridAutoColumns = "100px";
mystyle.gridAutoRows = "100px";
if(myproperty.includes("safe"))
{
mystyle.gridAutoColumns = "0";
mystyle.gridAutoRows = "0";
}
document.querySelector(".myclass > div").style.justifySelf = myproperty;
}
for(const mybutton of document.querySelectorAll("button"))
{
mybutton.addEventListener("mouseover", myfunction);
}
</script>
</body>
</html>