Home Web Front-end HTML Tutorial CSS DIV Day 2_html/css_WEB-ITnose

CSS DIV Day 2_html/css_WEB-ITnose

Jun 24, 2016 pm 12:33 PM

Start the second day. Yesterday I learned the basic usage of css, including css references and some common css attributes. Mastering the basic usage of CSS is only the first step in CSS div layout. When it comes to layout, the most important thing is positioning. When we use tables for typesetting, we directly draw grids on the web page and fill the content into the corresponding grids. The same principle applies when using CSS, but CSS cannot draw grids directly. It has its own set of positioning methods. Today’s goal is to master the positioning of css.


First, introduce two definitions: relative positioning and absolute positioning. Relative positioning allows for offsets from the original position of the document. Absolute positioning allows arbitrary positioning. The following are several attributes needed for positioning:



Because positioning is not generally important, here is a detailed introduction to the role of each parameter:


position: static | absolute |relative
static: No special positioning, the object follows HTML positioning rules
absolute: Drag the object out of the document flow, using left, right, top, bottom and other attributes Perform absolute positioning. And its cascading is defined through the z-index attribute. At this time, the object does not have margins, but there are still padding and borders
//We generally use this attribute when using absolute positioning.
relative: Objects cannot be stacked, but will be offset in the normal document flow based on left, right, top, bottom and other attributes


left: auto|lenth
auto : No special positioning, allocated in the document stream according to HTML positioning rules
length : A length value composed of a floating point number and a unit identifier | Percentage. The position attribute value must be defined as absolute or relative for this value to take effect.
Example: div { position: absolute; left: 1in; }
The usage of top and left are the same. It should also be noted that the position attribute value must be defined as absolute or relative for this value to take effect.


width: auto|lenth
auto: no special positioning, allocated in the document stream according to HTML positioning rules
length: composed of floating point numbers and unit identifiers Length value | Percent.
height has exactly the same syntax as width. And it does not need to define position must be absolute


clip : auto | rect ( number number number number )
auto : Object without clipping
rect ( number number number number ) : Based on The order of top-right-bottom-left provides four offset values ​​calculated from the upper left corner of the object as the (0,0) coordinate. Any of these values ​​​​can be replaced with auto, that is, this edge is not cut


overflow: visible | auto | hidden | scroll
visible: Does not cut content or add scroll bars. If this default value is explicitly declared, the object will be clipped to the size of the window or frame containing the object. And the clip attribute setting will be invalid
//The result of this attribute is like when there is no div, as much content as there is will be displayed.
auto: This is the default value of the body object and textarea. Cut content and add scrollbars when needed
hidden: Don’t show content that exceeds object size
scroll: Always show scrollbars


z-index: auto | number
auto: Follow the positioning of its parent object
number: A unitless integer value. Can be negative
//It should be used to produce some three-dimensional effects


visibility: inherit | visible | collapse | hidden
inherit: Inherit the visibility of the previous parent object
visible: Object visible hidden: Object hidden
collapse: Mainly used to hide table rows or columns. Hidden rows or columns can be used by other content. For other objects outside the table, its function is equivalent to hidden. IE5.5 does not yet support this property.


The position, width, height, left, top, z-index in the above attributes are used to position the div, and the clip, overflow, and visibility are used to control the alignment. For content display, these properties can be regarded as the basic properties of a layer. After mastering the basic properties of layers, we can look at an example of using layers to position and control display:



 
 dingwei css
!--
  #container1{position: absolute; top: 100}
//*position: absolute; define container1 as the absolute position*//
#container2{position: absolute; top: 100; visibility: hidden;}
    //*Define container2 as absolute positioning, and the initial visibility is hidden*//
   p{font-size: 12pt;}//*Define the font of p*//
  -->
  
  
   ;color:#cc33cc”>
  Please select a picture:

//*Set font size, name, color*//
 

 

  //*Import an image with the identifier container1*//
  < p style="font-family:cursive script;color:#cc9933;font-size:12pt">
 Name: Desert

//*Set font name, color, size*//
  

  

  

  

  //*Import another type of image, the identifier is container2*//
 

 onclick="container1.style.visibility='visible';
 container2.style.visibility=' hidden'">
//*Define the mouse click event to make picture 1 visible and picture 2 invisible*//
   container1. style.visibility='hidden';
onclick="container2.style.visibility='visible';
container1.style.visibility='hidden'">


Define mouse click event picture 1 as invisible, picture 2 as visible*//
 
 Techniques to control the visibility value in css.

The above example only talks about the flat layout. Tutuo’s previous css knowledge ends here. However, there is a z-index parameter above, which is used to Stereoscopically positioned, so div can also be stereoscopic. Here is a simple stereoscopic example:

 
  zindex

  
 
 ss01010.jpg" class="pile" id="image"
Style="z-index:1">
//*Import an image to make it a pile class, z-index attribute definition is 1, the position is at the bottom
  *//
  
 style="color:#ffff33;z-index:2" > This paragraph The text will be overlaid on the image.
 
//*Define the color and z-index attributes of a piece of text to be 2, in the middle position*//
  style="z-index:3">
   //*Import the second image, make it the "pile1" class, the z-index attribute is 3, and the position is at the top
Square*//
  
  





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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks 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)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

See all articles