英文教程:鼠标悬停(hover)效果

网站建设 2023-01-28 21:38www.1681989.com免费网站

前面一个CSS教程介绍了在网页中利用CSS建立立体表格效果,今天给大家来一篇很不错的鼠标悬停效果,也是用CSS实现的。
  这是一个很棒的鼠标悬停(hover)效果。从国外的网站上看到了,网络推广网站推广转载过来。没有作任何翻译与编辑,大家可以偿试阅读英文教程,加油!
  注意此悬停效果在IE6中无效
  实例预览地址http://.prukc./
  IwouldliketosharesomesightonapieceofCSSI’veusedforthehomepageforawebsiteawhileagothatI’vebuilttogetherwithRogerJohansson.
TheHTMLmarkup
  Let’stakealookfirstattheHTMLmarkupforthis.Firstweneedtothkaboutthestructureofthispieceofcontent.HowshoulditbestructuredwithCSSdisabledandstillmakesensefortheuser.Ithkabulletlistmakessense.Wesumupthe4differentwaystofdyourKansasCityHomesforSale.Thisisthe(X)HTMLmarkup:


HTML <h2>4differentwaystofdyourKansasCityHomesforSale</h2>
<ulid="differences">
<liid="diff-1"><h3><em>1</em><ahref="benefits.html">SeeallMLShomeslikeansider—jous</a></h3><div><p><ahref="benefits.html">Jous</a>andsee<strong>2,207</strong>additionalhomes,e-mailupdates,andfreecustomwebsite.</p></div></li>
<liid="diff-2"><h3><em>2</em>Whatismyhouseworth?</h3><div><p>Fdthe<ahref="/"title="empty">valueofyourhome</a>fromanyofouragentswithourpetitivemarketanalysis.</p></div></li>
<liid="diff-3"><h3><em>3</em>Google™searchKansasCityareahomesMLS</h3><div><p><ahref="/"title="empty">SearchvirtuallyallMLShomes</a>thegreaterKansasCityareabyusgGoogle™.</p></div></li>
<liid="diff-4"><h3><em>4</em>MapKansasCityrealestateGoogle™maps</h3><div><p><ahref="cma.html"title="empty">Seethelocation</a>ofallKansasCityrealestatewithGoogle™maps—maporsatelliteviews.</p></div></li>
</ul>
  IfyoulookatethepagewithCSSdisabled,Ithkthismarkupiswellstructuredandit’sperfecttobuildthenecessaryCSStoachievethestyleIhavemd.
Thebackgroundimages
  IfyoulookatthefalpageandtheeffectIwanttoachievewiththetabs,youknowthatIneedtocreatebackgroundimagesforthisthatareabletogrowiftheuserenlargesthetext.Hereishowtheylook:
  diff-tabs--wide.gif

  diff-tabs-bottom-wide.gif

  You'llnoticethatboththehoverbackgroundandthedefaultbackgroundaresavedas1giffile.Thiswaythehovereffectwillgosmoothwithoutteruption.Theentireimageisloadedandthebrowserdoesn’thavetoloadthehoverimagesonthemomenttheuserhoversthebox.Tobesuretheboxcangrowwesavethebottompartoftheboxandthepartofthebox,makgitlongenoughtobesuretherewillbenogaps(tillacertaenlargement).
TheCSSstyles
Theunorderedlist“differences”
  ThisistheCSSfortheliststartgwiththeunorderedlistofthe4boxes.TopreventthemargstocollapseI’veaddedfloat:left. #differences{
marg:0.5em01.5em0;
paddg:0;
list-style:none;
width:100%;
float:left;
}
Thelielementstyleslooklikethis:
#differencesli{
marg:018px00;
paddg:0;
float:left;
background:url(../images/diff-tabs--wide.gif)no-repeat00;
}
  Iaddaright-margof18pxtocreateagutterbetweeneachbox.Thelastboxtherowdoesn’tneedthismarg.Eachlielementhasanid.Theidforthelastoneis#diff-4.SoIaddthisCSSstyle:
#differencesli#diff-4{
marg-right:0;
}
Makgsurethetabbedboxescangrow
  Asyou’venoticed,we’velkedthepartofthebackgroundimage(thetabshape)tothelielementviaCSS.Tomakesurethetabbedboxescangrowiftheuserenlargeshistext,weneedtoaddanextradiveachlielement.ThiswaywecanlkthebottompartoftheimagetothisdivviaCSS:
#differencesdiv{
font-size:0.94em;
paddg:6px;
background:url(../images/diff-tabs-bottom-wide.gif)no-repeat0100%;
}
  WithCSS3wedon’thavetogothroughthishassleofaddgextradivs,becauseCSS3allowsformultiplebackgroundimagesononeelement.ThisismyfavoriteCSS3feature:)
Creatgthehovereffect
  I’veusedbackgroundpositiongtocreatethehovereffectonthelielementusgthe:hoverpseudo-class.TheCSSlookslikethis:
#differencesli:hover{
background-position:-156px0;
}
#differencesli:hoverdiv{
background-position:-156px100%;
}
  Thexcoordateissetto-156px.Thiswaythepkorangepartofthebackgroundimagewillbeshown.Thefirststylerepresentsthepartofthetabbedboxandthe2ndohebottompart.RememberIhadtoaddanextradivtomakesuretheboxcangrow(tillacertaenlargement).
Thepageusesadynamicresolutiondependentlayout
  Notsureifyou’venoticedornot,butifyouresizeyourbrowserwdowtolessthen750pixelswide,thepagewilladjustitslayout.ThisisdoneusgajavascriptcreatedbyKevHaleofParticleTreebationwithCSS.I’musganextraCSSstylesheetthatisappliedifthebrowserwdowisresizedtolessthen750pixels.Bydefaultthepage/siteusesthewiderversion,whichisaimedtoascreenresolutionof1024x768.About90%ofthevisitorsofthePrudentialKansasCityvisitorsareusgascreenresolutionofatleast1024x768pixels.
  HopefullysomeofyouhavelearnedfromthisarticleandarespiredtouseCSSacreativewaywithoutoverlookgtheaessibilitypartofitandkeepgtherightstructuremdforthe(X)HTML.I’mstillcreatgnewtemplatesforthiswebsiteonanoasionalbasis.Thiswebsiteisratherbigandnewfeaturesareconstantlyaddedbytheclientandthedeveloper.
  Ohandlet’snotfettomentionthatitisalwaysgreattoworktogetherwithRoger.He’spickywhathedoes,butthat’swhatIloveaboutworkgwithhim,andofcourseIalwayschallengehimwithmydesigns:)
  Previewurl:http://.prukc./

Copyright © 2016-2025 www.1681989.com 推火网 版权所有 Power by