html - 所有浏览器中 html 中的 div 问题

标签 html css

我有两个 html 代码。在第一个代码背景中没有出现。但是在第二个代码中,当我输入 clear:both; 代码时,背景就来了。你能有任何替代的简单选项来显示背景而不是高度吗?我不想放置高度和额外的 div 结构。

第一个代码:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-    transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<!-- please dont use height in background -->
<body>
<div style="background:#990000;">
<div style="float:left;">left part</div>
<div style="float:right">right part</div>
</div>
</body>
</html>

第二个代码:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<!-- please dont use height in background -->
<body>
<div style="background:#990000;">
<div style="float:left;">left part</div>
<div style="float:right">right part</div>
<div style="clear:both"></div>
</div>
</body>
</html>

非常感谢您的回复。提前致谢。

最佳答案

请尝试下面给出的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-    transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<!-- please dont use height in background -->
 <body>
 <div style="background-color:#999000;overflow:hidden;">
        <div style="float:left;">left part</div>
        <div style="float:right">right part</div>
 </div>
 </body>
 </html>

添加溢出:隐藏。这将是工作。

谢谢

关于html - 所有浏览器中 html 中的 div 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12889555/

相关文章:

html - 在 ShinyDashboardPlus 中完全折叠左侧边栏

javascript - 如何在Windows8移动应用程序中禁用触摸覆盖

css - 如何断线? (和 safari 移动问题)

html - html z-index 中的图像标签可以位于 css 背景图像后面吗?

css - 导航栏未显示在网站的第二页上

javascript - 如何使用 jquery/ajax 加载同一页面?

javascript - 视频全屏触发滚动事件

css - 如何获取使用 ExCSS 解析的 CSS 的十六进制代码

javascript - 使用 CSS 的动态 float 布局

browser - 为什么浏览器要使用前缀?