如何修复破坏布局的容器 div?
How do I fix the container div that ruined the layout?
完成侧边栏的工作后,我想转到右侧的内容页面,所以我添加了一个容器 div,我想将其设置为 flex 这样我就可以让两个框开始样式,但在添加它之后,页脚的位置被破坏了,侧边栏没有占用应有的空间 space。
这是一张照片:
.side-bar {
font-family: 'Montserrat', sans-serif;
font-size: large;
font-weight: bold;
display: flex;
justify-content: left;
background-color: rgb(235, 235, 235);
width: 20%;
height: 80%;
flex-direction: column;
}
.side-bar ul {
display: flex;
flex-direction: column;
margin-left: 0%;
list-style: none;
margin-top: 5%;
}
.side-bar ul li {
margin-bottom: 10px;
display: inline;
cursor: pointer;
}
.togglable:hover {
border-radius: 7px;
background-color: rgb(216, 216, 216);
}
.togglable:active {
background-color: rgb(221, 221, 221);
}
.side-bar ul a {
color: black;
text-decoration: none;
}
.side-bar h2 {
font-family: 'Josefin Sans', sans-serif;
margin-bottom: 20px;
}
.container {
display: flex;
}
.task-container {
background-color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ToDoList</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="nav-bar">
<img src="logo.png" alt="logo">
<nav>
<ul>
<li><a href="#">Services</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
<a class="cta" href="#"><button>Contact</button></a>
</div>
<div class="container">
<div class="side-bar">
<ul>
<li class="togglable"><img src="gym.png" alt="gym" id="gym"><a href="#">Gym</a></li>
<li class="togglable"><img src="today.png" alt="calendar" id="today"> <a href="#">Today</a></li>
<li class="togglable"><img src="week.png" alt="calendar" id="week"><a href="#">This Week</a></li>
<li class="togglable"><img src="month.png" alt="calendar" id="month"> <a href="#">This Month</a></li>
<h2>Projects : </h2>
<li id="addPr" class="togglable"><a href="#"><span id="plus-sgn">+</span> Add Project</a></li>
<!-- <li class="togglable"><img src="checklist.png" alt="checlist" id="list"> <a href="#">Testing</a></li> -->
</ul>
</div>
<div class="task-container">
<p>Some Text To test the box</p>
</div>
</div>
<div class="footer">
<p id="copyright">Copyright © 2021 FaroukHamadi</p>
</div>
<script src="main.js"></script>
</body>
</html>
向任务容器添加宽度属性,并在 CSS 文件中添加页脚 class 属性。
.task-container {
background-color: red;
width: 100%;
}
.footer{
position: absolute;
bottom: 0px;
width: auto;
}
完成侧边栏的工作后,我想转到右侧的内容页面,所以我添加了一个容器 div,我想将其设置为 flex 这样我就可以让两个框开始样式,但在添加它之后,页脚的位置被破坏了,侧边栏没有占用应有的空间 space。
这是一张照片:
.side-bar {
font-family: 'Montserrat', sans-serif;
font-size: large;
font-weight: bold;
display: flex;
justify-content: left;
background-color: rgb(235, 235, 235);
width: 20%;
height: 80%;
flex-direction: column;
}
.side-bar ul {
display: flex;
flex-direction: column;
margin-left: 0%;
list-style: none;
margin-top: 5%;
}
.side-bar ul li {
margin-bottom: 10px;
display: inline;
cursor: pointer;
}
.togglable:hover {
border-radius: 7px;
background-color: rgb(216, 216, 216);
}
.togglable:active {
background-color: rgb(221, 221, 221);
}
.side-bar ul a {
color: black;
text-decoration: none;
}
.side-bar h2 {
font-family: 'Josefin Sans', sans-serif;
margin-bottom: 20px;
}
.container {
display: flex;
}
.task-container {
background-color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ToDoList</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="nav-bar">
<img src="logo.png" alt="logo">
<nav>
<ul>
<li><a href="#">Services</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
<a class="cta" href="#"><button>Contact</button></a>
</div>
<div class="container">
<div class="side-bar">
<ul>
<li class="togglable"><img src="gym.png" alt="gym" id="gym"><a href="#">Gym</a></li>
<li class="togglable"><img src="today.png" alt="calendar" id="today"> <a href="#">Today</a></li>
<li class="togglable"><img src="week.png" alt="calendar" id="week"><a href="#">This Week</a></li>
<li class="togglable"><img src="month.png" alt="calendar" id="month"> <a href="#">This Month</a></li>
<h2>Projects : </h2>
<li id="addPr" class="togglable"><a href="#"><span id="plus-sgn">+</span> Add Project</a></li>
<!-- <li class="togglable"><img src="checklist.png" alt="checlist" id="list"> <a href="#">Testing</a></li> -->
</ul>
</div>
<div class="task-container">
<p>Some Text To test the box</p>
</div>
</div>
<div class="footer">
<p id="copyright">Copyright © 2021 FaroukHamadi</p>
</div>
<script src="main.js"></script>
</body>
</html>
向任务容器添加宽度属性,并在 CSS 文件中添加页脚 class 属性。
.task-container {
background-color: red;
width: 100%;
}
.footer{
position: absolute;
bottom: 0px;
width: auto;
}