调整窗口大小会导致浮动Div疯狂

如何解决调整窗口大小会导致浮动Div疯狂

| 我正在尝试创建一个纯粹的基于HTML和CSS的布局,该布局在左侧显示页面的主要内容(扩展到页面的整个宽度,减去框),在右侧显示一个较小的框,例如用于导航或某种信息。这是导致问题的代码示例,其中描述了问题:
<!DOCTYPE HTML>

<html lang=\"en\" dir=\"ltr\">

<head>
 <title>Floating Div Madness upon Window Resize</title>
 <style>
  * {margin:0; padding:0}
  body {margin:20px; font-size:0px; color:#000000}
  div.page {margin-right:120px; background-color:#AAAAFF; float:left}
  div.wide {width:300px; background-color:#AAFFAA}
  div.box  {width:100px; margin-left:-100px; background-color:#FFAAAA; float:left}
  h1 {font-size:x-large}
  p {padding-bottom:5px; font-size:small}
 </style>
</head>

<body>

 <div class=\"page\">
  <h1>MAIN PAGE</h1>
  <p>This is the main portion of the page (light blue). It is currently floated left with a right margin of 120px,to account for the box (light red) as well as the white space between it and the box (light red). All may look well on the surface,but...</p>
  <p>Resize the window in Firefox (I tested both 3.5 and 4) and the white margin of the body can be cut off,not only on the right side,but on the bottom of the page,too.</p>
  <p>Remove enough text and this div will shrink to fit it,no longer taking up the entire width of the page (minus the box).</p>
   <div class=\"wide\">
    <p>If I nest another,non-floating div with a fixed width (light green),something even stranger happens when I resize the window,this time in Internet Explorer 6 (maybe in other versions,too): The text in the page div (light blue) is squished,I think by the margin of the box (light red). The fixed width div (light green) is unaffected by this.</p>
   </div>
 </div>

 <div class=\"box\">
  <h1>BOX</h1>
  <p>(this could be navigation,or anything else)</p>
 </div>

</body>

</html>
出于语义原因,我想稍后在代码中保留该框(浅红色),但这是可选的。这是我已经尝试过的一些更成功的方法,以及它们似乎不起作用的原因: 绝对定位:当不调整浏览器大小时,这和我自己的代码一样好。它确实在某种程度上解决了Firefox中消失的机体空白的问题。但是,当窗口大小变得足够小时,根据我拥有更高或更低的z索引,该框(浅红色)将超出主页div(浅蓝色)之上或之下。 仅浮动框:这涉及更改HTML并将框(浅红色)置于代码中其余内容的前面。这会自动展开主页div(浅蓝色),这是我没有找到使用float方法的一种方法(没有给定的内容量)。但是,在Firefox中仍会删除正文的边距,在IE中仍会挤压文本,并且当出现以下情况时,框(浅红色)仍将在主页div(浅蓝色)的上方或下方(再次取决于z索引)窗户足够小。 为所有内容分配最小宽度:这在解决IE问题方面非常成功,但是需要在页面上进行一些CSS处理,而此页面比这要复杂得多,并且将支持不同的媒体类型。而且,由于它仍处于浮动状态,因此它仍然无法解决Firefox中的页边距问题,也无法为我提供一种无需内容即可扩展主页div(浅蓝色)的方法。 将主体边缘更改为边框:这也无法解决Firefox问题;无论是边框还是边距,当我使用浮点数时,它都会在页面的右侧和底部被切掉。 在框中添加边距:这对Firefox也不起作用。我可以在主页内容的底部留出一定的页边距(浅蓝色)以保留在原处(这对我来说似乎特别奇怪),但是框上的右边距(浅红色)仍然会被剪掉。 我们将不胜感激,因为我找不到任何网站或帖子来回答这些问题,更不用说描述这些问题了。我当然花了很多时间寻找和测试解决方案!     

解决方法

        亲爱的先生,祝您有美好的一天,您似乎在构建布局时遇到麻烦。 据我了解,您需要2列的布局。左列自动扩展到w / e的宽度,以w / e减去右列宽度减去20像素为空白。右列是固定宽度,将包含菜单或各种html结构... 在左侧列中,您将看到文本,其中包括固定宽度框,此列中的固定宽度框应始终留在其中。这意味着我们希望最小宽度为固定宽度的框宽度+ 20 px的边距+右列的宽度。 我通过使容器围绕所有内容,对其应用最小宽度并制作一个虚拟容器来解决IE6中的最小宽度问题来做到这一点。 这是一个看起来像这样的工作示例:http://jsfiddle.net/uXyPu/ 我没有运行IE6或firefox 3.5的版本来对其进行测试,但我相当有信心这会起作用。 附带说明一下,您在body标签上使用了边距,请不要这样做。作为基本规则,请保持身体完全扩张,最多应使用填充物。除此之外,避免边距是防止IE6大量问题的好方法,同时仍使布局与现代浏览器兼容。而且不要在浮动元素上完全使用填充/边距... 在对您的问题的第一条评论中,这位先生是完全避免使用ie6的,我希望您能要求大佬做这个项目,以便公司实际上可以开始考虑他们滥用ie6了。     ,        我将您的右侧框移到了其余代码的上方,将其右移,然后为主页提供了一定百分比的宽度。 编辑: 也许这更好。我绝对将侧边框放置在顶部:20px;右:20px;并在首页上设置了右边距:120px,因此它不会在div下方。 尝试新的代码:
<!DOCTYPE HTML>

<html lang=\"en\" dir=\"ltr\">

<head>
 <title>Floating Div Madness upon Window Resize</title>
 <style>
  * {margin:0; padding:0}
  body {
    margin:20px;
    font-size:0px;
    color:#000000; }
  div.page {
    background-color:#AAAAFF;
    margin-right: 120px; }
  div.wide {
    width: 300px;
    background-color:#AAFFAA; }
  div.box {
    position: absolute;
    top: 20px;
    right: 20px;
    width:100px;
    background-color: #FFAAAA; }
  h1 {font-size:x-large}
  p {
    padding-bottom:5px;
    font-size:small }
 </style>
</head>

<body>

 <div class=\"page\">
  <h1>MAIN PAGE</h1>

  <p>Resize the window in Firefox (I tested both 3.5 and 4) and the white margin of the body can be cut off,not only on the right side,but on the bottom of the page,too.</p>
  <p>Remove enough text and this div will shrink to fit it,no longer taking up the entire width of the page (minus the box).</p>
   <div class=\"wide\">
    <p>If I nest another,non-floating div with a fixed width (light green),something even stranger happens when I resize the window,this time in Internet Explorer 6 (maybe in other versions,too): The text in the page div (light blue) is squished,I think by the margin of the box (light red). The fixed width div (light green) is unaffected by this.</p>
   </div>
 </div>

 <div class=\"box\">
  <h1>BOX</h1>
  <p>(this could be navigation,or anything else)</p>
 </div>

</body>

</html>
    ,        用桌子...
<!DOCTYPE HTML>
<html>
<head>
</head>

<body>
    <table width=\"100%\">
    <tr>
        <td valign=\"top\">
             page content
        </td>
        <td width=\"100\" valign=\"top\">
           <div class=\"box\">
               menu content
           </div>
        </td>
    </tr>
    </table>
</body>
</html>
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-