再见西城 发表于 2015-1-15 23:35:50

DIV教程之英文教程:用CSS把持和操纵BODY标志

不管你用什么工具软件制作网页,都有在有意无意地使用CSS。用好CSS能使你的网页更加简炼,同样内容的网页,有的人做出来有几十KB,而高手做出来只有十几KB。
网页制造POLUOLUO文章简介:利用CSS利用你的body元素.
Let’ssayyouwanttochangethecolorofyourlinksonjustyourcontactpagetored.Theyareblueoneveryotherpage,butitjustmakessenseforthemtoberedonyourcontactpage(forsomereason).Thereareacouplewaysyoucouldgoaboutthis.


[*]Youcoulddeclareaseparatestylesheetforyourcontactpage.Thisisn’tideal,becauseit’sredundant.Ifyoumakeanyotherchanges,you’llalwayshavetomakethembothonthemainstylesheetandthecontactpagestylesheet.
[*]Youcouldgiveallthoselinksauniqueclassonthatpage.Thisisn’tideal,becauseitisn’tverysemanticandit’salsoredundant.Whyapplyaclasstoeverysinglelinkonthepagewhentheyreallyaren’tanydifferentfromlinkselsewhereonthesite,contextuallyspeaking?
[*]ThebestsolutionistogiveyourthebodyauniqueID.Thissolvestheproblemperfectly.YoucanusethesamestylesheetandtargetjustthelinksyouwanttowithasingleCSSselector.

Howit’sdone

Simple,literallyjustapplytheIDtothebodytag:
...</head><bodyid="contact-page">...Nowforourexampleofmakingalllinksonthecontactpageredinsteadofblue,justusesomeCSSlikethis:
a{color:blue;}#contact-pagea{color:red;}
Howaboutamorepracticalexample?

Yougotit.Oneofthemostusefulimplementationsofthistechniqueiswithinnavigation.Takealookatthissamplenavigation:

Seehowtheforumstabisthe“active”tab?Certainlythat’sjustaslightchangeinCSS,probablyjustashiftinthepositionofabackgroundimage.PerhapstheXHTMLlookssomethinglikethis:
...<li><ahref="/fieldtips">Fieldtips</a></li><liclass="active"><ahref="/forums">Forums</a></li>...The“active”classappliedtothelistitemiswhatshiftsthebackgroundimage.That’lldothetrick,butwhataboutwhenwemovetotheFieldTipspage?WewillhavetoremovetheactiveclassfromtheforumstabandapplyittothetheFieldTipstab.That’snotveryconvenient.Thatmeansthecodeforthenavigationblockisuniqueoneverysinglepageofthesite.Solet’ssaydowntheroadwewanttoaddaContacttab,we’llhavetoalterthecodeoneverysinglepage.Nofun.
Let’sdothisalittlesmarter.Firstwedon’twanttoincludethenavigationblockofcodeoneverypage,wewanttoincludeit,probablywithasimplePHPincludelikethis:
<?phpinclude_once("nav.html");?>
Butthenhowdoweapplythe“active”classtothecurrentnavigationlistelement?

ThisiswhereapplywhatwejustlearnedaboutgivinguniqueID’stothebody!Insteadofapplyingaclasstoonlytheactivelistelement,let’sapplyauniqueclasstoeachseparatelistitemaswellasgiveourbodyanuniqueID.
...</head><bodyid="field-tips">...<liclass="fieldtips"><ahref="/fieldtips">Fieldtips</a></li><liclass="forums"><ahref="/forums">Forums</a></li>...NowwecantargetspecificelementsinthenavigationwithsomecleverCSS:
#field-tipsli.fieldtips,#forumsli.forums{background-position:bottom;}Thismeansthatthecodeforthenavigationblockcanstaythesameoneverypage,yetonlythenavigationelementnativetothatpagewillbeaffectedbythisCSSand“flip”totheactivestate.

Let’sgetevenmoredynamic

ReaderBrianleftanawesomecommentonhowyoucanusePHPtoapplytheuniqueIDtotothebodyelement:
<bodyid="<?=basename(Let’ssayyouwanttochangethecolorofyourlinksonjustyourcontactpagetored.Theyareblueoneveryotherpage,butitjustmakessenseforthemtoberedonyourcontactpage(forsomereason).Thereareacouplewaysyoucouldgoaboutthis.


[*]Youcoulddeclareaseparatestylesheetforyourcontactpage.Thisisn’tideal,becauseit’sredundant.Ifyoumakeanyotherchanges,you’llalwayshavetomakethembothonthemainstylesheetandthecontactpagestylesheet.
[*]Youcouldgiveallthoselinksauniqueclassonthatpage.Thisisn’tideal,becauseitisn’tverysemanticandit’salsoredundant.Whyapplyaclasstoeverysinglelinkonthepagewhentheyreallyaren’tanydifferentfromlinkselsewhereonthesite,contextuallyspeaking?
[*]ThebestsolutionistogiveyourthebodyauniqueID.Thissolvestheproblemperfectly.YoucanusethesamestylesheetandtargetjustthelinksyouwanttowithasingleCSSselector.

