CSS显示:inline

编程入门 行业动态 更新时间:2024-10-18 16:50:59
CSS显示:inline-block不接受margin-top?(CSS display: inline-block does not accept margin-top?)

我有一个显示元素:inline-block,但它似乎并不接受margin-top。 这是因为元素仍被视为内联元素吗?

如果是,有没有人有解决方法?


编辑#1

我的CSS很简单:

.label {
  background: #ffffff;
  display: inline-block;
  margin-top: -2px;
  padding: 7px 7px 5px;
}
 

我最终将内容包装在另一个div中,并给出了一个边际顶点。 但是这会导致很多额外的标记,并使我的代码不太清楚。

编辑#2

inline-block元素的margin-top和margin-bottom似乎只能用正值。

I have an element with display: inline-block, but it doesn't seem to accept margin-top. Is this because the element is still treated as an inline element?

If yes, does anyone have a workaround?


EDIT #1:

My CSS is quite simple:

.label {
  background: #ffffff;
  display: inline-block;
  margin-top: -2px;
  padding: 7px 7px 5px;
}
 

I ended up wrapping the content in another div and giving that a margin-top. But that causes a lot of extra markup and makes my code less clear.

EDIT #2:

margin-top & margin-bottom on inline-block elements only seems to work with positive values.

最满意答案

我用display: table 。 它具有内联块的内容拟合属性,但也支持负边距,将会随之移动内容。 可能不是你应该如何使用它,但它的作品。

I used display: table. It has the content-fitting properties of inline-block but also supports negative margins in a way that will shift the content following it up along with it. Probably not how you should be using it, but it works.

更多推荐

本文发布于:2023-04-28 05:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1330322.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CSS   inline

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!