时间:2021-05-08
The CSS syntax is made up of three parts: a selector, a property and a value:
selector {property:value}The selector is normally the HTML element/tag you wish to define, the property is the attribute you wish to change, and each property can take a value. The property and value are separated by a colon, and surrounded by curly braces:
body {color:black}Note: If the value is multiple words, put quotes around the value:
p {font-family:"sans serif"}Note: If you want to specify more than one property, you must separate each property with a semicolon. The example below shows how to define a center aligned paragraph, with a red text color:
p {text-align:center;color:red}To make the style definitions more readable, you can describe one property on each line, like this:
pYou can group selectors. Separate each selector with a comma. In the example below we have grouped all the header elements. All header elements will be displayed in green text color:
h1,h2,h3,h4,h5,h6With the class selector you can define different styles for the same type of HTML element.
Say that you would like to have two types of paragraphs in your document: one right-aligned paragraph, and one center-aligned paragraph. Here is how you can do it with styles:
p.right {text-align:right}You have to use the class attribute in your HTML document:
<p class="right">This paragraph will be right-aligned.</p>Note:To apply more than one class per given element, the syntax is:
<p class="center bold">This is a paragraph.</p>The paragraph above will be styled by the class "center" AND the class "bold".
You can also omit the tag name in the selector to define a style that will be used by all HTML elements that have a certain class. In the example below, all HTML elements with class="center" will be center-aligned:
.center {text-align:center}In the code below both the h1 element and the p element have class="center". This means that both elements will follow the rules in the ".center" selector:
<h1 class="center">This heading will be center-aligned</h1>DoNOT start a class name with a number! This is only supported in Internet Explorer.
You can also apply styles to HTML elements with particular attributes.
The style rule below will match all input elements that have a type attribute with a value of "text":
input[type="text"] {background-color:blue}You can also define styles for HTML elements with the id selector. The id selector is defined as a #.
The style rule below will match the element that has an id attribute with a value of "green":
#green {color:green}The style rule below will match the p element that has an id with a value of "para1":
p#para1DoNOT start an ID name with a number! It will not work in Mozilla/Firefox.
Comments are used to explain your code, and may help you when you edit the source code at a later date. A comment will be ignored by browsers. A CSS comment begins with "", like this:
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
CSS入门教程:网页首字下沉:first-letter版本:CSS2 兼容性:IE5.5语法:Selector:first-letter{sRules}说明:设
ccs的优点:css相对xpath语法比xpath简洁,定位速度比xpath快css的缺点:css不支持用逻辑运算符来定位,而xpath支持。css定位语法形式
作为CSS的一种扩展,Less不仅完全兼容CSS语法,而且连新增的特性也是使用CSS语法。这样的设计使得学习Less很轻松,而且你可以在任何时候回退到CSS。l
使用DIV+CSS实现下拉列表菜单DIV+CSS实现下拉列表菜单文章CSS教程DOM教程XML教程Flash教程参考XHTMLXMLCSSBlog全部网页技
三:CSS操作传统javascript对css的操作相当繁琐,比如css取它的background语法是document.getElementById("a")