一篇极好的 CSS 教程

   这是我codeproject上面看到的极好的css教程,今日放上让大家看看,待我明日青岛归来翻译给大家看看。

CSS stands for Cascading Style Sheets. This is a simple styling language which allows attaching style to HTML elements. Every element type as well as every occurance of a specific element within that type can be declared an unique style, e.g. margins, positioning, color or size. So you might consider these style sheets as templates, very similar to templates in desktop publishing applications. For example:

     body { background-color: white; color: darkblue;font-size: 10pt;

                       font-family: Arial; margin-left: 10%}

Linking and Embedding

There are many ways to link style sheets to HTML, each carrying its own advantages and disadvantages. New HTML elements and attributes have been introduced to allow easy incorporation of style sheets into HTML documents.

External style sheets

An external style sheet can be linked with any number of HTML documents by using <link> that is placed in the document HEAD. The tag's various attributes indicate things about the style sheet - the rel attribute the type of link (a style sheet); the type attribute the type of style sheet (always text/css); and the href attribute the location of the style sheet. This is a very convenient way of formatting the entire site as well as restyling it by editing just one file. For example:

     <HTML><HEAD>

     <LINK rel="stylesheet" type="text/css" href="basic.css">

     </HEAD>

     <BODY>  ...  </BODY>

     </HTML>

