Parallel text layout without floating

Source: Internet
Author: User

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  > 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.