In web development, we often need to make the layout of the left image and the right text. The traditional method is to float two divs and adjust the size with width. Put the text on the right of the picture on the left to achieve the following effect.
But this will cause problems. Every time we have to define the floating width of the text on the right, we cannot automatically adapt to the width effect.
Today, when I was doing another project, I had a sudden whim. As a result, the text on the right was automatically adapted to the width.
No matter how you change the width of the parent container, the text automatically adapts to the width.
Now I want to share it with you.
The implementation principle is very simple. The parent element Div sets a margin consistent with the image size, and then allows it to locate it. The internal image adopts absolute positioning, so that the coordinates are fixed in the upper left corner, and the right side is free.
That's simple ~
<! Doctype html > < Html Lang = "En" Xmlns = "Http://www.w3.org/1999/xhtml" > < Head > < Title > </ Title > < Style Type = "Text/CSS" > HTML, body { Font-size : 12px ; Cursor : Default ; Padding : 10px ; Margin : 0 ; } Div. Status { Padding-left : 60px ; Position : Relative ; Margin-bottom : 10px ; } Div. Status P { Margin : 0 0 5px 0 ; Line-height : 1.5 ; Padding : 0 ; } Div. Status P span. Name { Color : #369 ; } Div. Status P. Status-cotent { Color : #333 ; } Div. Status. Face { Position : Absolute ; Left : 0 ; Top : 0 ; } Div. Status Div. repost { Border : Solid 1px # ACD ; Background : # F0faff ; Padding : 10px ; } Div. repost P. repost-cotent { Color : #666! Important ; } </ Style > </ Head > < Body > < Div Class = "Status" > < IMG SRC = "Http://tp4.sinaimg.cn/1987012015/50/5607856668/1" ALT = "Person name" Class = "Face" /> < P Class = "Status-cotent" > < Span Class = "Name" > This is what we are talking about. </ Span > : Sweet fan single shoes, sandals, small heels ~ The shoes of all these styles have been quickly collected. Sweet fan single shoes, sandals, small heels ~ These styles of All-tao single shoes quickly accept sweet fan single shoes, sandals, small high heels ~ These styles of All-tao single shoes quickly accept sweet fan single shoes, sandals, small high heels ~ All of these styles </ P > < IMG SRC = "Http://ww2.sinaimg.cn/thumbnail/766f65afjw1dtf50slhz4j.jpg" ALT = "Image" Class = "Inner-pic" /> </ Div > < Div Class = "Status" > < IMG SRC = "Http://tp4.sinaimg.cn/1987012015/50/5607856668/1" ALT = "Person name" Class = "Face" /> < P Class = "Status-cotent" > This is to say: Sweet Fan Shan shoes, sandals, small heels ~ The shoes of all these styles have been quickly collected. Sweet fan single shoes, sandals, small heels ~ These styles of All-tao single shoes quickly accept sweet fan single shoes, sandals, small high heels ~ These styles of All-tao single shoes quickly accept sweet fan single shoes, sandals, small high heels ~ All of these styles </ P > < Div Class = "Repost" > < P Class = "Repost-cotent" > < Span Class = "Name" > @ This is the content. </ Span > : Sweet fan single shoes, sandals, small heels ~ The shoes of all these styles have been quickly collected. Sweet fan single shoes, sandals, small heels ~ These styles of All-tao single shoes quickly accept sweet fan single shoes, sandals, small high heels ~ These styles of All-tao single shoes quickly accept sweet fan single shoes, sandals, small high heels ~ All of these styles </ P > < IMG SRC = "Http://ww2.sinaimg.cn/thumbnail/766f65afjw1dtf50slhz4j.jpg" ALT = "Image" Class = "Inner-pic" /> </ Div > </ Div > </ Body > </ Html >