Introduction to CSS Horizontal Align
CSS Horizontal Align is defined and specifies with the CSS Box Alignment module features. it can be aligned through and related with the different sets of alignments for various boxes meanwhile is used in the boxes, layout models like block layouts, grid layouts, table layouts, and flex layouts. These are the different set of layouts will be set and aligned to the boxes in the horizontal order the boxes and layouts are followed and supported with both horizontal and vertical layouts across all the css files similarly the horizontal layouts are supported with the images, text, and animations data’s.
Syntax and Parameters
The CSS codes are written with the html page using style tag we can follow some rules and syntax for customized web pages more attractiveness.
<html>
<head>
<style>
.example{
position:absolute;
right:
left:
width:
height:
background-color:
}
</style>
<body>
</body>
</html>
The above codes are the basic syntax for using the css horizontal alignments are using both left and right positions it can be supported the block elements. We can enable the above css properties and passing some default values or some user-defined values with any type of supported formats.
How Horizontal Align Work in CSS?
The Horizontal alignment is used for aligning the data contents for both horizontally and vertically for usual requirements in any of the web applications. It has some different sets of ways to achieve these features in the CSS file. The first type is CSS transform its one of the types for creating and aligning the data contents in the web pages for fixed content blocks with widths and heights in both directions. For sometimes the nonfixed width range of the html contents the blocks are assumed with 100% of the parent’s width it can be expanded with the whole width ranges of the parent containers for a fully horizontal position we can mark and checked this by removing the customized width ranges for the contents by using some examples like codepen etc. During this technique, it’s not acceptable for the work if the data contents is the inline level position of the elements it supports and works for only the block-level elements. The Modern flexbox is one of the layouts for using main and cross axis it depends on the flex-direction property by default the flex-direction the value is set to row. So the main axis is X and the cross axis is Y it belongs to the column direction. We can use <div> tag elements for aligning the elements in the web pages either in the horizontal and vertical direction. Because mainly in div tag container with fixed width and height even though they have some default properties with values for presenting the web pages with more attractiveness.
If we have aligned the text or any datas through horizontal position in the web pages we use <div> tag in html as well as it can be respected to the parent html elements also the css margin property is enabled with the default values like auto for both the left and right side of the margins. We can set the style rules as margin and also the text will be aligned parallelly in Inline Elements on the page each line of the page content is as line box. We already said css has many different properties likewise text-align is one of the property for aligning the text values on the web page using these properties we can align the text as the center, left, right, or justified. The auto is sometimes defaulted value of the properties like margin:0 auto; it can be supported to the left, right, center elements we can use these types in the margin lines or boxes from the file it will be reflected in the applications using div tag elements it will be possible for the block boxes.
Examples of CSS Horizontal Align
Following are the examples are given below:
Example #1
Code:
<!DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome To My Domain</title>
<style>
.first {
width: 83%;
margin: 2 auto;
padding: 23px;
background: green;
}
</style>
</head>
<body>
<div class="first">
<h1>Welcome To My Domain</h1>
<p>Users are Welcome</p>
</div>
</body>
</html>
Output:
Example #2
Code:
<!DOCTYPEhtml>
<html>
<head>
<title>Welcome To My Domain</title>
<style>
.first {
padding: 12px;
width: 73%;
margin: 2 auto;
background-color: green;
text-align: center;
color: red;
border-radius: 1 2 52px 53px;
border: 2px yellow;
}
.second{
margin: 12px;
padding: 13px;
color: green;
border: 3px blue;
}
.third{
width: 122px;
display: inline-block;
background-color: blue;
}
.four{
text-align: right;
}
.five{
text-align: center;
}
.six{
text-align: left;}
.seven{
text-align: center;
}
.eight {
background-color: violet;
}
.nine{
float: right;
}
.ten{
position: absolute;
left: 153px;
}
</style>
</head>
<body>
<div class="first">Siva</div>
<div class="second">Raman</div>
<span class="third">Arun</span>
<span class="four">Kumar</span>
<span class="five">Sam</span>
<div class="six">
<div class="seven">xxx</div>
<div class="eight">user</div>
<div class="nine">welcome</div>
</div>
</body>
</html>
Output:
Example #3
Code:
<!DOCTYPEhtml>
<html>
<head>
<title>Welcome To My Domain</title>
<style>
.first {
padding: 12px;
width: 73%;
margin: 2 auto;
background-color: green;
text-align: center;
color: red;
border-radius: 1 2 52px 53px;
border: 2px yellow;
}
.second{
margin: 12px;
padding: 13px;
color: green;
border: 3px blue;
}
.third{
width: 122px;
display: inline-block;
background-color: blue;
}
.four{
text-align: right;
}
.five{
text-align: center;
}
.six{
text-align: left;
}
.seven{
text-align: center;
}
.eight {
background-color: violet;
}
.nine{
float: right;
}
.ten{
position: absolute;
left: 153px;
}
.eleven {
width: 83%;
margin: 2 auto;
padding: 23px;
background: green;
}
.sam {
position: absolute;
right: 3px;
width: 303px;
background-color: yellow;
}
</style>
</head>
<body>
<div class="six">Siva</div>
<div class="second">Raman</div>
<div class="third">Arun</div>
<div class="four">Kumar</div>
<div class="five">Sam</div>
<div class="eleven">
<img src="first.jpg"alt="centered image"/>
</div>
<div class="seven">xxx</div>
<div class="eight">user</div>
<div class="nine">welcome</div>
<div class="sam">Sarath</div>
</div>
</body>
</html>
Output:
In the above three examples, we have used the horizontal alignments in the different scenarios of left, right, and the center position of the web pages. In the alignments, we have set some default values.
Conclusion
In CSS technique alignment is one of the features for creating the web pages with user attractiveness. The horizontal alignment is one of the techniques used in css for aligning the datas with some types also we used margin property for aligning the datas in the user perspective.
Recommended Articles
This is a guide to CSS Horizontal Align. Here we also discuss the introduction and how horizontal align work in css? along with different examples and its code implementation. You may also have a look at the following articles to learn more –