Home Web Front-end HTML Tutorial How to use position and float in html?

How to use position and float in html?

Jul 19, 2017 pm 02:36 PM
html position

Syntax:

position: static (static positioning) | absolute (absolute positioning) | fixed (fixed positioning) | relative (relative positioning)

Attribute parameters:

static: Static positioning, no special positioning, the object follows HTML positioning rules (the default state of html)

absolute: Absolute positioning, the object is out of the document flow, and you need to use left, top, right, bottom and other attributes for accuracy location. You can use the z-index attribute for cascading. (If the element floats when using absolute positioning and is not at the position you specified, you can use relative positioning on the parent element of the element. "Personal suggestion")

relative: Relative positioning, the object does not leave the document Flow cannot be cascaded like absolute, but attributes such as left, top, right, bottom, etc. must still be used to move relative to the original object position in the normal document flow, and the original position will be occupied by other elements.

fixed: Fixed positioning, separated from the document flow, can keep the element in a fixed position on the screen, and the element position will not change even if the scroll bar is pulled down.

<p  style="border=“1px  solid red;position:absolute;top:150px;left:200px;">我是p111111</p>
Copy after login

p111111 will move 150px down and 200px to the right

<p  style="border=“1px  solid red;position:absolute;bottom:50px;right:100px;">我是p222222</p>
Copy after login

p222222 will move 150px from the bottom and 100px from the right border

When you want to do Use position: fixed; bottom: 50px; right: 50px when using a module that is always displayed in the lower right corner of the page; you can make p display 50px from the bottom and 50px from the right border, and no matter how your page changes, p will always be displayed on you The same position within the visual range

z-index: 100px; the larger the pixels that follow, the higher the level of p

Syntax:

float: left | left | none; right, left or not used (default)

float: out of the document flow, floating is relative to the parent element

<p  id="p1">
  <p  id="p2"></p>
</p>
Copy after login

As above: p1 is the parent of p2 Level element p2 can only be floated inside p1

A frequently used situation for floating is the use of horizontal navigation bars. There are two ways to implement the horizontal navigation bar. As long as the display attribute of the li tag is changed to the inline style, the list can be tiled. This is the core part, but after understanding the box model, we can know that the margin and padding of the inline tag are opposite. The up and down directions are invalid. Only the left and right sides of the list options can be stretched here. The top and bottom directions will not be controlled. Only the top and bottom directions of block-level labels will be controlled.

float is also a simple application of some text wrapping picture effects. Put the picture and text into the same p and then give the picture and p a float: left | right;

<p   style="width:220px;height:300px;float:left;">
  <img  src=".."   style=" float:left;"/>这里是文字654651进行图文混排以及文字环绕kj dsh gkjh kjh jb kjf bg kjs dh fkj gh kj sd hjf hk jk jsh kjg hk
</p>
Copy after login

The above is the detailed content of How to use position and float in html?. 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles