.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>
这会将其定位在我希望的位置,但是当我调整浏览器的大小时,NEW元素将随之移动,并且我希望它保持原位,但仍与其余滚动。
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>