在 IE 8 中将浮动设置为右侧时,CSS div 宽度变为 100%,但在 Firefox 和 Chrome 中工作正常

发布于 2024-09-29 09:12:52 字数 1805 浏览 0 评论 0原文

这是我在 IE 8 上的 CSS 问题。

我有一个父 div 和 2 个子 div。我希望父级 div 的宽度根据内部子级 div 的宽度而增加。它在 Firefox 中运行良好,但在 IE8 中,当我为该 div 的内部元素设置 float:right 时,第一个子 div 的宽度将变为整个页面宽度。

我的 HTML 标记

<div class="divPageContainer">   
    <div id="pnlOrderOptions" class="pnlOrderOptions">      
        <div class="divOrderOptions">      
            some content           
        </div>    
    </div>
    <div class="divOrderDetails" id="pnlOrderDetails">
        <div style="height:20px;width:800px;border:3px solid red;padding:2px;">this width of this red box can be vary from 100 to 1000</div>
    </div>
</div>

和 CSS

.divPageContainer  
 { width:auto; 
   float:left; 
   margin-left:8px;
   height:auto;
   border:1px solid black;
 }
 .pnlOrderOptions 
 {
   min-height:10px; 
   height:auto;
   overflow:auto;
   margin-top:30px; 
   border:1px solid orange;
   width:auto;
 }
 .divOrderOptions 
  {
    margin-left:7px; 
    font-family:Verdana;
    font-size:12px; 
    width:400px; min-height:10px;height:auto;
    border:1px solid #858A8D;
    float:right; padding:5px;
    background-color:#F0F6F8;
  }
  .divOrderDetails 
  { 
    float:left; 
    margin-top:4px;padding:3px;
    border:2px solid blue;
    min-height:10px;height:auto;
  }

在 Firefox 中运行良好;这是:

alt text

在 IE 中我得到了(我将红色边框 div 宽度从 800 减少到 400 以获得一张很好的快照,因为我的显示器很宽)

alt text

我注意到的一件事是,当我部署这个时出现了这个问题作为 Intranet Web 应用程序。它在本地开发机器上运行良好。我记得以前我们把站点部署到内网时,会出现一些IE7兼容性问题。

我正在寻找的最终结果是内容为“somecontent”的div,这里应该是最右侧(不是页面,而是基于第二个div的宽度,它会动态变化),即它的行为应该像我的Firefox屏幕截图。

So here is my CSS problem with IE 8.

I have a parent div and 2 child div. I want the parent divs width to be increased based on the width of the inner -child div's. It works well in Firefox, but in IE8, the first child div's width going to the entire page width when I have a float:right for the inner element of that div.

My HTML markup

<div class="divPageContainer">   
    <div id="pnlOrderOptions" class="pnlOrderOptions">      
        <div class="divOrderOptions">      
            some content           
        </div>    
    </div>
    <div class="divOrderDetails" id="pnlOrderDetails">
        <div style="height:20px;width:800px;border:3px solid red;padding:2px;">this width of this red box can be vary from 100 to 1000</div>
    </div>
</div>

and the CSS

.divPageContainer  
 { width:auto; 
   float:left; 
   margin-left:8px;
   height:auto;
   border:1px solid black;
 }
 .pnlOrderOptions 
 {
   min-height:10px; 
   height:auto;
   overflow:auto;
   margin-top:30px; 
   border:1px solid orange;
   width:auto;
 }
 .divOrderOptions 
  {
    margin-left:7px; 
    font-family:Verdana;
    font-size:12px; 
    width:400px; min-height:10px;height:auto;
    border:1px solid #858A8D;
    float:right; padding:5px;
    background-color:#F0F6F8;
  }
  .divOrderDetails 
  { 
    float:left; 
    margin-top:4px;padding:3px;
    border:2px solid blue;
    min-height:10px;height:auto;
  }

It works well in Firefox; here it is:

alt text

And in IE I am getting (I reduced the red bordered divs width to 400 from 800 to get a good snapshot because my monitor is a wide one )

alt text

One thing I noticed is that this problem came when I deploy this as a intranet web application. It works well in local development machine. I remember some IE7 compatibility problem used to appear when we deploy sites to intranet.

The ultimate result I am looking for is the div with content "somecontent" here should be the right most side (not to the page but based on the width of the second div, which will change dynamically) ie it should behave like my Firefox screenshot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

绮筵 2024-10-06 09:12:52

float right 是 IE 和 FX 2

您可以使用 display:inline-block; 代替吗?有一种方法可以让它在 非 - IE 的内联元素

编辑:您必须在 inline-block 的父级上设置 text-align:right

编辑#2:这是我正在讨论的修复示例: http://work.arounds .org/sandbox/64/run

如果这不是您需要的或者它不适合您,请告诉我。

The float right thing is a known bug in IE and FX 2.

Can you use display:inline-block; instead? There is a way to get it to work on non-inline elements for IE.

EDIT: You'd have to set text-align:right on the parent of the inline-block.

EDIT #2: Here is an example of the fix I was talking about: http://work.arounds.org/sandbox/64/run

Please let me know if this isn't what you need or if it doesn't work for you.

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