定义图库 div 中图像风格的正确方法是什么?

发布于 2024-07-26 07:15:00 字数 426 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老旧海报 2024-08-02 07:15:00

I think this is the best way:

border: 1px solid yellow;
border-bottom: none;

The syntax for the border declaration goes width style color and affects all four borders. After that, you can override the bottom back to using no border by declaring border-bottom as none.

陌上芳菲 2024-08-02 07:15:00

我真的不知道是否有错误的方法,但基本上有3种方法可以做到这一点:

方法1

border-top: 1px solid yellow;
border-right: 1px solid yellow;
border-left: 1px solid yellow;

方法2

border: 1px solid yellow;
border-bottom: 0;

方法2 strong>

border: 1px solid yellow;
border-bottom: none;

我更喜欢方法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

border-top: 1px solid yellow;
border-right: 1px solid yellow;
border-left: 1px solid yellow;

Method 2

border: 1px solid yellow;
border-bottom: 0;

Method 2

border: 1px solid yellow;
border-bottom: none;

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").

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文