Thursday, 6 June 2019
Alignment in CSS
In CSS, we can align the HTML elements in different ways.
1) margin: auto;
To align a block level element horizontally in the center, give the value of the margin for that element auto.
For example
<style>
.box {
margin: auto;
padding: 20px;
border: 1px solid black;
width: 70%;
}
</ style>
<div class = "box"> <p> This is a test </ p> </ div>
Alignment of Content
Use the text-align property to align the text inside an element.
for example
1)
p {
border: 1px solid block;
text-align: left;
}
<p> This is a paragraph. </ p>
2)
p {
border: 1px solid black;
text-align: center;
}
<p> This is a paragraph. </ p>
3)
p {
border: 1px solid black;
text-align: right;
}
<p> This is a paragraph. </ p>
* vertical-align property: - Use vertical-align property to vertically align a content.
<style>
div p {
border: 1px solid red;
vertical-align: middle;
}
</ style>
<div>
<p> This is a test </ p>
</ div>
Center vertically through the padding
By defining the top and bottom padding of an element, we can also vertically align its contents in the center.
For example
<style>
div {
padding: 40px 0px;
border: 1px solid blue;
}
</ style>
<div>
<p> This is some text. </ p>
</ div>
Recommended Articles
- Web Devolpment in Easy Way
Float Property in CSSJun 08, 2019
Float Float property can have one of these five values ​​- left: - If the value is given then the element is left float on the left side. rig...
- Web Devolpment in Easy Way
Positioning in CSSJun 08, 2019
Positioning in CSS When we create a webpage, many elements are shown in the same order in which we have created them and each element has a...
- Web Devolpment in Easy Way
Text in CSSJun 08, 2019
Text in CSS The color property is used to set the color of the text. We can colorize the colors in the following ways. From color name - lik...
- Web Devolpment in Easy Way
Z Index in CSSJun 07, 2019
Z Index in CSS z-index property is used to define HTML elements of the stack order. Stack order means that any element will look above any oth...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment