css - 调整大小时保持 p 元素附加到 h2 p 元素不移动

标签 css wordpress element

.uvc-main-heading p {
  position: relative;
  left: -8%;
  transform: rotate(-20deg)
}
<div class="uvc-main-heading ult-responsive">
  <p style="text-decoration:underline;font-weight:bold;color:#800000;">NEW</p>
</div>
<div class="uvc-main-heading ult-responsive">
  <h2 style="font-weight:bold;color:#000000;">Open Stock</h2>
</div>

这会将它定位在我想要的位置,但是当我调整浏览器大小时,新元素会随之移动,我希望它保持原位,但仍会与其余元素一起滚动。

Website on Desktop

Website on Mobile

我知道我可以使用 CSS 和媒体查询来做每个断点,但我正在努力寻找更好的解决方案

谢谢

最佳答案

为什么不直接将新标签移动到标题中并将其绝对定位到标题,那么它的位置将不会随着相对于标题的变化而改变:

body {
  text-align: center;  /* for test only */
}

.uvc-main-heading {
  position: relative;    /* position new absolutely to this */
  display: inline-block; /* for test (so you can see it centred */
}

.uvc-main-heading p {
  /* position this absolutely */
  position: absolute;
  top: 0;
  left: 0;

  /* translation moves it left 25% it's ownb width and 100% up it's own height */
  transform: rotate(-20deg) translate(-25%, -100%);
}
<div class="uvc-main-heading ult-responsive">
  <h2 style="font-weight:bold;color:#000000;">Open Stock</h2>
  <p style="text-decoration:underline;font-weight:bold;color:#800000;">NEW</p>
</div>

关于css - 调整大小时保持 p 元素附加到 h2 p 元素不移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50723774/

相关文章:

javascript - 使用 javascript 将 css 系统颜色转换为十六进制?

php - 在单个查询中为每个类别选择 n 个帖子

php - 如何在 WordPress 的标题中添加图像

php - 在 PHP 中将数组元素移动到顶部

Angular2 使用指令在标签中插入自定义属性

html - 只有当另一个 div 悬停时才悬停一个 div

css - 如何水平对齐一行中的 3 个跨度?

wordpress - 如何在 AWS EC2 WordPress 站点上安装 SSL

list - 如何在erlang中更改列表中的元素

php - 如何为谷歌字体指定缓存验证器