📄 css_howto.asp@output=print
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS How to</title>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />
<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</head>
<body>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
<h1>CSS How To...</h1>
<a href="css_syntax.asp"><img border="0" src="../images/btn_previous.gif" width="100" height="20" alt="Previous" /></a>
<a href="css_background.asp"><img border="0" src="../images/btn_next.gif" width="100" height="20" alt="Next" /></a>
<hr />
<h2>Examples</h2>
<ul>
<li>Look at <a target="_blank" href="showit.asp@filename=ex1">Example 1</a></li>
<li>Look at <a target="_blank" href="showit.asp@filename=ex2">Example 2</a></li>
</ul>
<hr />
<h2>How to Insert a Style Sheet</h2>
<p>When a browser reads a style sheet, it will format the document according to it.
There are three ways of inserting a style sheet:
</p>
<h3>External Style Sheet</h3>
<p>An external style sheet is ideal when the style is applied to many pages. With an
external style sheet, you can change the look of an entire Web site by changing one file.
Each page must link to the style sheet using the <link> tag. The
<link> tag goes inside the head section:
</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
<pre><head>
<link rel="stylesheet" type="text/css"
href="mystyle.css" />
</head></pre>
</td></tr></table>
<p>The browser will read the style definitions from the file mystyle.css, and format
the
document according to it.
</p>
<p>An external style sheet can be written in any text editor. The file should not contain any
html tags. Your style sheet should be saved with a .css extension. An example of
a
style sheet file is shown below:
</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
<pre>hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}</pre>
</td></tr></table>
<br />
<table class="tip" width="100%" border="0">
<tr>
<td>
<p><img border="0" src="../images/lamp.gif" alt="Remark" />
Do <b>NOT</b> leave spaces between the property value and the units! If you
use "margin-left: 20 px" instead of "margin-left: 20px" it will only work
properly in IE6 but it will not work in Mozilla/Firefox or Netscape.</p>
</td>
</tr>
</table>
<h3>Internal Style Sheet</h3>
<p>An internal style sheet should be used when a single document has a unique style.
You define internal styles in the head section by using the <style> tag, like this:
</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
<pre><head>
<style type="text/css">
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
</style>
</head></pre>
</td></tr></table>
<p>The browser will now read the style definitions, and format
the
document according to it.
</p>
<p><b>Note:</b> A browser normally ignores unknown tags. This means that an old
browser that does not support styles, will ignore the <style> tag, but the content
of the <style>
tag will be displayed on the page. It is
possible to prevent an old browser from displaying the content by hiding it in the HTML
comment element:
</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
<pre><head>
<style type="text/css">
<!--
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
-->
</style>
</head></pre>
</td></tr></table>
<h3>Inline Styles</h3>
<p>An inline style loses many of the advantages of style sheets by mixing
content with presentation. Use this method sparingly, such as when a style is to
be applied to a single occurrence of an element.
</p>
<p>To use inline styles you use the style attribute in the relevant tag. The
style attribute can contain any CSS property. The example shows how to change
the color and the left margin of a paragraph:
</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
<pre><p style="color: sienna; margin-left: 20px">
This is a paragraph
</p></pre>
</td></tr></table>
<br />
<hr />
<h2>Multiple Style Sheets</h2>
<p>If some properties have been set for the same selector in different style sheets,
the values will be inherited from the more specific style sheet. </p>
<p> For example, an external style sheet has these properties for the h3 selector:</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
<pre>h3
{
color: red;
text-align: left;
font-size: 8pt
}</pre>
</td></tr></table>
<p>And an internal style sheet has these properties for the h3 selector:</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
<pre>h3
{
text-align: right;
font-size: 20pt
}</pre>
</td></tr></table>
<p>If the page with the internal style sheet also links to the
external style sheet the properties for h3 will be:</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
<pre>color: red;
text-align: right;
font-size: 20pt</pre>
</td></tr></table>
<p>The color is inherited from the external style sheet and
the text-alignment and the font-size is replaced by the internal style sheet.</p>
<hr />
<a href="css_syntax.asp"><img border="0" src="../images/btn_previous.gif" width="100" height="20" alt="Previous" /></a>
<a href="css_background.asp"><img border="0" src="../images/btn_next.gif" width="100" height="20" alt="Next" /></a>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -