使用position:absolute设置输入宽度

编程入门 行业动态 更新时间:2024-10-28 19:33:14
本文介绍了使用position:absolute设置输入宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一个简单而烦人的 - 我tryign通过使用绝对定位(即右:10px;左:10px)设置输入[type = text]宽度,但我不能得到它打球。

$

解决方案

实际上,你是什么人? 做得很好。您只需要记住设置父元素的位置。

< div> < input type =text> < / div>

然后CSS it:

div { width:400px; position:relative; } 输入{ position:absolute; left:5px; right:5px; }

这将导致输入框为390px。

如果你设置div是灵活的,那么输入框也是。

edit:似乎只能在Chrome中工作,因此您需要将输入内置到另一个元素中。这在FF和IE中也有效:

< div id =parent> < div>< input type =text>< / div> < / div>

使用此CSS:

#parent { position:relative; width:400px; } #parent div { position:absolute; left:5px; right:5px; } #parent div输入{ width:100%; }

这有预期的效果。有点hack-ish,也许...

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 anyone have a solution to kick it into shape?

解决方案

Actually, what you're doing works fine. You just need to remember to set the parent element's position as well.

<div> <input type="text"> </div>

Then CSS it:

div { width: 400px; position: relative; } input { position: absolute; left: 5px; right: 5px; }

This would result in the input box being 390px.

If you set the div to be flexible, then the input box would be too.

edit: seems to only work in Chrome, so you'd need to put the input inside another element. This works in FF and IE too:

<div id="parent"> <div><input type="text"></div> </div>

with this CSS:

#parent { position: relative; width: 400px; } #parent div { position: absolute; left: 5px; right: 5px; } #parent div input { width: 100%; }

This has the expected effect. A bit hack-ish, maybe...

更多推荐

使用position:absolute设置输入宽度

本文发布于:2023-10-07 22:19:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470675.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宽度   position   absolute

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!