Howit’sdone

Simple,literallyjustapplytheIDtothebodytag:
...</head><bodyid="contact-page">...Nowforourexampleofmakingalllinksonthecontactpageredinsteadofblue,justusesomeCSSlikethis:
a{color:blue;}#contact-pagea{color:red;}
Howaboutamorepracticalexample?

Yougotit.Oneofthemostusefulimplementationsofthistechniqueiswithinnavigation.Takealookatthissamplenavigation:

Seehowtheforumstabisthe“active”tab?Certainlythat’sjustaslightchangeinCSS,probablyjustashiftinthepositionofabackgroundimage.PerhapstheXHTMLlookssomethinglikethis:
...<li><ahref="/fieldtips">Fieldtips</a></li><liclass="active"><ahref="/forums">Forums</a></li>...The“active”classappliedtothelistitemiswhatshiftsthebackgroundimage.That’lldothetrick,butwhataboutwhenwemovetotheFieldTipspage?WewillhavetoremovetheactiveclassfromtheforumstabandapplyittothetheFieldTipstab.That’snotveryconvenient.Thatmeansthecodeforthenavigationblockisuniqueoneverysinglepageofthesite.Solet’ssaydowntheroadwewanttoaddaContacttab,we’llhavetoalterthecodeoneverysinglepage.Nofun.
Let’sdothisalittlesmarter.Firstwedon’twanttoincludethenavigationblockofcodeoneverypage,wewanttoincludeit,probablywithasimplePHPincludelikethis:
<?phpinclude_once("nav.html");?>
Butthenhowdoweapplythe“active”classtothecurrentnavigationlistelement?

ThisiswhereapplywhatwejustlearnedaboutgivinguniqueID’stothebody!Insteadofapplyingaclasstoonlytheactivelistelement,let’sapplyauniqueclasstoeachseparatelistitemaswellasgiveourbodyanuniqueID.
...</head><bodyid="field-tips">...<liclass="fieldtips"><ahref="/fieldtips">Fieldtips</a></li><liclass="forums"><ahref="/forums">Forums</a></li>...NowwecantargetspecificelementsinthenavigationwithsomecleverCSS:
#field-tipsli.fieldtips,#forumsli.forums{background-position:bottom;}Thismeansthatthecodeforthenavigationblockcanstaythesameoneverypage,yetonlythenavigationelementnativetothatpagewillbeaffectedbythisCSSand“flip”totheactivestate.

Let’sgetevenmoredynamic

ReaderBrianleftanawesomecommentonhowyoucanusePHPtoapplytheuniqueIDtotothebodyelement:
a{color:blue;}#contact-pagea{color:red;}2ThiswillreturnthenameofthePHPfilebeingexecutedastheID(e.g.bodyid=”index.php”).Toleaveoffthe.phppart,justremovethe“.php”part.
SERVER,".php")?>">ThiswillreturnthenameofthePHPfilebeingexecutedastheID(e.g.bodyid=”index.php”).Toleaveoffthe.phppart,justremovethe“.php”part.

提高易用性。使用CSS可以结构化HTML,例如:标签只用来控制段落,heading标签只用来控制标题,table标签只用来表现格式化的数据等等。

小妖女 发表于 2015-1-17 23:29:19

dreamweaver8中文版下载(dw)对专业网页图像设计的FIREWORKS,三者被MACROMEDIA公司称为DREAMTEAM(梦之队)。

简单生活 发表于 2015-1-24 14:48:50

还可以在Dreamweaver常用工具中选择超级链接,完成相应的填写即可。

第二个灵魂 发表于 2015-2-1 18:08:34

不管老师做怎样的解释,而我却对它感到很是吃力,诸如里面有许多不知道的功能。

分手快乐 发表于 2015-2-7 14:42:34

帧(frames)和表格的制作速度快的令您无法想像。进阶表格编辑功能使您简单的选择单格、行、栏或作未连续之选取。

仓酷云 发表于 2015-2-22 19:29:39

Dreamweaver8中文版(dw)是由Macromedia公司开发的一款所见即所得的网页编辑器。和二维动画设计软件FLASH,专业网页图像设计软件FIREWORKS,并称为“网页三剑客”。

不帅 发表于 2015-3-7 03:10:26

直接用代码建立链接,如:可以直接输入 <a herf = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"red.html\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\">红色的网页 12、插入标签法建立链接,可以再选中文字后在代码中插入html标签,页元素<a>.也可以按ctrl+t进入html标签插入方法之后输入代码即可。

活着的死人 发表于 2015-3-14 11:18:48

每天上网看着那样多的网页,于是我才下定决心选择了网页制作这一门课程,目的就是希望以后能够做出一个完美的网页来。

柔情似水 发表于 2015-3-21 06:01:16

Adobe Dreamweaver(前称Macromedia Dreamweaver)是Adobe公司的著名网站开发工具。
页: [1]
查看完整版本: DIV教程之英文教程:用CSS把持和操纵BODY标志