Questions to note about HTML page layouts

Source: Internet
Author: User

1. Set the element width as a percentage errors that may result

Many students are accustomed to using percentages to set the width of page elements (such as Div, which is referred to as the box, easy to introduce), which may cause unknown errors, most commonly when the page is reduced, or the screen resolution is lowered, because the width of the box is set by using the resolution, The box itself decreases as the resolution decreases, potentially causing internal elements to fit inside, and the contents are squeezed to the next line, resulting in layout errors.

I. Solutions

It should be emphasized that using percentages to set the width of the box is not a good idea, but if you use a percentage to set the width, we'd better set the minimum width element{min-width:1000px for the box, and ensure that the inner elements of the box are properly arranged in the box. or set the width of the box to a fixed size, so that we can ensure that when the page shrinks to a certain extent, the page will appear scroll bar, will not affect the layout of the elements inside the box.

2. Do not move the parent element when you want the icon to move position

A common mistake for some students is to change the position of the parent element by changing the position of the icon (for example, to center the icon and moving the N px to the left), which is obviously wrong. The popular saying is that we want to move the sofa, but the house was moved away.

3. How to center a block element

There are many ways to center a block element horizontally, and the most common practice is to set the following style for the element div{margin:0 auto;} , or we can use relative displacement to change the position of the element selector{position:relative;left:npx}, but this practice often requires the calculation of pixel values, so the first approach is more direct and effective.

4. Comparison of block elements and inline elements

Block elements are called block elements because they all appear by default in a rectangular shape (using the CSS3 style can change this feature), the block element has height, width characteristics, that is, we can set the height and width of the block element to change its original size. Inline elements are different, and by default the contents of the mid-term are arranged, and their shapes are displayed. Another block element adds a newline between the front and the back, which means that the block element is displayed by default (unless we set a float or use a displacement to change its initial position), and through the display property, we can set the state of the element to be displayed;

Display:block; /* element is displayed as a block element */ Display:block; /* elements displayed as inline elements */ Display:inline-block; /* element is displayed as a block element, but with inline features, that is, the end of the line break is canceled/

  

Questions to note about HTML page layouts

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.