CSS Align Content Property Example [How To]

CSS Align Self Property Example [How To]

“How to write align-self property using css”?

The Align Self property is a sub property of “Flexible Box” and it is used to overrides the container's “align-items” property.


Align Content Property Accepts 5 different values and it will be the same as “align-items”.
1.      centre,
2.      flex-end,
3.      flex-start,  
4.      stretch and
5.      baseline

CSS Syntax:-

.align-self {
    width: 300px;
    height: 200px;
    border: 1px solid black;
    display: -webkit-flex; 
    -webkit-align-items: flex-start;
    display: flex;
    align-items: flex-start;
}

.align-self div {
    -webkit-flex: 1; 
    flex: 1;
}

.self {
    -webkit-align-self: center;
    align-self: center;
}

Exaample as,

<!DOCTYPE html>
<html>
<head>
<style> 
.align-self {
    width: 300px;
    height: 200px;
    border: 1px solid black;
    display: -webkit-flex; 
    -webkit-align-items: flex-start;
    display: flex;
    align-items: flex-start;
}

.align-self div {
    -webkit-flex: 1; 
    flex: 1;
}

.self {
    -webkit-align-self: center;
    align-self: center;
}
</style>
</head>
<body>

<div class="align-self">
  <div style="background-color:lightblue;" class="self">BLUE</div>  
    <div style="background-color:coral;">RED</div>
  <div style="background-color:lightgreen;">AND SO ON..</div>
</div>
</body>
</html>

The live demo Result,

BLUE
RED
AND SO ON..

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.