[英]Add width to left side of div?
How can I add N pixels to a div's width, but append that extra width to the left side of the div?如何将 N 像素添加到 div 的宽度,但将额外的宽度附加到 div 的左侧?
For example, simply increasing its width by 20px will add 20px to the right side.例如,简单地将其宽度增加 20px 将向右侧添加 20px。
On the other hand, I could add left-padding
but that doesn't quite cut it for me.另一方面,我可以添加
left-padding
,但这对我来说并没有完全减少。
Is there a way to genuinely expand the div to the left using CSS or Javascript?有没有办法真正使用 CSS 或 Javascript 将 div 扩展到左侧?
Same question about expanding to the top instead of expanding to the bottom if height is changed.如果高度改变,关于扩展到顶部而不是扩展到底部的相同问题。
Here are some possible options:以下是一些可能的选择:
direction
property to make the writing mode RTL.direction
属性,使书写模式 RTL。flex-direction: row-reverse
for the width problem.flex-direction: row-reverse
解决宽度问题。flex-direction: column-reverse
for the height problem.flex-direction: column-reverse
来解决高度问题。 div { direction: rtl; width: 400px; /* width: 450px; */ background-color: lightgray; height: 25px; } p { display: flex; flex-direction: row-reverse; width: 450px; /* width: 500px; */ background-color: lightgreen; height: 25px; } span { display: flex; flex-direction: column-reverse; height: 50px; /* height: 150px; */ background-color: aqua; }
<div>with RTL, width expands the div leftward</div> <p>with flex-direction: row-reverse, to p simulates leftward expansion</p> <span>with flex-direction: column-reverse, the span simulates upward expansion</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.