html - 页面呈现为空。为什么?

标签 html css

我正在学习 HTML5 和 CSS 3(新手)。当我浏览书中的示例时,我遇到了渲染问题。

我想做的是: 创建一个人造列。

工作样本:

<!doctype html>
<html>
    <head>
        <title>Faux Columns</title>
        <style>
            .container{
                background: black;
                color: #fff;
            }
            .container::after{
                content: ' ';
                clear: both;
                display: block;
            }
            .col{
                float: left;
                width: 50%;
            }
        </style>
    </head>

    <body>
        <div class="container">
            <aside class="col">
                Aside
            </aside>
            <div class="col main">
                Main Content Area
            </div>
        </div>
    </body>
</html>

运行脚本,可以看到两列。

现在运行这个脚本,

<!doctype html>
<html>
    <head>
        <title>Faux Columns</title>
        <style>
            .container{
                background: black;
                color: #fff;
            }
            .col{
                float: left;
                width: 50%;
            }
        </style>
    </head>

    <body>
        <div class="container">
            <aside class="col">
                Aside
            </aside>
            <div class="col main">
                Main Content Area
            </div>
        </div>
    </body>
</html>

为什么上面没有渲染?

  1. 我做错了什么?
  2. 此外,在工作示例中,::after 是什么?
  3. 在工作示例 CSS 内容中:“”;为什么这样设置?
  4. 该工作示例 CSS 实际上做了什么?

根据一些评论,我只是更改了父容器中的颜色。

<!doctype html>
<html>
    <head>
        <title>Faux Columns</title>
        <style>
            .container{
                background: black;
                color: red;
            }
            .col{
                float: left;
                width: 50%;
            }
        </style>
    </head>

    <body>
        <div class="container">
            <aside class="col">
                Aside
            </aside>
            <div class="col main">
                Main Content Area
            </div>
        </div>
    </body>
</html>

现在我可以看到两列了。但是没有设置parent的背景色black。

最佳答案

您可以添加 <div style="clear:both;"></div>.col.main之后元素,或添加 overflow: auto;.container

关于html - 页面呈现为空。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33614881/

相关文章:

html - 检测宽度与检测浏览器

html - 当存在 UTF-8 字符编码时,显示引号的问号图标

HTML5 : Is iPhone4's hardware acceleration that much weaker than compared to the 4s?

javascript - CSS:通过鼠标拖动实现双向无限滚动

php - Zend Form 没有放置标签值,如何将它们移动到恰好在文本框上方?

javascript - 多个 Canvas 的 RequestAnimationFrame

javascript - 如何以编程方式关闭 HTML5 表单验证错误消息?

css - 如何在 GWT 中使用 CSS 格式化 ScrollPanel?

html - 获取 <p> 元素来裁剪文本

javascript - 调整浏览器大小时更改占位符