search
HomeWeb Front-endHTML Tutorialdiv css (key review)_html/css_WEB-ITnose

CSS Cascading Style Sheet

优势:使页面结构和表现分离1.引入方式:   1)行内样式:<h2 id="Hello-World">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可以控制的。   优先级问题:行内样式  > 内部样式 > 外部样式   就近原则

 2.CSS选择器
      1)语法格式:选择器{属性:属性值;}    举例:h2{color:#0F0;}
  2) 常见选择器
Tag Selector h2{ } Class 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 *{ }

  注意:

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

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.

  
Statement
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
What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

See all articles

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 Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),