Once you have linked the style sheet to your page, you then have to create the style sheet. For example:

     body { font-family: Verdana, Helvetica, Arial, sans-serif;

                       color: darkblue; background-color: #ffeeff}

If you saved the example above as a style sheet, then every page that links to it will have the specified styles. Files containing style information must have extension .css.

Embedded Style Sheets

If you have a single document that has a unique style, you can use an embedded style sheet. If the same style sheet is used in multiple documents, then an external style sheet would be more appropriate. A embedded style sheet is inside the HEAD element with the STYLE element and will apply to the entire document:

     <STYLE TYPE="text/css" MEDIA=screen>

     <!--

     body  { background: url(flower.gif) lightyellow; color: darkblue }

     .zn { margin-left: 8em; margin-right: 8em }

     -->

     </STYLE>

The required TYPE attribute is used to specify a media type, as is its function with the LINK element. You should write the style sheet as a HTML comment, that is, between <!-- and --> to hide the content in browsers without CSS support which would otherwise be displayed.

Importing Style Sheets

You can import a style sheet with CSS's @import statement:

     <STYLE TYPE="text/css" MEDIA="screen, projection">

     <!--

     @import url(http://www.tongchiu.com/gen.css);

     @import url(/product/file.css);

     table { background: yellow; color: #003366 }

     -->

     </STYLE>

The @import allows you to keep some things the same while having others different; and follows this syntax: @import url(gen.css);

Note: If more than one sheet is imported they will cascade in order they are imported - the last imported sheet will override the next last; the next last will override the second last, and so on. If the imported style is in conflict with the rules declared in the main sheet then it will be overridden.

Inline Style

Inline style is the style attached to one specific element. Any opening tag may take the style attribute:

     <P style="font-size: 10pt">.

To use inline style, one must declare a single style sheet language for the entire document using the Content-Style-Type HTTP header extension. With inlined CSS, an author must send text/css as the Content-Style-Type HTTP header or include the following tag in the HEAD:

     <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">

Syntax

Basic syntax as follows:

     selector { property: value }

That is a property (such as color) followed by a colon (:) and a value. A property is assigned to a selector in order to manipulate its style. Examples of properties include color, margin, and font. The value is an assignment that a property receives. Multiple style declarations for a single selector may be separated by a semicolon. The following example defines the color and font-size properties for H1 and P elements:

     <HEAD>

     <TITLE>CSS Example</TITLE>

     <STYLE TYPE="text/css">

     H1 { font-size: x-large; color: darkred }

     P { font-size: 12pt; color: darkblue }

     </STYLE>

     </HEAD>

You can use grouping of selectors and declarations to decrease repetitious statements within style sheets. For example:

     H1, H2, H3, H4 { color: #666666; font-family: Arial }

Selectors

Selectors are used to associate style declarations with an element or elements. This is done by placing the declarations within a block (enclosed in {}) and preceding it with a selector. For example:

     p {color: #008000}

     div {color: #cccccc; font-size: 14pt}

Tag selectors

You can take any opening HTML tag and use it as a selector:

     h3 {color: red}

Class selectors

These allow you to give elements a particular name. For example:

     <P class="zn"> .... </P>

In a style sheet, The syntax as the below:

     P.zn { color: blue }

Or like this:

     .zn { color: blue }

Pseudo-class selectors

Pseudo-classes can be assigned to the A element to display links, visited links and active links differently. The anchor element can give the pseudo-classes link, visited, or active. A visited link could be defined to render in a different color and even a different font size and style. The sample style sheet might look like this:

     A:link    { color: red }

     A:active  { color: blue; font-size: 150% }

     A:visited { color: green }

ID selectors

These selectors are very similar to classes except there can only be one element with a given ID in a document. An ID selector is assigned by using the indicator "#". For example:

     #abc { text-style: bold }

To use an ID selector:

     <P ID=abc>Welcome to my website</P>

Note: IDs like classes they should be in lowercase, may not start with a number or contain spaces. This selector type should only be used sparingly due to its inherent limitations.

Span

This element may be used as a selector in a style sheet, and it also accepts the STYLE, CLASS, and ID attributes. Some examples of SPAN follow:

     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">

     <HTML><HEAD><TITLE></TITLE>

     <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">

     <STYLE TYPE="text/css">

     <!--

     .zn { font-size: 28pt }

     -->

     </STYLE>

     </HEAD>

     <BODY>

     <P><SPAN CLASS=zn>These words could be big.</SPAN></p>

     <p><SPAN STYLE="font-family: Arial;font-size:12"> And these ones are different.</SPAN>.</P>

     </BODY></HTML>

Div

DIV (short for "division") is a block-level element that, in function, is similar to the SPAN. But DIV may contain paragraphs, headings, and tables. For example:

     <DIV CLASS=zn>

     <H1>Welcome</H1>

     <P>Hello World</P>

     <P>Welcome to my website!</P>

     </DIV>

Properties

Color

You can declare a color as the following example:

     P {color: red}

     H2 { color: #000080 }

     LI {color: rgb(12%, 51%, 62%)}

Background

Background-color This sets the background color of an element. For example:

     BODY { background-color: white }

     H1   { background-color: #000080 }

Note:
1. To help avoid conflicts with user style sheets, background-image should be specified whenever background-color is used. In most cases, background-image: none is suitable.
2. Netscape 4.* does not color in the background of block elements if they are given a background color that is different from BODY - it does not color in the spaces between words. To avoid this, explicitly set border: none

Background-image Specified with background-image. For example:

     BODY { background-image: url(/images/cloud.gif) }

     P { background-image: url(http://www.internetcollege.com/bg1.gif) }

Background-repeat This states the tiling of the background image. The possible values include: repeat | repeat-x | repeat-y | no-repeat.

The repeat-x value will repeat the image horizontally while the repeat-y value will repeat the image vertically. For example:

     BODY { background: white url(candybar.gif);

     background-repeat: repeat-x }

In the above example, the image will only be tiled horizontally. IE only draws repeat-x to the right, and repeat-y down, not left and right and up and down as it should do.

Background This allows one or more of the properties to be specified in the order color, image, repeat, attachment, position. For examples:

     BODY       { background: white url(http://www.internetcollege.com/bg1.gif) }

     BLOCKQUOTE { background: #6699ff }

     P          { background: url(image/line.gif) #e2e9ee fixed }

     TABLE      { background: #ffeeff url(house.gif) no-repeat top center }

Fonts

Font-family This allows a specific font to be used. For example:

     P { font-family: Times }

You may specify a couple fonts separated by comma. In case that if your preferred font is not available, your second choice is used. For example, font-family: Times, Arial. Note that any font name containing whitespace must be quoted, with either single or double quotes. For example:

     P { font-family: "New Times Roman", Times, serif    }

Font-size This can be specified as a length, or one of the following keywords: xx-small, x-small, small, medium (initial), large, x-large, xx-large. For example:

     H2 { font-size: large }

     P { font-size: 10pt }

     LI { font-size: 80% }

     Table { font-size: small}

Note: Internet Explorer 3 and Netscape 4.* treat all relative units and % as relative to the element default rather than as relative to the parent element.

Font-style This defines that the font be displayed in one of three ways: normal, italic or oblique (slanted). For example:

     P {font-style: italic}

Font-weight This is used for specifying the weight of the font that can be specified as normal (initial value), or bold. For example:

     P {font-weight: bold}

It can also be specified as an absolute number, being one of 100, 200, 300, 400 (the same as normal), 500, 600, 700 (the same as bold), 800, or 900, where 100 is the lightest and 900 the most bold. For example:

     H1 { font-weight: 800 }

Font This may be used as a shorthand for the various font properties. For example:

     P { font: italic bold 12pt/14pt Times, serif }

This specifies paragraphs with a bold and italic Times or serif font with a size of 12 points and a line height of 14 points.

Text

Text-align The value can be left (initial value), right, center, or justify (aligns to both margins). Text-align only applies to block elements and is inherited. For example:

     H1          { text-align: center }

     P.newspaper { text-align: justify }

Text-decoration This allows text to be decorated through one of five properties:

underline, overline, line-through, blink, or the default, none. For example:

     A:link, A:visited, A:active { text-decoration: none }

Text-transform allows text to be transformed by one of four properties: none (initial value), lowercase, uppercase, or capitalize (capitalize the first letter of every word). It applies to all elements and is inherited. For example:

     H1 { text-transform: uppercase }

     H2 { text-transform: capitalize }

Margin

This property sets the margin of an element by specifying a length or a percentage. Each element can have four margins - left, right, bottom and top. These are defined by the margin-left, margin-right, margin-top, margin-bottom properties. For example:

     P {margin-left: 20px}

The margins can be specified for all four sides at once with the margin shorthand. Margins can be negative, and initially margins are 0.

     P {margin: 10px 12px 6cm8pt}

This would give P a top margin of 10 pixel, a right margin of 12 pixel, a bottom margin of 6 pixel and a left margin of 8 pixel.

Rules

Inheritance Basically a selector which is nested within another selector will inherit the property values assigned to the outer selector. For example, a font defined for the BODY will also be applied to text in a paragraph.

! important A style can be designated as important by specifying ! important. A style that is designated as important will win out over contradictory styles of otherwise equal weight. A ! important statement like this:

     BODY { background: url(man.gif) white; background-repeat: repeat-x ! important }

The weight sort The weight sort sorts declarations according to their weight. Declarations can have normal weight or important weight. Declarations are made important by the addition of !important (or ! important). For example:

     P {font-size: 36pt !important} P {font-size: 16pt}

36 pt will result because that declaration has greater weight.

The order sort When two rules have the same weight, the last rule specified wins. Thus:

     P {color: red}

     P {color: green}

It would result in green.

Case sensitivity All CSS is case insensitive.

转载于:https://www.cnblogs.com/jessezhao/archive/2006/12/15/592813.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/412005.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python增强对比度_python增加图像对比度的方法

python增加图像对比度的方法来源&#xff1a;中文源码网 浏览&#xff1a; 次 日期&#xff1a;2019年11月5日【下载文档: python增加图像对比度的方法.txt 】(友情提示:右键点上行txt文档名->目标另存为)python增加图像对比度的方法本代码实现的是&#xff0c;在旋转…

因缺思厅的绕过

看一下页面源码&#xff0c;看到source.txt。所以进入同目录下的source.txt 代码审计下&#xff0c;并且百度了一些函数。过滤了很多关键字&#xff0c;因此常规的SQL注入没有头绪。想了挺久&#xff0c;因为要满足三个条件。1&#xff1a;不能输入过滤的关键字2&#xff1a;只…

[vue] vue能监听到数组变化的方法有哪些?为什么这些方法能监听到呢?

[vue] vue能监听到数组变化的方法有哪些&#xff1f;为什么这些方法能监听到呢&#xff1f; 你说的是vue内部的源码对Array数据的中转代理嘛 好像对push, shift等通用方法都做了代理吧! 因为它对中转的数据都做了监听个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知…

Python自制微信机器人:群发消息、自动接收好友

运营公众号也有半年了&#xff0c;今年5月份开始的&#xff0c;之前一直用一款windows工具来运营自动接受好友请求、群发文章、自动回复等操作&#xff0c;但颇有不便。 举几个场景&#xff1a; 突然在外面看到一篇文章很好&#xff0c;临时写了一篇&#xff0c;想群发一下。好…

61条面向对象设计的经验原则

你不必严格遵守这些原则&#xff0c;违背它们也不会被处以宗教刑罚。但你应当把这些原则看成警铃&#xff0c;若违背了其中的一条&#xff0c;那么警铃就会响起。 -----Arthur J.Riel (1)所有数据都应该隐藏在所在的类的内部。p13 (2)类的使用者必须依赖类的共有接口&#xff0…

gesturedetector.java_我的flutter代码中的GestureDetector不起作用

我正在玩flip_card package(这个软件包会创建一张卡片&#xff0c;当你点击它时&#xff0c;它会翻转卡片并显示卡片的正面或背面) . 我想要做的是&#xff0c;每次点击卡片时显示不同的图像&#xff0c;并且卡片翻转到正面 .为此&#xff0c;我将flip_card example修改为有状态…

[vue] vue打包成最终的文件有哪些?

[vue] vue打包成最终的文件有哪些&#xff1f; vendor.js, app.js, app.css, 1.xxx.js 2.xxx.js如果有设置到单独提取css的话 还有 1.xxx.css ......个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 …

IronPython资料

Python文档&#xff1a;http://blog.csdn.net/ccat/category/9998.aspx A bit more on IronPython&#xff1a;http://blogs.msdn.com/aaronmar/archive/2006/02/16/a-bit-more-on-ironpython.aspx Python 2.5 中文Tutorial http://wiki.woodpecker.org.cn/moin/March_Liu/PyT…

记一次webpack4+react+antd项目优化打包文件体积的过程

背景 最近自己整了一个基于webpack4和react开发的博客demo项目&#xff0c;一路整下来磕磕碰碰但也实现了功能&#xff0c;就准备发到阿里云上面去看看&#xff0c;借用了同事的阿里云小水管服务器&#xff0c;配置完成之后首页加载花了十几秒&#xff0c;打开控制台network查看…

java hashedmap_Java基础 - Map接口的实现类 : HashedMap / LinkedHashMap /TreeMap 的构造/修改/遍历/ 集合视图方法/双向迭代输出...

import java.util.*;/**一:Collection接口的* Map接口: HashMap(主要实现类) : HashedMap / LinkedHashMap /TreeMap* Map接口:对, 重复的键会进行值得覆盖 ,输出顺序和放入顺序是不一定可以保持顺序的!* 修改查询操作: 1.put(key, value), 2.remove(key) 3.putAll(其他map), 复…

[vue] vue如何优化首页的加载速度?

[vue] vue如何优化首页的加载速度&#xff1f; 补充下2楼&#xff1a; ssr直出&#xff0c; webpack压缩HTML/CSS/JS&#xff0c; 首屏css单独提取内联&#xff0c; 关键资源Proload&#xff0c; 图片&#xff1a;不缩放&#xff0c;使用webp、小图片base64&#xff0c;iconfo…

25岁了

忙了一天&#xff0c;在下午收到kk的email才想起来今天是自己的生日&#xff0c;应该请大家吃蛋糕的。想想这一年过得真快&#xff0c;2006这几个数字我还没有写惯&#xff0c;就要开始写2007了。时光如梭&#xff0c;一点都不假。 25岁啰&#xff0c;转眼间自己怎么就这把年纪…

java同时满足语句_关于控制语句,下列哪些说法符合《阿里巴巴Java开发手册》:...

案例分析一&#xff1a;假定CPU的主频是500MHz。硬盘采用DMA方式进行数据传送&#xff0c;其数据传输率为4MB/s, 每次DMA传输的数据量为8KB, 要求没有任何数据传输被错过。如果CPU在DMA初始化设置和启动硬盘操作等方面用了1000个时钟周期&#xff0c;并且在DMA传送完成后的中断…

【java小知识】FileReader读取文件出现乱码的解决办法

转1&#xff1a;https://blog.csdn.net/a532672728/article/details/79432619 转2&#xff1a;https://www.cnblogs.com/qq78292959/p/3794993.html 小结&#xff1a; 1&#xff09;注意txt文件&#xff0c;保存的格式&#xff0c;Windows的记事本默认保存的ANSI&#xff0c;我…

[vue] 说说你对vue组件的设计原则的理解

[vue] 说说你对vue组件的设计原则的理解 第一: 容错处理, 这个要做好, 极端场景要考虑到, 不能我传错了一个参数你就原地爆炸 第二: 缺省值(默认值)要有, 一般把应用较多的设为缺省值 第三: 颗粒化, 把组件拆分出来. 第四: 一切皆可配置, 如有必要, 组件里面使用中文标点符号,…

最高法院明确反向工程合法 腾讯诉PICA恐生变

原文: http://it.sohu.com/20070118/n247688457.shtml通过自行开发研制或者反向工程等方式获得的商业秘密&#xff0c;将不被认定为反不正当竞争法有关条款规定的侵犯商业秘密行为。 昨天&#xff0c;最高人民法院发布的第一个涉及不正当竞争案件审理的司法解释明确了以上规则。…

[19/03/16-星期六] 常用类_Date时间类DateFormat类

一、Date时间类 计算机中 以1970 年 1 月 1 日 00:00:00定为基准时间&#xff0c;每个度量单位是毫秒(1秒的千分之一) 用ong类型的变量来表示时间&#xff0c;如当前时刻数值&#xff1a;long now new System.currentTimeMillis(); 【常用方法】 1. Date() 分配一个Date对象&a…

php array第一张图片_PHP array_udiff() 函数

PHP array_udiff() 函数实例比较两个数组的键值(使用用户自定义函数比较键值)&#xff0c;并返回差集&#xff1a;<?php function myfunction($a,$b){if ($a$b){return 0;}return ($a>$b)?1:-1;}$a1array("a">"red","b">"gre…

在FF与IE中使用数据岛

在FF与IE中使用数据岛 <div style"display:none;"><xml id"XMLNode"><xmp><Root>...<III><![CDATA[***]]></III>...</Root></xmp></xml></div><script language"javascript>…

[vue] 怎么缓存当前打开的路由组件,缓存后想更新当前组件怎么办呢?

[vue] 怎么缓存当前打开的路由组件&#xff0c;缓存后想更新当前组件怎么办呢&#xff1f; 可以在路由meta中加入参数, 对打开的路由进行keep-alive的判断, 通过钩子active等个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很…