Home Web Front-end HTML Tutorial div css (key review)_html/css_WEB-ITnose

div css (key review)_html/css_WEB-ITnose

Jun 24, 2016 pm 12:27 PM

CSS Cascading Style Sheet

优势:使页面结构和表现分离1.引入方式:   1)行内样式:<h2 style="color:#0F0">Hello World</h2>  2)内部样式:<style type="text/css">              h2{                 color:#F00;                  }         </style>  3)外部样式:<link href=“a.css”  type=“text/css” rel=“stylesheet”/>    推荐         <style type="text/css">              @import url("a.css");                    //  @import “a.css”;          </style>    问题:link和@import的区别: Link和@import的区别:                     1.隶属上的差别                        link是一个html的一个标签,而@import是css的一个标签                      2. @import次数限制  听说在IE下只能导入61个CSS样式文件                       3.加载顺序的不同                         当一个页面被加载的时候(就是被浏览者浏览的时候),link引用的CSS文件会同时被加载,                         而@import引用的CSS 会等到页面全部被下载完再被加载。                        4.兼容性上的差别                         由于@import是CSS2.1提出的,@import只有在IE5以上的才能识别,而link标签无此问题                        5.使用DOM控制样式时的差别                         当使用javascript控制DOM(document.styleSheets)去改变样式的时候,只能使用link标签,因为@import不是dom可以控制的。   优先级问题:行内样式  > 内部样式 > 外部样式   就近原则
Copy after login

 2.CSS选择器
Copy after login
      1)语法格式:选择器{属性:属性值;}    举例:h2{color:#0F0;}
Copy after login
  2) 常见选择器
Copy after login
Tag Selector h2{ } Class Selector .a { }

// Cannot be a numeric ID selector #a{ }

// ID must be a unique intersection selector h1,h2{ } Union selector ( Parent class selector) p a{ } Pseudo class selector Anchor link LoVe Hate CSS2 - :first-child Pseudo class p:first-child { font-weight: bold; } Universal selector *{ }

  注意:
Copy after login

    一个HTML元素只能有一个ID选择器,但是可以有多个类选择器。
Copy after login
    ?<h1 id = “a” id = “b”></h1>                                             错误
Copy after login
    ?<h1 class = “a b c”></h1> .a{  }   .b{   }   .c{   }               正确  3. 盒子模型(边距)                
Copy after login

border, margin, padding.

boder: The border of the table box.

Margin: the distance between the box and the outside world

padding: the distance between the box boundary and the content inside the box.

border:1px means the top, bottom, left and right borders are 1px

boder:1px 2px means the top and bottom borders are 1px, and the left and right borders are 2px

Represents a border The order is top, right, bottom, left.

Set borders individually: bottom border: border-bottom: 2px solid #cccccc;

Head border: border-top: 2px solid #cccccc;

margin,padding Similar to border.

IE6/IE7/firefox final width = left margin, left border width, left inner margin, width, right inner margin, right border width, right outer margin.

4. CSS floating

Floating concept:
When using div layout, I found that each div is arranged in blocks, which is not conducive to the layout of the page, so CSS The floating technology of elements is proposed, which can make block elements appear in the same line while floating.
Features
The element will get stuck when it encounters the border of the parent container when floating
If the child element and the parent element float in opposite directions at the same time, then the parent element will be floated first, and then the child element will float in the parent element Internal float
If the parent element does not float and contains floating child elements, then the floating element will break away from the document flow (emphasis)

1: Web page layout method: floating layout, positioning layout. They are all out of the control of document flow (top-down relationship).
2: Floating cleaning: clear
3: When to use floating positioning
Note: Floating is required when the website has strong adaptability to resolution and content size. In the center layout, the horizontal width can be scaled by percentage, and you need to use attributes such as margin, padding, and border.
After the layer is set to float, the layer will be separated from the document flow, and subsequent layers will flow into this layer, but the text will not flow into this layer. It is not completely separated from the document flow


Absolute positioning will cause the layer to be completely separated from the document flow and placed on top of other objects. At this time, the layer has the z-index attribute. The larger the value of the z-index attribute, the more this layer appears on top. Position has two commonly used values: absolute and relative. The former represents absolute positioning and does not take up space. The latter represents relative positioning and takes up space. The default is not set to static

z-index
The z-index attribute in CSS is used to set the stacking order of nodes. Nodes with a higher stacking order will be displayed in front of nodes with a lower stacking order. This is our common understanding of the z-index attribute.

Copy after login

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)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

See all articles