我是一般的CSS和网页设计新手。 我创建了一个对应于页面上的3个“按钮”或“链接”的CSS精灵表。 这些按钮的默认位置为OFF,“当前”位置为ON。
页面加载时,所有3个按钮默认为OFF位置。 当您点击其中一个按钮时,该按钮会变为ON位置,让观众知道屏幕上加载的内容与他们按下的按钮相对应。 如果他们按下另一个按钮,则加载新信息,并且该按钮现在处于ON位置。 我希望其中的一个默认加载页面时的ON位置。 有人可以帮我用CSS做这个吗? 下面是我使用的CSS:让CSS Sprite“按钮”默认为ON页面加载状态
/*--- Set Sprite Image ---*/
#branch0,
#branch1,
#branch2
{background-image : url('images/sprite2.jpg');}
#branch_buttons #branch0{width:300px; height:65px; background-position:0 0;}
#branch_buttons #branch1{width:300px; height:65px; background-position:left -66px;}
#branch_buttons #branch2{width:300px; height:65px; background-position:left -131px;}
/* Hover/Focus State */
#branch_buttons #branch0:hover,#branch_buttons #branch0:focus, #branch_buttons #branch0.current{width:300px; height:65px; background-position:-301px top;}
#branch_buttons #branch1:hover,#branch_buttons #branch1:focus, #branch_buttons #branch1.current{width:300px; height:65px; background-position:-301px -66px;}
#branch_buttons #branch2:hover,#branch_buttons #branch2:focus, #branch_buttons #branch2.current{width:300px; height:65px; background-position:-301px -131px;}
/* Active */
#branch_buttons #branch0:active{background-position:left -195px;}
#branch_buttons #branch1:active{background-position:left -261px;}
#branch_buttons #branch2:active{background-position:left -326px;}`
我不完全知道你是问什么,你是否在每一页上表示页精灵被“上”?如果是这样,我会建议对与当前页面相关的图像进行硬编码(例如,将其中一个图像标记为“当前”类,并使用它来覆盖CSS)或使用Javascript。 – DBS
想象一下你有3个按钮。每个按钮都有一个UP和DOWN位置。默认情况下它们全部都是UP。当你点击一个按钮时,它会进入DOWN位置并保持这种状态直到你点击一个不同的按钮。当页面加载时,我只想让其中一个按钮默认为DOWN位置。原因在于每个按钮都会将数据加载到页面中心的iframe中,并且在页面加载时,默认情况下它会显示其中一个按钮的数据 - 这是我要默认为DOWN的那个。 – user3013140