push elements left or right with the float property - zilongxuan001/LearnFreecode GitHub Wiki
这个定位工具并不是实际上用position
,而是设置元素的属性为float
。
浮动(floating)元素就是从文档自然流中移除该元素,然后放到父元素的左边或右边。
使用width
属性设置浮动元素偏离多少水平空间。
这里有两个列的布局,section
和aside
两个是挨着的。
给#left
条目一个left
的float
,给#right
条目一个right
的float
。
<head>
<style>
#left {
float:left;
width: 50%;
}
#right {
float:right;
width: 40%;
}
aside, section {
padding: 2px;
background-color: #ccc;
}
</style>
</head>
<body>
<header>
<h1>Welcome!</h1>
</header>
<section id="left">
<h2>Content</h2>
<p>Good stuff</p>
</section>
<aside id="right">
<h2>Sidebar</h2>
<p>Links</p>
</aside>
</body>
Applied Visual Design: Push Elements Left or Right with the float Property | Learn freeCodeCamp
2018-10-25 09:42:30