Four ways to implement CSS and introduction to selectors
CSS implementation and selector
Contents of this lesson:
1. Four ways to implement CSS
1, in each htmltag There is a style style attribute, and the value of this attribute is the css code. (For a tag)
2, use style tag . Generally defined in the head tag. (For multiple identical tags)
3, when multiple pages use the same style, the style can be individually packaged as a CSS fileImport
4, link a CSS file through the link tag in the HTML header tag
Tag selector div{}
Class selector .haha
id selector #qq (The value of id is unique in the page, because this attribute is not only given to CSS Use, but also for javascript)
The class selector is used the same as the id selector. The priority of the id selector is higher than the class selector. The lower the priority, the higher
3. CSS Notes
css: Separate web page content and display style to improve the display function.
CSS cascading style sheets
separates the styles in the web page and is completely controlled by CSS, enhancing style reusability and scalability.
Format: selector {Attribute name: attribute value; Attribute name: attribute value;...}
4 ways to combine CSS with HTML:
1. Each Every HTML tag has the style attribute
2. When there are multiple tags on the page with the same style, you can define the style tag to encapsulate the style for reuse
css”>css code
3. When multiple pages use the same style, the style can be individually encapsulated as a CSS file and imported
4. Link a CSS file through the link tag in the HTML header tag
Tips: In order to improve the reusability and scalability of styles, define multiple styles separately and combine them Encapsulate it into CSS files, such as p.css, div.css... In a general CSS file, use import to import these CSS files, and then use the link tag in the HTML page to import the general CSS file.
Priority: Proximity principle The style attribute set on the label can override other styles
Selector:
1. Label selector: each The HTML tag name is a selector
2. Class selector: The class attribute in the tag is specified. Add a dot when defining the style. Use className
when referencing js. 3. ID selector: The id of the tag Attributes should be as unique as possible to facilitate JavaScript to obtain elements
4. Extension selector:
a. Association selector: The label in the label table div represents the table div div area
b. combinationselector: multiple selectors separated by commas
c. Element selector: the state of the element is such as the default state of a hyperlink, click Status, hover status, etc.
a:link a:visited a:hover a:active LVHA order
Delete hyperlinks by default underline: text-decoration: none
p :first-letter p:first-line focus: IE6 does not support
CSS filters: styles enriched by some codes
When designing web pages, DIV+CSS
# DIV and P tags belong to the row -level area, and the Enter effect. The SPAN tag is a block -level area, without the effect of the car. Set DIV tag
4. Code 1
1 <!-- 2 本课内容: 3 一、实现CSS四种方式 4 1,每个html标签中都有一个style样式属性,该属性的值就是css代码。(针对一个标签) 5 2,使用style标签的方式。 一般都定义在head标签中。(针对多个相同的标签) 6 3,当多个页面使用相同样式时,可将样式单独封装为CSS文件导入 7 <style type=”text/css”>@import url(“1.css”);</style> 8 4,通过HTML头标签中的link标签链接一个CSS文件 9 <link rel=”stylesheet” href=”1.css” media属性可选,默认设备屏幕/>10 二、选择器11 标签选择器 div{}12 类选择器 .haha13 id选择器 #qq (id的取值在页面中是唯一的,因为该属性除了给CSS使用,还要给javascript使用)14 类选择器和id选择器用法一样,id选择器的优先级比类选择器高,优先级越少越高
15 -->16 nbsp;html>17 18 19 <meta>20 <title>Insert title here</title>21 <!-- type指定下面的css以什么方式解析 -->22 <!--指定这两个样式都作用与div,所以用div后的大括号括起来-->23 <!-- css一般放在头部,因为要预先加载,所以每个出现div的位置都已经被换了样式 -->24 <!--25 第二种方式:26 标签选择器27 div{28 background-color: #000;29 color: #FFF
30 }31 32 -->33 <!-- @IMPORT url("div.css?1.1.11");第三种方式 -->34 <!-- 第四种 link -->35 <link>36 <style>37 /*38 @IMPORT url(1.css);39 @IMPORT url(div.css);40 @IMPORT url(span.css);41 */42 div.haha{43 background-color: #000;44 }45 </style>46 <!-- 类选择器div.haha 优先级比标签选择器高 约少数,优先级越高 -->47 <!-- 类选择器不仅可以相同标签的少部分做,还可以对不同的标签做 -->48 <!-- div.haha中的div可以不写,.haha,那就所有的有哈哈类的都变了 -->49 <!-- 按钮加多套这样的.haha实现动态样式 -->50 51 52 <!--53 css和html相结合的第一种方式54 1,每个html标签中都有一个style样式属性,该属性的值就是css代码。(针对一个标签)55 2,使用style标签的方式。 一般都定义在head标签中。(针对多个相同的标签)56 3,当多个页面使用相同样式时,可将样式单独封装为CSS文件导入57 <style type=”text/css”>@import url(“1.css”);</style>58 4,通过HTML头标签中的link标签链接一个CSS文件59 <link rel=”stylesheet” href=”1.css” media属性可选,默认设备屏幕/>60 61 -->62 <!-- -->63 64 65 <!-- 样式的重叠 重复样式一最后加载为主,不重复样式层叠,其实都是层叠 -->66 <!-- color: #F00 为颜色的缩写 -->67 <div>这是一个div区域1</div>68 <div>这是一个div区域2</div>69 <span>span区域1</span>70 <span>span区域2</span>71 <p>这是一个段落1</p>72 <p>这是一个段落2</p>73 74 75 76
五、代码二
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><meta><title>无标题文档</title><!--link rel="stylesheet" href="1.css?1.1.11" type="text/css" /--><style>/*@import url(1.css); div{ background-color:#09F; color:#FFF; } .haha{ background-color:#FF3; color:#0C0; }*//*预定样式,实现动态的加载。.hehe{ background-color:#C93; color:#00F; }*//*#qq{通常ID的取值在页面中是唯一的,因为该属性除了给css使用,还可以被js使用。id通常都是为了去标示页面中一些特定区域使用的。 background-color:#000; color:#FFF; }*//*span b{关联选择器 选择器中的选择器background-color:#09F; color:#FFF; }*//*组合选择器*//*.haha,div b{对多种选择器进行相同样式定义background-color:#000; color:#C00; }*//*伪元素 超链接的状态。*//*未访问*/a:link{background-color:#06F;color:#FFF;text-decoration:none;font-size:18px;}/*鼠标悬停*/a:hover{background-color:#FFF;color:#F00;font-size:24px;}/*点击效果*/a:active{background-color:#000;color:#FFF;font-size:36px;}/*访问后效果*/a:visited{background-color:#FF9;color:#000;text-decoration:line-through;}p:first-letter{font-size:36px;color:#F00;}div:hover{background-color:#F00;color:#FFF;}input:focus{background-color:#09F;}#qq{float:left;}/*L V H A*/</style><input><input><hr><a>伪元素选择器演示</a><hr><!--css和html相结合的第一种方式。 1,每一个html标签中都有一个style样式属性。该属性的值就是css代码。 2,使用style标签的方式。 一般都定义在head标签中 优先级:标签选择器<类选择器<id选择器<style属性 --><div>这是一个div<b>区域</b>1</div><div>这是一个div区域2</div><span>span<b>区域</b>1</span><span>span区域2</span><p>这是一个段落1</p><p>这是一个段落2</p>
The above is the detailed content of Four ways to implement CSS and introduction to selectors. For more information, please follow other related articles on the PHP Chinese website!

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

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

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

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.

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.

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.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools