选择跨浏览器缩放元素,IE8 除外
我正在尝试使用窗口大小(调整大小时)缩放 select
元素。这适用于 FF3.6、Chrome 10、IE6 (!!) 和 IE7,但是...不适用于 IE8。
特定代码片段的演示可以在 http://jsfiddle.net/yKVbr/5/.
即:
HTML:
<div id="wrap">
<select>
<option value='field1'>Datum gereed</option>
<option value='field2'>Korte omschrijving</option>
<option value='field3'>Taak Code</option>
<option value='field4'>Project omschrijving</option>
</select>
</div>
CSS:
div {
position: absolute;
left: 10px;
right: 96px;
width: auto;
width: -moz-availble;
width: expression(document.body.clientWidth-(10+96));
top: 134px;
height: 18px;
background-color: yellow;
}
select {
position: absolute;
left: 25px;
right: 90px;
width: auto;
width: -moz-available;
width: expression(wrap.style.pixelWidth-(25+90)););
top: -2px;
height: 16px;
}
当 IE8 在 Quirksmode 下呈现时(即没有 DOCTYPE),它会很顺利,因为它的行为就像 IE7 一样。然而,这不是一个令人满意的解决方案:-)
我已经在论坛中进行了搜索,但没有发现类似的问题。 我还尝试使用 CSS3 属性 resize
(resize:both; Overflow:auto
) 但无济于事。
谁可以帮助我指出正确的方向,以便所有浏览器仍然可以正确缩放包括 IE8?
I'm trying to scale a select
-element with the window-size (on resizing). This goes well for FF3.6, Chrome 10, IE6 (!!) and IE7, however... not for IE8.
A demonstration of the particular code-fragment can be found on http://jsfiddle.net/yKVbr/5/.
That is:
HTML:
<div id="wrap">
<select>
<option value='field1'>Datum gereed</option>
<option value='field2'>Korte omschrijving</option>
<option value='field3'>Taak Code</option>
<option value='field4'>Project omschrijving</option>
</select>
</div>
CSS:
div {
position: absolute;
left: 10px;
right: 96px;
width: auto;
width: -moz-availble;
width: expression(document.body.clientWidth-(10+96));
top: 134px;
height: 18px;
background-color: yellow;
}
select {
position: absolute;
left: 25px;
right: 90px;
width: auto;
width: -moz-available;
width: expression(wrap.style.pixelWidth-(25+90)););
top: -2px;
height: 16px;
}
When IE8 renders in Quirksmode (i.e. without a DOCTYPE), it goes well because then it behaves like IE7. However, this is not a satisfiable solution :-)
I've searched through the forum, however I didn't find a similar problem.
I've also tried working with the CSS3-property resize
(resize:both; overflow:auto
) to no avail.
Who can help pointing me in the right direction so that all browsers still scale it correcly including IE8?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是可行的:
我在这里所做的是使用宽度百分比。但请记住,只有宽度属性可以使用百分比元素。
This works:
What i did here is use a percentage for the width. But keep in mind that only the width property can make use of the percentage element.
波普杰为我指明了正确的方向。唯一缺少的是保持相同数量的左右位置(因为宽度%)。
用另一个 div 包裹
select
,显示预期的结果。 IE8确实正确渲染div
元素的左右属性,以便大部分select
样式可以移动到周围的div
并且只为选择设置width:100%
。新的演示可以在 http://jsfiddle.net/yKVbr/8/ 上找到,即:
HTML:
CSS:
poepje pointed me in the right direction. The only thing that was missing was to keep the same amount of left and right position (because of the width-%).
Wrapping the
select
with another div, shows the intended result. IE8 does renderdiv
elements correctly concerning its left and right properties, so that most of theselect
style can be moved to the surroundingdiv
and only settingwidth:100%
for the select.The new demo can be found on http://jsfiddle.net/yKVbr/8/, i.e.:
HTML:
CSS:
左右定位,你的意思是你想要它居中吗?在这种情况下,我会尝试以下操作之一:
或者
另外,您可能必须声明属性
,因为这有时似乎是必要的(如果您问我,这在 css 中有点奇怪)。
希望这对您有所帮助,如果您有其他意思,请直接说出来;)
With left and right positioning, do you mean you want it centered? In that case i would try one of the following:
or
Also, you might have to state the property
since this seems to be neccesary sometimes (kindof a weird thing in css if you ask me).
Hope this helped, if you meant something else just say so ;)