浮动时出现奇怪的div边界问题
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

Could I please get a explanation of why this code produces the result it does? And a way to fix it/work around it, if possible.

I dont want div 'z' and 'q' to go over 'the blue div border' on the right.

Or

I would like div 'x' to be consitant with 'z' and 'q' and also go over the blue right border as well.

<div style='margin: 5px;width: 653px;border: blue 1px solid;float: left;'>
    <div style='margin: 0px; margin-bottom: 5px;width: 100%;border: red 1px solid;/*float: left;*/'>z</div>
    <div style='overflow: hidden;margin: 0px; margin-bottom: 5px;width: 100%;border: red 0px solid;/*float: left;*/'>
            <div style='margin: 0px; margin-bottom: 0px;width: 300px;border: red 1px solid;float: left;'>y</div>
            <div style='margin: 0px; margin-bottom: 0px;width: 300px;border: red 1px solid;float: right;'>x</div>
    </div>
     <div style='margin: 0px; margin-bottom: 5px;width: 100%;border: red 1px solid;/*float: left;*/'>q</div>

#0

Throught what browser did you produce the screenshot? If it's IE, there's a problem with the box model that causes the border width to be ignored when calculating 100% width.

Either you create an invisible container to size the inner div's or size your inner div to container.width -2.

Also, try removing the width: 100%; from the div's.

#1

The red-border is actually inside the blue border in your image - but I assume you want to increase the margin on the z and q containers...

I've taken the liberty of enclosing the attributes in double-quotes and correcting the style rules that were re-declared (margin and margin-bottom) - but apologies for the line-formatting - I couldn't seem to get it to all stay inside the code block on this forum until I took out the line breaks:

<div style="margin: 5px;width: 653px;border: blue 1px solid;float: left;"><div style="margin: 5px;width: 100%;border: red 1px solid;">z</div><div style="overflow: hidden;margin: 5px;width: 100%;border: red 0px solid;"><div style="margin: 0px;width: 300px;border: red 1px solid;float: left;">y</div><div style="margin: 0px;width: 300px;border: red 1px solid;float: right;">x</div></div><div style="margin: 5px;width: 100%;border: red 1px solid;">q</div>

#2

For this scenario may be your design is working but can break very easily as you have not cleared and handled floated elements.

You can refer to example I have created.I have created a working fiddle for such kind of problems.

http://jsfiddle.net/mayankipsa/e7snvdag/

.floatLeft { float: left;}
.floatRight { float: right;}
.clearBOTH { clear: both; }

.redBorder{border:1px solid red;}
.blueBorder{border:1px solid blue;}

.x,.y{width:49%;margin:1px; }
.z{margin:1px;}
.q{margin:1px;}
<div style='margin: 5px;width: 653px;border: blue 1px solid;float: left;'>
    <div style='margin: 0px; margin-bottom: 5px;width: 100%;border: red 1px solid;/*float: left;*/'>z</div>
    <div style='overflow: hidden;margin: 0px; margin-bottom: 5px;width: 100%;border: red 0px solid;/*float: left;*/'>
            <div style='margin: 0px; margin-bottom: 0px;width: 300px;border: red 1px solid;float: left;'>y</div>
            <div style='margin: 0px; margin-bottom: 0px;width: 300px;border: red 1px solid;float: right;'>x</div>
    </div>
     <div style='margin: 0px; margin-bottom: 5px;width: 100%;border: red 1px solid;/*float: left;*/'>q</div>
</div>

<div class="clearBOTH"></div>
<div class="blueBorder" style="margin-top:50px;">
    <div class="z redBorder">z</div>
    <div class="redBorder">
        <div class="y floatLeft redBorder">y</div>
        <div class="x floatRight redBorder">x</div>
        <div class="clearBOTH"></div>
    </div>
    <div  class="q redBorder">q</div>
</div>

推荐文章

ASP.NET主机环境/ShadowCopyBinAssembles

ASP.NET主机环境/ShadowCopyBinAssembles

推荐文章

Docker Compose 整合发布应用相关服务

Docker Compose 整合发布应用相关服务

推荐文章

是否有使用T-SQL验证XML的方法?

是否有使用T-SQL验证XML的方法?

推荐文章

RijndaelManaged支持128-256位密钥,默认构造函数生成器的密钥大小是多少?

RijndaelManaged支持128-256位密钥,默认构造函数生成器的密钥大小是多少?

推荐文章

记Linux安装nginx的过程

记Linux安装nginx的过程

推荐文章

MS-Access中本地服务器上的慢SQL代码

MS-Access中本地服务器上的慢SQL代码

推荐文章

Java SpringMVC使用nginx和WildFly实现动静分离

Java SpringMVC使用nginx和WildFly实现动静分离

推荐文章

在.Net中解压缩MSI

在.Net中解压缩MSI

推荐文章

浅谈MVC设计模式

浅谈MVC设计模式

推荐文章

ClickOnce.appref ms不止一个指向.application file的链接?

ClickOnce.appref ms不止一个指向.application file的链接?

推荐文章

注释已删除的代码

注释已删除的代码

推荐文章

Nginx + Tomcat HTTPS配置

Nginx + Tomcat HTTPS配置

推荐文章

是否可以对LINQ to SQL使用/访问标量函数?

是否可以对LINQ to SQL使用/访问标量函数?

推荐文章

nginx超时配置

nginx超时配置

推荐文章

java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to

java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to

推荐文章

如何将AES Rijndael生成的密钥存储到数据库中?

如何将AES Rijndael生成的密钥存储到数据库中?