如何引用css外部样式来改变html中的P的颜色

html-css012

如何引用css外部样式来改变html中的P的颜色,第1张

一个外部的样式表可以通过HTML的LINK元素连接到HTML文档中:

<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen<

<LINK REL=StyleSheet HREF="color-8b.css" TYPE="text/css" TITLE="8-bit Color Style" MEDIA="screen, print"<

<LINK REL="Alternate StyleSheet" HREF="color-24b.css" TYPE="text/css" TITLE="24-bit Color Style" MEDIA="screen, print"<

<LINK REL=StyleSheet HREF="aural.css" TYPE="text/css" MEDIA=aural<

<LINK<标记是放置在文档的HEAD部分。可选的TYPE属性用于指定媒体类型--text/css是一个层叠样式表--允许浏览器忽略它们不支持的样式表类型。为CSS文件配置服务器而将text/css当作Content-type内容发送出去也是一个好注意。

外部样式表不能含有任何像<HEAD<或<STYLE<这样的HTML的标记。样式表仅仅由样式规则或声明组成。一个单独由

P { margin: 2em }

组成的文件就可以用作外部样式表了。

<LINK<标记也有一个可选的MEDIA属性,用于指定样式表被接受的介质或媒体。允许的值有

screen?(缺省值),提交到计算机屏幕;

print, 输出到打印机;

projection,提交到投影机;

aural,扬声器;

braille,提交到凸字触觉感知设备;

tty,电传打字机 (使用固定的字体);

tv,电视机;

all,所有输出设备。

多样的媒体通过用逗号隔开的列表或值all指定。

Netscape Navigator 4.x?错误地忽略除了screen值外的任何使用MEDIA值声明的连接或嵌入样式表。例如,MEDIA="screen,projection"会令到样式表被Navigator 4.x忽略,尽管展示的设备是计算机的屏幕。Navigator 4.x?也忽略使用MEDIA=all声明的样式表。

REL属性用于定义连接的文件和HTML文档之间的关系。REL=StyleSheet指定一个固定或首选的样式而REL="Alternate StyleSheet"定义一个交互样式。固定样式在样式表激活时总被应用。缺少的TITLE属性,就像例子中的第一个<LINK<标记,定义一个固定样式。

一个首选样式会自动被应用,就像例子中的第二个<LINK<标记。REL=StyleSheet和一个TITLE属性的组合指定一个首选的样式。网页制作者不能指定多于一个的首选样式。

交互样式通过REL="Alternate StyleSheet"指出。例子中的第三个<LINK<标记定义一个交互样式,用户可以选择用来代替首选样式表。

注意现在的浏览器一般都缺乏选择交互样式的能力。

单一的样式也可以通过多个样式表给出

<LINK REL=StyleSheet HREF="basics.css" TITLE="Contemporary"<

<LINK REL=StyleSheet HREF="tables.css" TITLE="Contemporary"<

<LINK REL=StyleSheet HREF="forms.css" TITLE="Contemporary"<

在这个例子中,三个样式表组合成一个"Contemporary"样式,作为一个首选样式表被应用。要组合多个样式表成一个单一样式,必须在每个样式表中使用相同TITLE。

当样式被应用到很多的网页时,一个外部样式表是理想的。网页制作者使用外部样式表可以改变整个网站的外观而仅仅通过改变一个文件。同样的,大多数浏览器会保存外部样式表在缓冲区,从而如果样式表在缓冲区就避免了在展示网页时的延迟。

Microsoft Internet Explorer?3 for Windows 95/NT4并不支持来自连接的样式表中的BODY?背景图象或颜色。如果考虑到这个错误,网页制作者不妨提供另外的包括一个背景图象或颜色的结构,例如嵌入或内联样式,或使用BODY元素的BACKGROUND属性。

