In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge points about how to use float in css. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Float and margin
For two adjacent floating elements, when the width of the first floating element (whether left or right) is 100%, the second floating element is squeezed below and can be brought back to the first line by adding a negative margin-right value (the absolute value is at least equal to its own width).
When writing html code, it is our usual habit to write code from left to right according to the UI style, but sometimes the content on the right is more important, so its html structure needs to be placed on top of the left content to allow it to load earlier, such as:
Left fixed width flow layout
Wow 2016-78-55 eat no matter how much do not put on weight, very sad people ah, how can quickly gain weight, online and so on, urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent!
Like reply
* {margin:0; padding:0;} li {list-style: none;} a {text-decoration: none;} body {font-family: 'Microsoft Yahei';}. Wrap {width: 800px; margin: 50px auto;}. Content {float: right; margin-left: 100px;}. Date {font-size: 14px; color: # 666;}. Text {margin: 20px 0;}. Avatar {float: left; margin-right:-80px;}. Avatar img {width: 80px Height: 80px; border-radius: 50%;}
As shown in the figure above, although on UI, the .content element is to the right of the .avatar, we still need to put the .content element in front of the .avatar element in the html structure. At this time, we can set the .content element to float to the right, then set the left or right float to the .avatar element, and then add a negative margin-right value to let it go back to the top.
1. The width of the left and right sides is variable.
Effect picture:
Html Code:
Wow 2016-78-55 eat no matter how much do not put on weight, very sad people ah, how can quickly gain weight, online and so on, urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent! No matter how much you eat, you don't get fat, it's so sad, how can you get fat quickly, online, etc., urgent!
Like reply
Core point:
The .avatar element floats to the left, and the display attribute of the .content element is set to table-cell. In fact, the .content element does not have to set display to table-cell, as long as it can trigger BFC/haslayout, for example:
Float:left/rightposition:absolute/fixedoverflow:hidden/scroll (IE7+) display:inline-block/table-cell (IE8+)
However, because the .content element here is adaptive, cannot be widened, and contains block-level elements, you can only set the overflow attribute.
Css Code:
* {margin:0; padding:0;} li {list-style: none;} a {text-decoration: none;} body {font-family: 'Microsoft Yahei';}. Wrap {width: 800px; margin: 50px auto;}. Avatar {float: left; margin-right: 20px;}. Avatar img {width: 80px; height: 80px; border-radius: 50%;} .content {display: table-cell;}. Date {font-size: 14px; color: # 666 }. Text {margin: 20px 0;}
two。 Right fixed width streaming layout
Effect picture:
Html Code:
Li Ronghao 2016-01-22 will not make do with it.
They tortured each other until they were white-headed, sad and determined not to let go and began to entangle before being magnified by others. Your violence is too tender and painful and enjoyable. If I say no kiss to you, no one can force me to deal with it.
Songs like 5000.
Core point:
1: when the width of the first floating element is 100%, the second element automatically wraps the line, next to the first element, and you can add a negative margin value to the second floating element to make it go up.
2: there is a package element outside the first floating element .content, which makes it easy to add a padding-right value to the .content element, leaving a gap between the content on the left and the picture on the right.
In fact, the idea of double-wing layout also includes the above two points.
Css Code:
* {margin:0; padding:0;} li {list-style: none;} a {text-decoration: none;} body {font-family: 'Microsoft Yahei';}. Wrap {width: 800px; margin: 50px auto;}. Item {padding-bottom: 15px; border-bottom: 1px solid # ccc; overflow: hidden;}. Content {float: left; padding-right: 180px;} .avatar {display: inline-block; width: 32px; height: 32px; border-radius: 50% Vertical-align: middle; overflow: hidden;}. Avatar img {width: 100%; height: 100%;}. Name {vertical-align: middle;}. Date {font-size: 14px; color: # 666; vertical-align: middle;}. Title {display: block; padding: 10px 0; font-size: 18px; font-weight: bold; line-height: 1.5; color: # 333;} .thumbnail {float: left; margin-left:-120px Thumbnail img {width: 120px; height: 120px;}. Meta {margin-top: 15px; font-size: 14px;}. Category-tag {display: inline-block; padding: 08px; margin-right: 10px; border: 1px solid # ea6f5a; border-radius: 3px; color: # ea6f5a}. Msg-tag {color: # 999;} above is all the content of this article "how to use float in css". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.