选择跨浏览器缩放元素,IE8 除外

发布于 2024-10-13 05:08:01 字数 1370 浏览 0 评论 0原文

我正在尝试使用窗口大小(调整大小时)缩放 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不弃不离 2024-10-20 05:08:01

这是可行的:

div {
    position: absolute;
    left: 10px;
    right: 96px;
    width: auto;
    width: -moz-availble;
    width: expression(document.body.clientWidth-(10+96));
    top: 134px;
    background-color: yellow;
    width:80%;
    height:20px;
}

select {
    position: absolute;
    left: 25px;
    right: 90px;
    width: auto;
    width: -moz-available;
    width: expression(wrap.style.pixelWidth-(25+90)););
    top: -2px;
    width: 100%;
}

我在这里所做的是使用宽度百分比。但请记住,只有宽度属性可以使用百分比元素。

This works:

div {
    position: absolute;
    left: 10px;
    right: 96px;
    width: auto;
    width: -moz-availble;
    width: expression(document.body.clientWidth-(10+96));
    top: 134px;
    background-color: yellow;
    width:80%;
    height:20px;
}

select {
    position: absolute;
    left: 25px;
    right: 90px;
    width: auto;
    width: -moz-available;
    width: expression(wrap.style.pixelWidth-(25+90)););
    top: -2px;
    width: 100%;
}

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.

东走西顾 2024-10-20 05:08:01

波普杰为我指明了正确的方向。唯一缺少的是保持相同数量的左右位置(因为宽度%)。
用另一个 div 包裹 select,显示预期的结果。 IE8确实正确渲染 div 元素的左右属性,以便大部分 select 样式可以移动到周围的 div 并且只为选择设置width:100%

新的演示可以在 http://jsfiddle.net/yKVbr/8/ 上找到,即:
HTML

<div id="wrap">
  **<div id="innerwrap">**
        <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>**
</div>

CSS

div#wrap {..same as before..}
div#innerwrap {
    position: absolute;
    left: 25px;
    right: 90px;
    width: auto;
    width: -moz-available;
    width: expression(wrap.style.pixelWidth-(25+90)););
    top: -2px;    
}

select {
    position: absolute;
    height: 16px;
    width: 100%;
}

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 render div elements correctly concerning its left and right properties, so that most of the select style can be moved to the surrounding div and only setting width:100% for the select.

The new demo can be found on http://jsfiddle.net/yKVbr/8/, i.e.:
HTML:

<div id="wrap">
  **<div id="innerwrap">**
        <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>**
</div>

CSS:

div#wrap {..same as before..}
div#innerwrap {
    position: absolute;
    left: 25px;
    right: 90px;
    width: auto;
    width: -moz-available;
    width: expression(wrap.style.pixelWidth-(25+90)););
    top: -2px;    
}

select {
    position: absolute;
    height: 16px;
    width: 100%;
}
多彩岁月 2024-10-20 05:08:01

左右定位,你的意思是你想要它居中吗?在这种情况下,我会尝试以下操作之一:

div#wrap { /* or innerwrap, whatever suits you best */
   margin: auto;
}

或者

div#wrap {
   margin: x%; /* where the x is to be replaced by a number that's dependable on the width of the elements*/
}

另外,您可能必须声明属性

position:relative;

,因为这有时似乎是必要的(如果您问我,这在 css 中有点奇怪)。

希望这对您有所帮助,如果您有其他意思,请直接说出来;)

With left and right positioning, do you mean you want it centered? In that case i would try one of the following:

div#wrap { /* or innerwrap, whatever suits you best */
   margin: auto;
}

or

div#wrap {
   margin: x%; /* where the x is to be replaced by a number that's dependable on the width of the elements*/
}

Also, you might have to state the property

position:relative;

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 ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文