缩小时 HTML 边框出现浮动问题
我有一个 div 容器,宽度为 800px,由单个边框(1px)分成两部分。 div A (399px) 向左浮动,div B(400px) 向右浮动。问题是当我缩小时,右边框(div B)正在移动,将其放置在页面底部。为了解决这个问题,我将两个 div 的宽度设置为各 50% 的百分比——我删除了边框。现在,当我在中心添加边框(通过设置 div A 的 border-right),并将 div A 调整为 49.8% 时,缩小时它再次将 div B 放在底部。我做错了什么吗?我猜问题是边框设置为 1px。如何解决这个问题?我需要 1px 大小的边框。
I have a div container, which is 800px width, that is separated into two by a single border(1px). div A (399px) is floated left while div B(400px) is float right. The problem is when i'm zooming out, the right border, which is div B, is being move wherein it place it at the bottom of the page. To fix it, I set the two div's width to percentage at 50% each -- I removed the border. Now when I add the border at the center (by setting border-right of div A), and also adjusting div A to 49.8%, it again places div B at the bottom when zooming out. Am I doing something wrong? The problem is that the border is set to 1px I guess. How to fix this? I need the 1px size of the border.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
出现此问题的原因是浏览器按比例缩小了 div 的大小,但没有对边框进行缩小。
要解决此问题,请尝试使用以下 css:
div 的大小将使用边框进行测量,并在缩小时适当缩小,您可以将两个 div 的宽度保留为 400px。
完整的代码应该类似于:
This problem occurs because the browser is reducing the size of the divs proportionally, but does not apply reducing to the border.
To resolve this try using this css:
The size of the div will be measured with the border and reduced properly when zooming out and you can leave both divs with the width of 400px.
The full code should look simillar to this:
你可以这样做:
http://jsfiddle.net/SNZEK/
如果将一个 div 放入另一个 div 中并将边框大小添加到父级 div。这应该适用于 FF、Chrome 和 >=IE7
You could do it like this:
http://jsfiddle.net/SNZEK/
If you put one div within another div and add the border size to the parent div. That should work in FF, Chrome and >=IE7
尝试以下 css 看看是否能解决您的问题。我已经在 IE8 和 Chrome 上尝试过了
他们都工作得很好。我在 jsfiddle 设置了我的测试示例。
Try the following css see if it solve your problem. I have tried it in on IE8 and Chrome and
they both work fine. I had setup my test example at jsfiddle.