定义图库 div 中图像风格的正确方法是什么?
我有一个 id 为“gallery”的 div,我想设置其中图像的样式。 具体来说,我想给每个图像一个 1px 的纯黄色边框(底部除外),因为它们位于彼此的顶部,所以我不想将底部的边框加倍。
我感到困惑的是如何在不同的边框样式元素之间进行选择:边框、边框样式、边框宽度。 我尝试了这个:
div#gallery img
{
border-width:1px;
border-style:solid;
border: solid yellow;
border: 1px 1px 0px 1px;
}
我设法用上面的 css 获得了一个黄色边框,但边框看起来更像是一个 2px 边框 - 它相当厚 - 而且,除此之外,我使用的语法看起来不太优雅。
关于如何更简洁/优雅地做到这一点有什么建议吗?
I have a div with an id of 'gallery' and I want to style the images inside it. Specifically, I want to give each of the images a 1px solid yellow border except on the bottom because they sit on top of each other, so I don't want to double the border on the bottom.
What I'm confused about is how to choose between the different border style elements: border, border-style, border-width. I tried this:
div#gallery img
{
border-width:1px;
border-style:solid;
border: solid yellow;
border: 1px 1px 0px 1px;
}
I managed to get a yellow border with this css above but the border seems more like a 2px border - it's quite thick - and, besides that, the syntax I'm using doesn't look very elegant.
Any recommendations on how to do this more concisely/elegantly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是最好的方法:
border
声明采用width style color
并影响所有四个边框。 之后,您可以通过声明border- 将底部覆盖回使用无边框底部
为无。I think this is the best way:
The syntax for the
border
declaration goeswidth style color
and affects all four borders. After that, you can override the bottom back to using no border by declaringborder-bottom
as none.我真的不知道是否有错误的方法,但基本上有3种方法可以做到这一点:
方法1
方法2
方法2 strong>
我更喜欢方法2或方法3。
(我知道方法2和方法3基本相同,但我想给出两种解决方案,所以你可以选择你喜欢的,“无”或“0”)。
I don't really know if there's a wrong way to do it, but you basically have 3 methods to do it:
Method 1
Method 2
Method 2
I would prefer either method 2 or method 3.
(I know method 2 and method 3 are basically the same, but I wanted to give both solutions, so you can choose what you like, "none" or "0").