Home > Web Front-end > CSS Tutorial > CSS box-align attribute controls sub-element layout example analysis

CSS box-align attribute controls sub-element layout example analysis

高洛峰
Release: 2017-03-08 13:52:23
Original
1297 people have browsed it

box-align Description

box-align attribute, used when specifying the vertical arrangement of sub-elements within the element.
When the container element is much larger than the child elements, you can use the box-align attribute to specify the sorting order of the child elements and how to represent the child elements.
Also, the vertical arrangement can be explained as the default value of the configuration direction of the sub-elements within the element is horizontal. After using this attribute, the vertical direction is arranged. You can also use box-orient:vertical to set the direction of child elements.

Attribute value
start: standard direction element, the upper end of each sub-element is arranged along the upper end of the element, and the remaining positions are sorted downward. For reverse-oriented elements, they are arranged along the lower end. Sort the remaining positions upward.
end: For standard direction elements, the lower ends of each sub-element are arranged along the lower end of the element, and the remaining positions are sorted upward. For reverse-direction elements, the lower ends are arranged along the upper end, and the remaining positions are sorted downward.
center: The remaining space will be distributed equally.
baseline: In the case of inline-axis and horizontal, all child elements are aligned with the baseline configuration
stretch: Each child element is automatically sorted according to the height of the container element (default value)

About centering
The original horizontal and vertical centering method is: height=line- height implements vertical centering text-align implements horizontal centering
Now use box-align to implement vertical centering box-pack implements horizontal centering

<!DOCTYPE html>   

<html>   
<head>   
    <title>水平及垂直居中</title>   
</head>   
<body >   
<p style="width:300px; height: 300px; background-color: #ccc;
  line-height: 300px; text-align: center;">   
    <input type="button" value="原有居中方式">   
</p>   
<p style="width:300px; height: 300px; background-color: #aaa;
 display:-webkit-box;-webkit-box-pack: center;
   ; -webkit-box-align:center">   
    <input type="button" value="css3的居中方式">   
</p>   
</body>   
</html>
Copy after login

Example code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml">   
<head>   
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
<title> box-align </title>   
<style>   
p.prefix_sample1 {   
width:500px; height:100px;   
background-color:yellow;   
display:-moz-box;   
display:-webkit-box;   
display:-o-box;   
display:-ms-box;   
-moz-box-align:start;   
-webkit-box-align:start;   
-o-box-align:start;   
-ms-box-align:start;   
}   
p.prefix_sample2 {   
width:500px; height:100px;   
background-color:yellow;   
display:-moz-box;   
display:-webkit-box;   
display:-o-box;   
display:-ms-box;   
-moz-box-align:end;   
-webkit-box-align:end;   
-o-box-align:end;   
-ms-box-align:end;   
}   
p.prefix_sample3 {   
width:500px; height:100px;   
background-color:yellow;   
display:-moz-box;   
display:-webkit-box;   
display:-o-box;   
display:-ms-box;   
-moz-box-align:center;   
-webkit-box-align:center;   
-o-box-align:center;   
-ms-box-align:center;   
}   
p.prefix_sample4 {   
width:500px; height:100px;   
background-color:yellow;   
display:-moz-box;   
display:-webkit-box;   
display:-o-box;   
display:-ms-box;   
-moz-box-align:baselinebaseline;   
-webkit-box-align:baselinebaseline;   
-o-box-align:baselinebaseline;   
-ms-box-align:baselinebaseline;   
}   
p.prefix_sample5 {   
width:500px; height:100px;   
background-color:yellow;   
display:-moz-box;   
display:-webkit-box;   
display:-o-box;   
display:-ms-box;   
-moz-box-align:stretch;   
-webkit-box-align:stretch;   
-o-box-align:stretch;   
-ms-box-align:stretch;   
}   

p.aka {background-color:red;}   
p.midori {background-color:green;}   
p.ao {background-color:blue;}   
</style>   

</head>   

<body>   
<h4>box-align:start;</h4>   
<p class="prefix_sample1">   
<p class="aka">abcde</p>   
<p class="midori">abcde</p>   
<p class="ao">abcde</p>   
</p>   

<h4>box-align:end;</h4>   
<p class="prefix_sample2">   
<p class="aka">abcde</p>   
<p class="midori">abcde</p>   
<p class="ao">abcde</p>   
</p>   

<h4>box-align:center; </h4>   
<p class="prefix_sample3">   
<p class="aka">abcde</p>   
<p class="midori">abcde</p>   
<p class="ao">abcde</p>   
</p>   

<h4>box-align:baselinebaseline; </h4>   
<p class="prefix_sample4">   
<p class="aka">abcde</p>   
<p class="midori">abcde</p>   
<p class="ao">abcde</p>   
</p>   

<h4>box-align:stretch; </h4>   
<p class="prefix_sample5">   
<p class="aka">abcde</p>   
<p class="midori">abcde</p>   
<p class="ao">abcde</p>   
</p>   

</body>   
</html>
Copy after login

Example diagram
CSS box-align attribute controls sub-element layout example analysis

The above is the detailed content of CSS box-align attribute controls sub-element layout example analysis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template