左浮动在 IE7 中不起作用,但在 IE8 sharepoint .aspx 页面中起作用
div 的三个块将包含文本,其中块 1 和 2 是可选的。在这种情况下,我想使用 float:left 对齐 div 以避免 div 之间有额外的空间。这是我使用的代码。这段代码在 IE8 中工作正常,但在 IE7 中不行。我已经浏览了这篇文章div 中的左浮动在 IE7 中不起作用,但在 Firefox 和 IE8 中起作用。但它不起作用。
代码:
<div style="width:1120px;overflow:auto">
<div id="_invisibleIfEmpty" name="_invisibleIfEmpty"
style="overflow:hidden; vertical-align:text-top; float:left;height:100%;width:33%;display:table-row">
Block 1 </div >
<div id="_invisibleIfEmpty" name="_invisibleIfEmpty"
style="overflow:hidden;vertical-align:text-top;padding-left:5px;height:100%;width:33%;float:left;display:table-row;">
Block 2</div >
<div id="_invisibleIfEmpty" name="_invisibleIfEmpty" style="overflow:hidden;vertical-align:text-top;padding-left:5px;height:100%;width:33%;float:left;display:table-row">
Block 3 </div >
There are three blocks of div which will contain text, where block 1 and 2 are optional. in that case i want to align the div using float:left to avoid extra space between the div. here is the code im using. this code is working fine in IE8 but not in IE7. i have gone through the post Float left in a div does not work in IE7 but does in Firefox and IE8. but it is not working.
Code:
<div style="width:1120px;overflow:auto">
<div id="_invisibleIfEmpty" name="_invisibleIfEmpty"
style="overflow:hidden; vertical-align:text-top; float:left;height:100%;width:33%;display:table-row">
Block 1 </div >
<div id="_invisibleIfEmpty" name="_invisibleIfEmpty"
style="overflow:hidden;vertical-align:text-top;padding-left:5px;height:100%;width:33%;float:left;display:table-row;">
Block 2</div >
<div id="_invisibleIfEmpty" name="_invisibleIfEmpty" style="overflow:hidden;vertical-align:text-top;padding-left:5px;height:100%;width:33%;float:left;display:table-row">
Block 3 </div >
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道 ESPN 中的 ASP,但我可以告诉你 1. 标记一团糟,2. 你对 CSS 的思考太多了。
首先,第一个
没有关闭,但这可能是由于您粘贴到 SO 中造成的。其次,三个内部 div 具有相同的 ID - 这是一个禁忌。第三,您的样式都是内联的,这也不理想,但我假设您为了简洁起见将它们粘贴到这里。
您的标记可以大大简化:
然后这个 CSS 应该可以让您到达您需要的位置:
您可以根据口味调整高度。如果需要,您可以添加溢出值 - 但不需要“overflow:auto”,因为这是 CSS 中的默认值。仅当先前的样式声明了不同的“溢出”值并且您想要撤消该值时,您才需要这样做。
PS:我对此进行了测试,它可以在 IE7 中运行: http://jsfiddle.net/xZ2Az/1/
I don't know ASP from ESPN, but I can tell you 1. the markup is a mess and 2. you're over-thinking the CSS.
First off, the first
<div>
didn't close, but that may be due to you pasting into SO. Second, the three inner div's have the same ID - which is a no-no. Third, your styles are all inline, which isn't ideal, either, but I'm assuming you're pasting them in here for brevity's sake.Your markup can be greatly simplified:
And then this CSS should get you where you need to be:
You can adjust the heights to taste. You can add the overflow values if you want - but you don't need 'overflow:auto' because that is the default in CSS. You only need that if a previous style declares a different 'overflow' value, and you want to undo that.
PS: I tested this and it works in IE7: http://jsfiddle.net/xZ2Az/1/