英文教程:鼠标悬停(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./
网站设计
- 静宁会SEO的网站建设公司:全面提升您的网络影
- 提升在线业务的关键:选择最佳的丽水网站建设
- 浙江网站优化发展潜力如何
- 井研专业的网站建设公司:打造您的在线品牌
- 灵山SEO网站建设公司:提升您的在线业务表现
- 蒙城网站建设优化公司:提升您网站表现的理想
- 阳谷企业网站优化:提升线上业务力的关键
- 樟树专业的网站建设公司:打造您在线业务的坚
- 通河百度SEO排名的策略与技巧
- 重庆百度快照排名如何进行精准的客户引流
- 重庆百度快照排名
- 常宁便宜的建站公司:助您轻松打造在线业务
- 巫溪百度网站优化:提升网站曝光率与流量的关
- 湖北整站优化怎么做才能放大客户需求
- 闸北网站建设多少钱?全面解析与预算规划
- 辽宁企业网站优化怎么做电话营销