动态加载元素并直接通过服务器时,CSS负边距差异(CSS negative margin difference when loading elements dynamically and straig

编程入门 行业动态 更新时间:2024-10-27 14:32:32
动态加载元素并直接通过服务器时,CSS负边距差异(CSS negative margin difference when loading elements dynamically and straight through the server)

当从服务器直接加载并通过CSS动态加载时,元素的位置不同。

我在两种情况下使用相同的CSS类但结果不同。

margin-bottom设置为-40px ,当我通过PHP加载元素并通过jQuery动态加载元素时,元素的位置不同。

CSS类:

.iconView .adLocation { background-color: rgba(0,0,0,0.3); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #FFF; height: 18px; font-size: 13px; position: absolute; margin-top: -40px; width: 188px; }

我通过chrome dev工具检查了元素的CSS,并将margin-top正确设置为40px 。 我不能发布预览不够的声誉。 SRY。

The position of the element differs when loading straight from server and dynamically through CSS.

I am using the same CSS class on both occasions but different results.

The margin-bottom is set to -40px, the location of the element is different when I am loading the element through PHP and dynamically through jQuery.

The CSS class:

.iconView .adLocation { background-color: rgba(0,0,0,0.3); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #FFF; height: 18px; font-size: 13px; position: absolute; margin-top: -40px; width: 188px; }

I inspected the CSS of the element via chrome dev tools & margin-top is set properly to 40px. I can't post a preview not enough reputation. sry.

最满意答案

由于你已经定义了你的元素位置绝对,所以你可以使用top: -40px; 而不是使用margin-top: -40px;

As you have defined your element position absolute, so you can use top: -40px; instead of using margin-top: -40px;

更多推荐

本文发布于:2023-07-16 15:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130455.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:差异   元素   加载   服务器   动态

发布评论

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

>www.elefans.com

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