Home >Web Front-end >HTML Tutorial >CSS tag selector (2)_html/css_WEB-ITnose
CSS language has two basic functions: matching and rendering
When browsing When the browser parses the CSS style, it should first determine which elements need to be rendered, that is, which HTML elements are matched. This operation is identified by the selector in the CSS style.
Only after matching a specific object, the browser can determine the rendering effect based on the CSS style declaration and present it on the page in time.
Uses elements of document object type as selectors, such as p, div, span, etc.
The most commonly used selector is the tag selector. Tag selectors can be used to find specific types of elements, such as paragraphs, hyperlinks, or heading elements. Simply specify the name of the element to which you want the style applied.
Tag selectors are sometimes called element selectors or simple selectors.
Such as:
/*段落字体颜色为黑色*/p{ color:black;}/*超链接显示下划线*/a{ text-decoration:underline;}/*一级标题显示为粗体效果*/h1{ font-weight:bold;}
Advantages: Able to quickly Labels of the same type on the page have a unified style.
Disadvantages: Differentiated styles cannot be designed and sometimes interfere with each other
For example: If the following style is defined in the web style sheet, all div element objects are defined to have a width of 774px
/*所有div元素对象定义为宽度为774px*/div{ width:774px; }
Then when using divs for layout, you need to redefine the width of each div object in the page, because not every div element object in the page has a width of 774px. , otherwise it will be a very troublesome thing774.
If you want the label to define a default style, you can use the label selector. For example, when using the ul element, it will be automatically indented and come with a list symbol. Sometimes this style will cause trouble in the list layout. In this case, you can select the ul element as the label selector and clear the predefined style.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>标签选择器</title><link type="text/css" rel="stylesheet" href="css/test2.css" /></head><body><h1>标签选择器</h1><p>段落设置字体为蓝色</p><a href="#">超链接没有下划线</a><ul><li><a href="#">列表1</a></li><li><a href="#">列表2</a></li><li><a href="#">列表3</a></li></ul><img alt="狗粮" src="images/003.jpg" /><a href="#"><img alt="小狗" src="images/408330.jpg" /></a><table><tr><td>姓名:</td><td><input type="text" name="username" /></td></tr><tr><td>密码 :</td><td><input type="password" name="password" /></td></tr><tr><td><input type="submit" value="提交" /></td><td><input type="reset" value="重置" /></td></tr></table></body></html>
@charset "utf-8";/* CSS Document *//*统一文档字体大小,行高,字体*/body{ font:12px Arial, Helvetica, sans-serif; color:#000000;}/*段落字体颜色为蓝色*/p{ color:#0000FF;}/*一级标题显示为粗体效果*/h1{ font-weight:bold;}/*设置a标签的下划线为没有*/a{ text-decoration:none;}/*清除预定义样式*/ul{ margin:0px; list-style:none; }/*设置图像的边框为0*/img{ border:0px;}/*统一表格字体和行高*/table{ border:solid 5px #000000; /*边框实线,宽度为5px,颜色为黑色*/ font-size:12px; /*字体大小为12px*/ color:#666; /*字体颜色为中灰*/ line-height:200%; /*行主为默认值的2倍*/}/*设置input标签的边框为实线,1个像素,颜色为浅灰*/input{ border:solid 1px #ddd;}
/*清除预定义样式*/ul{ margin:0px; list-style:none; }
If you want to unify the styles in the document tags, you can also Use tag selector.
For example, unify the document font size, line height, and font, unify the font style of the table through the table tag selector, clear the underline of all hyperlinks through the a tag selector, and clear the web page through the img tag selector. The border of the image. When the image is embedded in the a element, that is, when it is used as a hyperlink object, the border will appear. Through the input tag selector, the unified input form border is light gray, etc.
/*统一文档字体大小,行高,字体*/body{ font:12px Arial, Helvetica, sans-serif;}/*统一表格字体和行高*/table{ font-size:12px; /*字体大小为12px*/ color:#666; /*字体颜色为中灰*/ line-height:200%; /*行主为默认值的2倍*/}/*设置a标签的下划线为没有*/a{ text-decoration:none;}/*设置图像的边框为0*/img{ border:0px;}/*设置input标签的边框为实线,1个像素,颜色为浅灰*/input{ border:solid 1px #ddd;}
For general structural elements such as div and span, it is not recommended to use tag selectors because general structural elements have a wide range of applications. Use tag selectors Will interfere with each other