using position:absolute to set an inputs width

后端 未结 4 451
没有蜡笔的小新
没有蜡笔的小新 2021-01-11 12:21

A simple yet annoying one - I am tryign to set an input[type=text] width by using absolute positioning (ie right:10px;left:10px) yet I cant get it to play ball.

Does

4条回答
  •  难免孤独
    2021-01-11 12:30

    The css positioning doesn't work quite how you want it to. All it does is set it's position relative to it's parent. The key is that (with most browsers) you only get to specify one of left/right, and one of top/bottom.

    You can set the width of the input to 100%, then set the padding-left to 10px and the padding-right to 10px of the parent container of the input. That should give you want you want.

提交回复
热议问题