CSS tips: Learn about CSS page layouts and loading processes

Source: Internet
Author: User

If you develop web-related applications or websites, you must know the importance of CSS for page layouts. In this CSS tip we'll introduce the page loading process to help you better implement the page layout.

introduce

Before we begin the formal introduction of the page process, we need to learn a few different types of HTML elements and how they are displayed by default. Here we mainly focus on two types of elements:

    • Block
    • Inline

If you care about HTML5, you should know that there are a few new elements in HTML5, such as Section,article, but still follow the display type we introduced here.

Elements of the inline type include: Img,span,a, which is used to define text or data, and is usually displayed "on the same line". More specifically, if many of the inline types of elements are on the same line, they will appear in the same row until the width is not enough, and then go to the next line. For example, the following code:

1
gbtags.com is website for geeks

View Online debugging

Elements of the opposite block type, such as Div,p or HTML5, and the new elements section,article and article are displayed differently than the inline type. They are typically structured elements that can contain elements of the inline type. The browser handles the elements of the block type, adding lines before and after the elements, so you can see that they are all displayed independently. Of course, if you modify its default display type of inline, it will display according to the inline element's display.

Style CSS

Often we use CSS to control the display of elements:

1
2
3
sometag{   
  Display:inline;
						/* Of course you can also set to Block,none and so on supported properties *

Although we specify the display type in the above attribute, it also means that other related styles, for example, you can specify the width and height of the element with the display type block, but the inline type cannot be specified. Padding (inner margin) and margin (outer margin) can be applied to elements displayed by inline, but they are not affected by the elements that are contained. Take a look at the following examples:

View Online debugging

some other ways of showing

In addition to the inline and block type display, there is also a inline-block display. The following figure:

It appears in the same way as inline, but its associated attributes, such as width, height, and padding/margin, are governed by the rules of the block display type. Inline-block can help us achieve the effect of float-like elements, but we also have our own problems.

Other properties such as List-item, as the name suggests, appear in the same way as list elements.

1
2
3
4
     
  • elements 1
  • elements 2

Finally, there is an element to mention that is "none", this property allows the element to not be displayed, and does not occupy any document space. Notice the difference with the "hidden" attribute.

loading process for normal document

So what is the normal loading process of the browser? Basically the browser displays the content in the order in which it is parsed, the top is loaded first, and then the following content is loaded. When you start to do web design, you may not care about the normal document loading process, but only a variety of different fancy techniques, if you can correctly understand the document loading, for better help you understand the web design is absolutely good for no harm.

do an exercise!

Here we will make a simple contact to help you consolidate your study, here we use HTML5 Shiv to help us support HTML5 tag, use Placekitten image placeholder application to generate pictures.

The HTML frame code is as follows:

1
2
3
4
5
6 7 8 9 (15)
18
						
     

an Intro to Normal Document flow.

gbtags.com

CSS Layout code:

1
2
3
4
5
6
7 8 9
30 (a) (a)
at
36
body{
  font-size:12px;
  font-family:arial;
}
. Container
						{
    width:
						85%;
    margin:0
						Auto;
    Background:
						#f2f2f2;
}
Figure img {
    padding-left:
						10px;
}
H1 {
    Font-family:verdana, Geneva, Arial, Helvetica,
						Sans-serif;
    Color:
						#707070;
    padding:
						10px;
    font-size:14px;
}
Article {
    background:
						#505050;
    Color:
						#f2f2f2;
    padding:
						10px;
}
footer{
  width:
						85%;
  margin:0
						Auto;
}
section{
  padding:
						20px
						0;
}

View Online debugging

Summary

Hope that through the study of this article, we can better understand the document loading and layout, if you have any questions or suggestions, please give us a message, thank you!

Source: CSS Tips: Learn about CSS page layouts and loading processes



Related Article

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.