css - 一切都进入 flex 容器

标签 css containers flexbox

对于编码来说真的很陌生,我一直在为我正在从事的元素使用 flex 容器。我遇到的问题是,我在容器样式之后放入代码中的所有内容似乎都在容器中结束。我想知道如何停止这个或启动一个新容器。这是我正在查看的代码:

<style>
.flex-container {
    display: -webkit-flex;
    display: flex;
    width: 100%;
    height: 500px;
    background-color: lightgreen;
margin: 0px;
}

.flex-right{
float: right;
 background-color: none;
    width: 700px;
    height: 100%;
    margin: auto;

}
.flex-left{
    background-color: none;
    width: 800px
    height: 100%;
    margin: 15px 90px;
float: left
}
</style>
<body>

<div class="flex-container">
  <div class="flex-left"><img src="sample trainer.png" width="400" height="475" alt="" border="0"></div>
  <div class="flex-right">
<h1><span style="font-family: Arial; font-weight: bold; font-style: normal; text-decoration: none; font-size: 30pt;">Sample Text Here</span></h>

<p><span style="font-family: Arial; font-weight: normal; font-style: italic; text-decoration: none; font-size: 24pt;">More Sample Text here</span></p>
</div>
</body>
</html>

<div id="footer">Ending</div>

当我在浏览器中查看它时,我看到页脚最终出现在 flex.container 中

我希望有人能帮我解决这个问题。

谢谢!

最佳答案

您忘记关闭您的 flex-container div 与 </div>在页脚之前。确保在关闭之前保留所有 HTML </body>标签。您那里还有其他无效代码,例如 </h>而不是 </h1> , 所以要小心检查你的语法。

同时避免内联 CSS(包括那些不必要的 span 元素)。请记住,您真的不想 float flex 容器的内容,因为 flex 布局实际上是 float 布局的替代方案。

.flex-container {
    display: -webkit-flex;
    display: flex;
    width: 100%;
    height: 500px;
    background-color: lightgreen;
margin: 0px;
}

.flex-right{
float: right;
 background-color: none;
    width: 700px;
    height: 100%;
    margin: auto;

}
.flex-left{
    background-color: none;
    width: 800px
    height: 100%;
    margin: 15px 90px;
float: left
}
<div class="flex-container">
  <div class="flex-left"><img src="sample trainer.png" width="400" height="475" alt="" border="0"></div>
  <div class="flex-right">
    <h1><span style="font-family: Arial; font-weight: bold; font-style: normal; text-decoration: none; font-size: 30pt;">Sample Text Here</span>
    </h1>

<p><span style="font-family: Arial; font-weight: normal; font-style: italic; text-decoration: none; font-size: 24pt;">More Sample Text here</span></p>
</div>
</div>

<div id="footer">Ending</div>

关于css - 一切都进入 flex 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36831821/

相关文章:

docker - Gitlab Docker Postfix从 “boot”开始

css - 使用 flexbox 的水平滚动页面

html - 为什么我的 Visual Studio Code Live Server 在保存时跳转到页面的特定部分?

html - 基于 Bootstrap 的导航以及下拉支持,以使用全宽显示均匀间隔的导航

c++ - std::vector 应该尊重 alignof(value_type) 吗?

python - Azure 容器实例部署失败

javascript - 在 ASP.NET Web 窗体中缩小和捆绑 CSS 时出现 "403 - Forbidden: Access is denied"错误

jquery - 如何测试jquery是否正确加载?

javascript - 如何将 HTML 字符串插入到 div 容器中,并在 "flex-wrap"行中显示这些容器?

html - 如何在 Safari 中将 flex 容器的绝对定位子项居中?