转载自个人博客
1.常用选择器
1.1标签选择器
p{ }/*选择标签名为p的元素*/
1.2类选择器
.box{ }/*选择class名为box的元素*/
1.3ID选择器
#pid{ }/*选择id名为pid的元素*/
1.4通配符选择器
*{ }/*选择页面中所有的元素*/
1.5选择器前缀
div.bd{}/*选中class名为bd且标签为div的元素*/
1.6属性选择器
[disabled]{}/*选择带有属性disabled的所有元素*/[type=button]{}/*选择type属性为button的所有元素*/[class~=sports]{}/*选择class属性包含sports所有元素*/[lang|=en]{ }/*选择以lang属性以"en"开头以及以"-"分隔的所有元素*/a[href^="#"]{ }/*选择href属性以"#"开头的a元素*/[href$="pdf"]{ }/*选择href属性以"pdf"结尾的元素*/[href*="lady.163.com"]{}/*选择href属性中包含"lady.163.com"的元素*/
2.伪类选择器
2.1链接伪类
/*前两个只可用于描元素(链接)*/a:link {color:#FF0000;} /* 未被访问的链接 */a:visited {color:#00FF00;} /* 已被访问的链接 *//*后两个可以用于其它元素*/a:hover {color:#FF00FF;} /* 鼠标指针移动到链接上 */a:active {color:#0000FF;} /* 正在被点击的链接 */
链接在进行设置时:a:hover 必须位于 a:link 和 a:visited 之后, a:active 必须位于 a:hover 之后。
2.2动态伪类
input:focus{}/*设置input元素获得焦点后的样式*/input:enabled{}/*元素可用的状态*/input:disabled{}/*元素不可用的状态,属性选择器[disabled]的简写*/input:checked{}/*单选框或者复选框选择的样式*/
2.3树形图上的伪类
html结构如下:
<ul> <li>1</li> <li>2</li> <li><a href="#">3</a></li> <li>4</li> <p>5</p></ul>
选择符:
ul:first-child{}/*选择第一个ul下第一个标签(css2定义,支持ie7)在处理margin时很有用*//*以下全是CSS3新增的伪类*/ul:last-child{}/*选择最后一个li标签*/ul:nth-child(n){}/*选择()内的表达式如:[2n+1],或者数字所代表的li标签*/ul:nth-last-child(n)/*同上,反向选择*/ul:only-child{}/*选择ul只有一个子元素的项,这里会选中第三个li下的a标签*/ul:first-of-type{}/*选择第一个该类型的标签,会选择第一个li和p*/ul:last-of-type{}/*选择最后一个该类型的标签,会选择第四个li和p*/ul:nth-last-of-type(2n){ }/*倒数的选择(.)内的表达式[2n],或数字所代表的该类型标签。选择第一个和第三个li标签*/ul:only-of-type{}/*选择ul下中只有一个该类型的项,会选中a标签和p标签*/:root{}/*选择文档的根元素*/ul:not(li){}/*选择不含有li标签的元素,这里会选中a标签和p元素*/ul:empty{}/*匹配ul下没有任何子元素(包括text节点)的元素,这里匹配不到,把p标签中的5删除,可匹配成功*/E:target{}/*匹配相关URL(锚点)指向的元素。*/
3.伪元素选择器
::first-letter{}/*选择第一个字母*/::first-line{}/*选择第一行*/::before{content:"before";}/*在某个元素之前插入一些内容*/::after{content:"after";}/*在某个元素后插入一些内容*/::selection{}/*设置于被用户选中时的样式*/::placeholder{}/*设置对象文字占位符的样式*/
4.组合选择器
4.1后代选择器
.main h2{ }/*选择class名为mian元素内的所有h2标签*/
4.2子选择器
.main>h2{ }/*选择class名为mian元素内的直接关联与父元素的h2标签*/
4.3相连选择器
h2~p{}/*只要P标签前有h2标签便选择*/
4.4兄弟选择器
h2~p{}/*选择h2标签后出现的所有p标签*/
4.4选择器分组
h1,h2,h3{backgound-color:#ddd;}/*同时设置h1,h2,h3标签,使用","分隔*/
5.继承
body{font-family:"Microsoft Yahei";}/*设置页面中所有的字体为微软雅黑*/
-
继承属性
color
font
text-align
list-style
...
-
非继承属性
background
border
position
...
6.CSS优先级
-
计算方法
a = 行内样式
b = ID选择器的数量
c = 类/伪类和属性选择器的数量
d = 标签选择器和伪元素选择器数量
value = a1000 + b100 + c*10 +d
!important强行提升优先级

The usage methods of HTML tags and attributes include: 1. Basic usage: Use tags such as and, and add necessary information through attributes such as src and href. 2. Advanced usage: Use data-* custom attributes to achieve complex interactions. 3. Avoid common mistakes: Make sure the property values are surrounded by quotes. 4. Performance optimization: Keep it simple, use standard attributes and CSS class names to ensure that the image has alt attributes. Mastering these will improve web development skills.

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

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.

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

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.

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.

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.

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


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

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

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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