如何在基于 960 网格的布局中的 LI 上显示投影?
我正在尝试创建一个以网格(960.gs)格式显示产品列表的页面。为了匹配 COMP,当用户将鼠标悬停在 LI 上方时,我需要在 LI 上显示阴影。
在悬停时显示投影很简单,但以 COMP 中的方式显示它却是一项很难完成的任务,我需要一些帮助。
下面是我必须匹配的 COMP 的屏幕截图。
数字 1 到 10 是网格。我使用 UL 创建行,使用 LI 来显示行中的产品项。
<!-- loops n times for n rows -->
<UL class="container_10 clearfix">
<!-- loops 5 times for 5 list items in a row -->
<LI class="grid_2 product">
<UL>
<LI class="prodImg clearfix">...</LI>
<LI class="prodTitle clearfix">...</LI>
<LI class="prodPrice clearfix">...</LI>
<LI class="prodPromo clearfix">...</LI>
<LI class="prodReviews clearfix">...</LI>
</UL>
</LI>
</UL>
从屏幕截图中可以看出,阴影从网格布局中流出......我现在知道如何将其合并到这里。
编辑:根据项目要求,我们只支持现代浏览器,所以不用担心 IE6 或其他垃圾浏览器,我可以使用 CSS3 :)
I am trying to create a page showing a list of products in a grid (960.gs) format. To match the COMP, I need to show a drop shadow on a LI when the user hovers above it.
Showing the drop shadow on a hover is simple, but showing it the way as it is in COMP is turning out to be a difficult task to complete and I need some assistance.
Below is the screen-shot of the COMP I have to match.
The numbers 1 to 10 are grids. I am using ULs to create rows and LIs to show product items in the row.
<!-- loops n times for n rows -->
<UL class="container_10 clearfix">
<!-- loops 5 times for 5 list items in a row -->
<LI class="grid_2 product">
<UL>
<LI class="prodImg clearfix">...</LI>
<LI class="prodTitle clearfix">...</LI>
<LI class="prodPrice clearfix">...</LI>
<LI class="prodPromo clearfix">...</LI>
<LI class="prodReviews clearfix">...</LI>
</UL>
</LI>
</UL>
As can be seen in the screen-shot the shadow flows out of the grid layout.... I have now clue how to incorporate that here.
edit: As per project requirements we are only supporting modern browsers, so no worries about IE6 or other junk browsers, I am allowed to use CSS3 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果将
position:relative
添加到 LI 标记,则可以在其中添加一个 html 元素,该元素将绝对定位在外部并放置在产品图像和信息下方。如果您想避免添加另一个 html 元素,您甚至可以使用 li:after 来添加它。我不知道这是否足够清楚,如果不够清楚,请询问,我会尽力提供一个可行的示例。
If you add
position:relative
to your LI tags, you could add an html element inside it that would be absolutely positioned outside and placed under the product image and infos.If you want to avoid adding another html element, you could even use
li:after
to add it. I don't know if this is clear enough, if not, just ask, I'll try to provide a working example.由于您不需要适应不太兼容的浏览器,因此我将使用伪元素和 CSS box-shadow 的组合:
.product:after
声明在相对定位的文档流之外创建一个元素到.product
元素。.product:hover:after
声明创建阴影。调整尺寸等以适合您的模型。这是一个示例: http://jsfiddle.net/blineberry/SMqDx/
Since you don't need to accommodate less accommodating browsers, I would use a combination of pseudoelements and CSS box-shadow:
The
.product:after
declaration creates an element outside of the flow of the document positioned relative to the.product
element. The.product:hover:after
declaration creates the drop shadow. Adjust the measurements, etc. to fit your mockup.Here's an example: http://jsfiddle.net/blineberry/SMqDx/
您不能只使用
box-shadow
在悬停时为您的产品框提供阴影吗?类似代码的示例: http://jsfiddle.net/6zcqZ/
编辑
看起来您可能想要使用盒子阴影的
属性,定义如下:因此,您可以简单地添加点差值,例如:
Could you not just use
box-shadow
to give your product boxes shadows when hovered?Example of similar code: http://jsfiddle.net/6zcqZ/
EDIT
Looks like you may be wanting to use the
<spread>
property of box shadows, as defined below:So, instead of the above, you could simply add the spread value, such as: