gpt4 book ai didi

javascript - 在div的左侧添加宽度?

转载 作者:行者123 更新时间:2023-11-28 01:01:04 26 4
gpt4 key购买 nike

如何将 N 像素添加到 div 的宽度,但将额外的宽度附加到 div 的左侧?

例如,只需将其宽度增加 20px,右侧就会增加 20px。

另一方面,我可以添加 left-padding 但这对我来说不太合适。

有没有办法使用 CSS 或 Javascript 真正将 div 向左扩展?

如果高度改变,关于扩展到顶部而不是扩展到底部的相同问题。

最佳答案

这里有一些可能的选择:

  • 调整 CSS direction 属性,使书写模式为 RTL。
  • 使用带有 flex-direction: row-reverse 的 flex 布局来解决宽度问题。
  • 使用带有 flex-direction: column-reverse 的 flex 布局来解决高度问题。

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>

关于javascript - 在div的左侧添加宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42189407/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com