How to Build a Website Step 1 — Hosting:Hosting is where you put your website and all the web pages. While it’s possible to build a website on your personal computer and never move it online, it’s pointless. No one but you will ever see it. So the first thing you’ll want to do is find a web hosting provider.There are several types of web hosting options you can choose from:Free Web hostsStandard web hostingDedicated, Virtual, and Shared HostingColocationMost people gravitate to free web hosting without too much thought, but there can be drawbacks to free hosting. You don’t always get as much space, you might be required to run their ads on your site, or there may bebandwidth limits. There are sometimes limitations on what can be put on a free hosting provider—for example, some don't allow ecommerce or gambling or other types of content. Some free hosting providers tack on charges like maintenance and renewal fees on their “free” accounts. Be sure to read all the fine print before you put your website on a free web host. I recommend using free hosting providers for testing web pages and for personal pages, but not for websites you hope to make money from.Find a Web Hosting Provider — links to other sites for help finding a good hostWeb Hosting Reviews — find out what other users thinkWeb Hosting Profiles — overviews of several hosting providersHow to Build a Website Step 2 — Do You Need a Domain Name?:A domain name is a friendly URL people can type into their browser to get to your website. You don’t need a domain name to put up a website. You can put up a site on free hosting or even paid hosting plans without a domain name. A domain name provides extra branding for your site and makes it easier for people to remember the URL. But domain names cost money, typically between $8 and $35 a year.Get a URL that People Can FindHow to Buy a Domain Name with Network SolutionsHow to Register a Website Domain — VideoHow to Build a Website Step 3 — Plan Your Website:Once you’ve gotten a domain and decided on your URL, you can plan your site. You need to decide:Type of site — Most websites are either news/information, product, or reference sites. As such they each have a slightly different focus.Navigation — The navigation affects the information architecture of your site.Content — Content is the actual pages you will build.Play the Web Page Types game. If you can recognize page types, you’ll be able to recognize what types of pages you need for your site.How to Build a Website Step 4 — Build Your Website Page by Page:Building a website requires you to work on one page at a time. To build your site you should be familiar with:Design Basics — The elements of good design and and how to use it on websites.Learning HTML — HyperText Markup Language or HTML is the building block of a web page. While it’s not absolutely required, you’ll do better if you learn HTML than if you don’t.Learning CSS — Cascading Style Sheets or CSS is the building block of how pages look. And learning CSS will make it easier for you to change your site’s look when you need to.Web Page Editors — Finding the perfect editor for your needs will help you learn design, HTML, and CSS.How to Build a Website Step 5 — Publish Your Website:Publishing your website is a matter of getting the pages you created in step 4 up to the hosting provider you set up in step 1. You can do this with either the tools that come with your hosting service or with FTP (File Transfer Protocol) clients. Knowing which you can use depends upon your hosting provider. Contact them if you are not sure.How to UploadBest FTP Clients for WindowsBest FTP Clients for MacintoshHow to Build a Website Step 6 — Promote Your Website:The easiest way to promote your website is through search engine optimization or SEO. You build your web content so that it ranks well in search engines. This can be very difficult, but it is inexpensive and can have good results if you work at it.Other ways to promote your site include: word of mouth, email, and advertising. You should include your URL on all professional correspondence and whenever it makes sense in personal messages. I put my URL in my email signature along with my email address.Improve Your Page Views — With More HitsBoosting Your HitsCreate a Great Home PageWeb Marketing ArticlesHow to Build a Website Step 7 — Maintain Your Website:Maintenance can be the most boring part of website design, but in order to keep your site going well and looking good, you need to do it. Testing your site as you’re building it and then after it’s been live for a while is important. New devices come on the market all the time, and the browser makers are always improving their browsers. You should also work on content development on a regular basis. The more content you create and add to your site the more visitors you will get.How to Preview Your Web PagesSolving Problems in Web DesignHow to Use BrowserCam to Review Your Website6 Ways to Get UnblockedWhat to Write AboutWriting Web Pages that Meet Your Customers’ Goals