如何让div在IE6中调整大小? [英] How do I keep divs from resizing in IE6?

查看:79
本文介绍了如何让div在IE6中调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的标记( 实况转载 ):

 < body> 
< div style =text-align:center> header< input class ='datepicker'/>< / div>
< table>< tr>< td>真宽表.....................< / td>< / tr> < /表>
< / body>

激活日期选择器时,标题div的宽度会从屏幕宽度变为宽度该表(更大)。这导致标题的中心内容转移到新的中心......这非常烦人。

这发生在IE6中,而不是FF3.5,IE8或IE8-compat-mode。

什么是最好的方式来修复头div的宽度与窗口宽度(而不是内容)?

注意:可能有一个比datepicker - 可能不涉及jQuery的东西 - 这只是触发我的触发器,所以我以这种方式发布。这里是一个例子,它添加了一个dom元素而不会触发这个问题。

解决方案

没有容器或CSS指令的简单组合似乎适用于我。这是我最终做的事情(我已经在我的堆栈中有jquery):

  //在px中设置头部div的宽度页面加载/窗口大小
$(window).bind('load resize',function(){
$('#header')。css('width',$(window).width( ) - 20 / *滚动条* /);
});

这确实是一种管道胶带解决方案:它比症结在于根本原因。 。但它似乎工作得很好,我可以继续做更好的事情。



我相信一个纯css解决方案存在这个问题...如果你有它,请张贴!

Here's my markup (live repro):

<body>
  <div style="text-align:center">header <input class='datepicker'/></div>
  <table><tr><td>really wide table.....................</td></tr></table>
</body>

When the datepicker is activated, the header div's width changes from the width of the screen to the width of the table (larger). This causes the header's centered contents to shift to its new center...which is very annoying.

This occurs in IE6 but not in FF3.5, IE8, or IE8-compat-mode.

What's the best way to fix the width of the header div to the width of the window (not the content)?

Note: there is probably a much simpler example than the datepicker--probably something that doesn't involve jQuery--that's just the trigger that hit me so I'm posting it that way. Here's an example that adds a dom element without triggering this problem.

解决方案

No simple combination of containers or CSS directives seemed to work for me. Here's what I ended up doing (I already have jquery in my stack):

// set the header div's width in px on page load/window resize
$(window).bind('load resize', function() {
  $('#header').css('width', $(window).width() - 20 /* scrollbars */);
});

This is a duct-tape solution for sure: it treats the symptoms more than the root cause...but it seems to work well enough that I can move on to better things.

I'm confident a pure-css solution exists to this problem...if you have it, please post it!

这篇关于如何让div在IE6中调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