html - 如何在不弄乱页脚的情况下将两个 div 并排放置
问题描述
这是我的 HTML,我想将 £first 放在 £second 旁边,但是当我尝试使用 float:left; 时,我的页脚会忽略我的内容并移动到我的页面顶部。有没有办法解决这个问题?
<!DOCTYPE html>
<html>
<link rel = "stylesheet" href = "style.css">
<head>
<title>Home</title>
</head>
<body bgcolor="lightgrey">
<header>
<h1>
HEADING
</h1>
</header>
</div id="wrapper">
<div id="first">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</div>
<div id="second">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<footer>
Footer text here
</footer>
</body>
</html>
这是CSS。我设法通过添加 display: flex; 来解决页脚问题。在 body 和 flex-direction: 列上;但现在 div 不会彼此相邻
body{
min-height: 100vh;
display: flex;
flex-direction: column;
}
header{
padding: 10px;
background-color: black;
height: 70px;
opacity: 80%;
}
footer{
padding: 10px;
background-color: black;
height: 70px;
opacity: 80%;
color: white;
margin-top: auto;
}
}
#wrapper {
display: flex;
}
解决方案
您的 div 中有错字
</div id="wrapper">
应该是<div id="wrapper">
body {
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
padding: 10px;
background-color: black;
height: 70px;
opacity: 80%;
}
footer {
padding: 10px;
background-color: black;
height: 70px;
opacity: 80%;
color: white;
margin-top: auto;
}
#first {
border: 1px solid blue;
}
#second {
border: 1px solid red;
}
#wrapper {
display: flex;
}
<body bgcolor="lightgrey">
<header>
<h1>
HEADING
</h1>
</header>
<div id="wrapper">
<div id="first">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div id="second">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<footer>
Footer text here
</footer>
</body>
</html>
推荐阅读
- sql - 如何修复 SQL 错误“将数据类型 varchar 转换为数字时出错”?
- django - 使用实例将数据保存到 Django 中的数据库的问题
- persistent-memory - 区分易失性和持久性变量,它会影响正确性吗?
- sharepoint - Sharepoint 无缘无故地显示“正在努力”
- python - Pandas - 如果观察到另一列 (col B) 中的条件,则使用来自另一列 (col A) 的值创建一列 (col C)
- python - 用于多个匹配的 Python 正则表达式
- php - 如何用 PHP 去除问号(字符串)
- python - 如何在 Django 中用 HTML 编写 python 代码?
- react-native - 推送通知中的自定义操作按钮反应原生android
- c# - 如何使用 c# 中的 poco 类和用于 UWP 应用程序的 xaml 显示 json 值