Floating and locating problems in an instance

Source: Internet
Author: User

First, in a tag to add pictures, the resolution of the time there was a strange distance.

  
 
  1. div{
  2. border:1px solid red;
  3. padding:1px;
  4. float:left;
  5. }
  6. <div>
  7. <a> src="img/pic.jpg"/></a>
  8. </div>

Solutions
One, you can choose to add a font-size:0 to the parent div; Two, add a vertical-align:middle to the style of the picture;

Because the picture is arranged according to the text, you can add a vertical-align:middle to the attributes of the picture; )


  
 
  1. div{
  2. border:1px solid red;
  3. padding:1px;
  4. float:left;
  5. /*font-size:0;*/
  6. }
  7. img{
  8. vertical-align: middle;
  9. }
  10. <div>
  11. <a> src="img/pic.jpg"/></a>
  12. </div>
Unresolved resolved

Second, the use of floating problem

To make an element appear on the same line, you can use float. (when not given wide, the float will change the width of the element from the width of the upper parent to the width of the content)

Floating gives, be sure to give the parent clear float, because there will be a lot of unexpected effects. (except for collapse)

After using the float, want to adjust the distance between the elements with margin

This div is not wide, so its width will follow the upper level, which is the width of the body. When a div uses a floating element, if it has a child element, its width will be stretched by the contents of the subelements.



Third, the use of positioning problems

Because the positioning is out of the document flow, when the child element uses positioning, the parent's height is no longer stretched by sub-level content, so the parent must be given a clear height.

For problems with the width of the parent, if the width is not given, the element will generally inherit the previous level of width.







Floating and locating problems in an instance

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.