如何使用 div 模拟
我正在尝试为选择的标签提供边框,并且在过去的两个小时里一直在抓狂。
我在通过绝对和相对使用位置之前已经完成了它,但是我的硬盘崩溃了并且我的所有代码都丢失了。
简而言之,我有
<div style="position:relative; border:1px solid #cc0000;">
<select style="position:absolute;">
<option>1</option>
</select>
</div>
这似乎不起作用... div 自动扩展到父 div 的宽度而不是其内容的宽度
如何将 div 设置为自动适合选择框的内容并具有1px 的边框而不被推出框架?
如果您需要更多代码,请说明。
感谢任何和所有的帮助。 :)
编辑
这是更多代码...
HTML:
<div class="orderQuantity">
<label for="quantity" class="orderInputLabel">Quantity:</label>
<div> <!--THIS IS THE DIV THAT NEEDS A BORDER!! -->
<select id="quantity_cs" name="quantity_cs" autocomplete="off" class="required">
<option value=''>     </option>
<option value='10'>10</option>
<option value='20'>20</option>
<option value='30'>30</option>
<option value='40'>40</option>
<option value='50'>50</option>
<option value='60'>60</option>
<option value='70'>70</option>
<option value='80'>80</option>
<option value='90'>90</option>
<option value='100'>100</option>
</select>
</div> <!-- end of div that needs border -->
</div>
CSS:
.orderQuantity {
margin-top: 12px;
}
这就是我目前所拥有的全部代码。我尝试了很多方法,但没有一个有效。包括使选择绝对和父级 div 相对,反之亦然。
帮助? d:
I'm attempting to provide a border for a select tag and have been pulling my hair out for the last 2 hours.
I had it done before using position via absolute and relative, but my hard drive crashed and all my code was lost.
Put simply I have
<div style="position:relative; border:1px solid #cc0000;">
<select style="position:absolute;">
<option>1</option>
</select>
</div>
This doesn't seem to work... The div automatically expands to the parent div's width as opposed to the width of its content
How do I set the div to automatically fit to the contents of the select box AND have a border of 1px without getting pushed out of the frame?
If you need more code, please say so.
Any and all help is appreciated. :)
EDIT
Here's some more code...
HTML:
<div class="orderQuantity">
<label for="quantity" class="orderInputLabel">Quantity:</label>
<div> <!--THIS IS THE DIV THAT NEEDS A BORDER!! -->
<select id="quantity_cs" name="quantity_cs" autocomplete="off" class="required">
<option value=''> </option>
<option value='10'>10</option>
<option value='20'>20</option>
<option value='30'>30</option>
<option value='40'>40</option>
<option value='50'>50</option>
<option value='60'>60</option>
<option value='70'>70</option>
<option value='80'>80</option>
<option value='90'>90</option>
<option value='100'>100</option>
</select>
</div> <!-- end of div that needs border -->
</div>
CSS:
.orderQuantity {
margin-top: 12px;
}
This is all I have at this point. I've tried numerous things, none of which worked. Including making the select absolute and the parent div relative and vice versa.
Help? D:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为此使用 jQuery。跨浏览器兼容。检查工作示例 http://jsfiddle.net/Npv8P/2/
You can use jQuery for this. Cross Browser Compatible. Check working example http://jsfiddle.net/Npv8P/2/
我已经找到了一个涉及浮动和“clear:both”的解决方案,它似乎可以跨浏览器工作。
似乎工作正常。感谢 Mahima 重申了我的尝试,也感谢 Hussein 的帮助。 :)
I've figured out a solution that involves floats and "clear:both" that appears to work cross browser.
Seems to work fine. Thanks to Mahima for reaffirming what I was trying and to Hussein for the help. :)