步骤8
--------
添加:active和:focus状态
IE使用:active伪类但其他所有浏览器使用:focus伪类来作鼠标单击的样式。
和:hover样式我们扩大图片区域一样,这次,要扩大到320 x 240px并减小padding到上下48px左右64px,总共是448 x 336px.
每个超链接的单击状态必须移动到更低的z-index,所以,它应该低于:hover状态。这段允许所有链接被激活并且允许下一个:hover显示在被“单击”的图片之上。
/* Resizing the link when 'clicked' */ #gallery a:active, #gallery a:focus { background:transparent; width:320px; height:240px; padding:48px 64px; position:absolute; left:0; top:0; z-index:10; }
background:transparent; 在ie中用来激活:active样式width:320px; 设置超链接宽度为320px(和显示区域一样宽)height:240px; 设置超链接高度为240px (和显示区域一样高)padding:48px 64px; 设置超链接总体大小为 448 x 336 pxposition:absolute; 允许我们绝对定位我们的超链接left:0; 移动超链接到<ul>的左边top:0; 移动超链接到<ul>的上边z-index:10; 让这个超链接在:hover底下(一个更低的层)
步骤8a示例:
运行代码框 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
我们现在可以设置被“单击”的图片为原始大小 320 x 240px。
/* Resizing the image when 'clicked' */ #gallery a:active img, #gallery a:focus img { background:#eee; position:relative; width:320px; height:240px; border:0; z-index:10; }
background:#eee; 在ie中被用来激活:active状态position:relative; 设置这个,让z-index能够被指定width:320px; 设置图片宽度为320px(和显示区域一样宽)height:240px; 设置图片高度为240px(和显示区域一样高)border:0; 移除1px的框z-index:10; 移动图片到和它所在超链接一样的层。
步骤8b示例:
运行代码框 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
Users of Internet Explorer may now notice a bug in this arrangement whereby the full sized clicked image does not display until the mouse is moved onto another image. This is a very curious bug and I'm not sure why it happens intermittently.Fortunately,there's and easy cure (hack) that can be applied without any problem to other browsers.
(子乌注:不知道为什么,我这里没出现他指出的这个bug。所以这段我没翻译,我不确定我理解的是不是他所指的--我从字面上看好像是说完整大小的图片不能显示,除非鼠标移动到其他图片上……可在我机器上不会出现这个问题??)
/* The 'click' hack for Internet Explorer */ a:visited { color:#000; }
color:#000; 用来修正ie中的:active样式bug
添加这个全局样式后,所有的超链接都没了这个问题,如果谁知道为什么会出现这个问题,请联系我。(子乌注:如果你知道的话,顺便跟帖也告诉我一声)
步骤8c示例:
运行代码框 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
出处:蓝色理想
责任编辑:moby
上一页 XHTML+CSS创建“两步式”的相册 [7] 下一页 XHTML+CSS创建“两步式”的相册 [9]
◎进入论坛网络编程 版块参加讨论