Home Web Front-end CSS Tutorial Comprehensive list of CSS layout properties: display, position and float

Comprehensive list of CSS layout properties: display, position and float

Oct 20, 2023 pm 05:36 PM
position float show

CSS 布局属性大全:display,position 和 float

CSS layout properties: display, position and float

CSS is a markup language used to control the style of web pages. Layout properties are very important when designing web page layout. CSS provides a variety of layout properties, the most commonly used of which are display, position and float. In this article, we will introduce these three layout properties in detail and provide specific code examples.

  1. display attribute
    The display attribute is used to specify the display type of the element. Common display attribute values ​​are as follows:

1.1. block
The block element occupies an exclusive line, always starts from a new line, and fills the width of the parent element. For example, the

element is a typical block element.

div {
  display: block;
}
Copy after login

1.2. inline
The inline element will not occupy a line by itself, but only takes up the space it needs. For example, the element is a typical inline element.

span {
  display: inline;
}
Copy after login

1.3. inline-block
The inline-block element will not occupy a row, but the width and height can be set. For example, the element is a typical inline-block element.

img {
  display: inline-block;
}
Copy after login

1.4. none
none elements will not be displayed and will be removed from the document flow. For example, you can hide an element by setting display: none.

.hidden {
  display: none;
}
Copy after login
  1. position attribute
    The position attribute is used to specify how an element is positioned. Common position attribute values ​​are as follows:

2.1. static
static is the default positioning method, and elements are laid out in the order of the document flow.

div {
  position: static;
}
Copy after login

2.2. relative
relative Position relative to its own initial position. The position of an element can be adjusted by using the top, bottom, left and right properties.

div {
  position: relative;
  top: 10px;
  left: 20px;
}
Copy after login

2.3. absolute
absolute Positioning relative to the parent element, or positioning relative to the nearest ancestor element with positioning attributes (position is not static).

div {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
Copy after login

2.4. fixed
fixed is positioned relative to the browser window and will not change position as the scroll bar scrolls.

div {
  position: fixed;
  top: 0;
  right: 0;
}
Copy after login
  1. float attribute
    The float attribute is used to specify how the element floats. When an element is set to float, it is taken out of the normal document flow and floated as far left or right as possible. Other elements will be laid out around the floated element.
img {
  float: left;
}
Copy after login

The above is the introduction and code examples of the three common layout properties of display, position and float. In practice, we can choose which layout attribute to use based on specific needs to achieve web page layout design. I hope this article can provide readers with some help in CSS layout.

The above is the detailed content of Comprehensive list of CSS layout properties: display, position and float. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to locate Apple wireless earphones if they are lost_How to locate Apple wireless earphones How to locate Apple wireless earphones if they are lost_How to locate Apple wireless earphones Mar 23, 2024 am 08:21 AM

1. First, we open the [Search] App on the mobile phone and select the device in the list on the device interface. 2. Then, you can check the location and click on the route to navigate there.

Reasons and solutions for desktop layout being locked Reasons and solutions for desktop layout being locked Feb 19, 2024 pm 06:08 PM

What happens when the desktop layout is locked? When using the computer, sometimes we may encounter the situation where the desktop layout is locked. This problem means that we cannot freely adjust the position of desktop icons or change the desktop background. So, what exactly is going on when it says that the desktop layout is locked? 1. Understand the desktop layout and locking functions. First, we need to understand the two concepts of desktop layout and desktop locking. Desktop layout refers to the arrangement of various elements on the desktop, including shortcuts, folders, widgets, etc. we can be free

How to make a remote desktop connection display the other party's taskbar How to make a remote desktop connection display the other party's taskbar Jan 03, 2024 pm 12:49 PM

There are many users using Remote Desktop Connection. Many users will encounter some minor problems when using it, such as the other party's taskbar not being displayed. In fact, it is probably a problem with the other party's settings. Let's take a look at the solutions below. How to display the other party's taskbar during Remote Desktop Connection: 1. First, click "Settings". 2. Then open "Personalization". 3. Then select "Taskbar" on the left. 4. Turn off the Hide Taskbar option in the picture.

How to locate the other party's mobile phone location on Amap - How to locate the other party's mobile phone location on Amap How to locate the other party's mobile phone location on Amap - How to locate the other party's mobile phone location on Amap Apr 01, 2024 pm 02:11 PM

1. Click to enter the Amap map software on your mobile phone. 2. Click My in the lower right corner. 3. Click to enter the family map. 4. Click Create My Family Map. 5. After the creation is successful, an invitation code will appear and can be shared with another mobile phone.

How to change the location information and how to modify the address How to change the location information and how to modify the address Mar 12, 2024 pm 09:52 PM

We all know very clearly that Taku APP is a very reliable chat and social platform. Now it allows everyone to make friends online. Some of the forms of making friends here mainly allow people to make friends by location. Oh, it's so simple and direct. After all, it can automatically locate your current location information for you, and better match you with some friends in the same city who are close to each other, so that everyone can chat more easily and feel special. Happy, many times, in order to get to know more friends in other places, everyone has the idea of ​​​​modifying their address, but they don’t know how to modify their location information, which is very difficult. troubled, so the editor of this site also collected some specific

How to display the wifi password QR code? It is recommended to scan the wifi password on WeChat in 3 seconds. How to display the wifi password QR code? It is recommended to scan the wifi password on WeChat in 3 seconds. Feb 20, 2024 pm 01:42 PM

You don’t need to enter the WIFI password often, so it’s normal to forget it. Today I will teach you the simplest way to find the password of your own WIFI. It can be done in 3 seconds. To check the WIFI password, use WeChat to scan it. The premise of this method is: there must be a mobile phone that can connect to WIFI. Okay, let’s start the tutorial: Step 1. We enter the phone, pull down from the top of the phone, bring up the status bar, and the WIFI icon. Step 2. Long press the WIFI icon to enter the WLAN settings; long press the WIFI icon. Step 3. Click Connected. Enter the WIFI name of your home, click Share Password, and a QR code will pop up; Step 4 of sharing WIFI password, we take a screenshot and save this QR code; Step 5, long press the WeChat icon on the desktop, and click Scan

How to quickly find the location of a Huawei phone after it is lost? How to quickly find the location of a Huawei phone after it is lost? Mar 24, 2024 am 08:48 AM

In today's society, mobile phones have become an indispensable part of our lives. As a well-known smartphone brand, Huawei mobile phones are deeply loved by users. However, with the popularity of mobile phones and the increase in frequency of use, mobile phones are often lost. Once our phone is lost, we tend to feel anxious and confused. So, if you unfortunately lose your Huawei phone, how can you quickly find its location? Step 1: Use the mobile phone positioning function. Huawei mobile phones have built-in powerful positioning functions. Users can use the "Security" option in the mobile phone settings.

How to check the current directory in Linux? How to check the current directory in Linux? Feb 23, 2024 pm 05:54 PM

In Linux systems, you can use the pwd command to display the current path. The pwd command is the abbreviation of PrintWorkingDirectory and is used to display the path of the current working directory. Enter the following command in the terminal to display the current path: pwd After executing this command, the terminal will display the full path of the current working directory, such as: /home/user/Documents. In addition, you can use some other options to enhance the functionality of the pwd command. For example, the -P option can display

See all articles