html - 在 div 中添加大量文本时,下一个元素会向下移动
问题描述
我正在使用弹性 div。现在,当我在其中添加大量文本时,它会使 div 接近移动并失去位置,希望你们能帮忙。
正如您在图片中看到的那样,没有太多文本,一切正常,但是有点 lorem,一切都变糟了——即使我在每个 div 上使用了 3 的 flex-grow,div 内的大小也会发生变化
html:
<section id='portfolio'>
<h1>My Projects</h1>
<div class="slider">
<div class="left">
<span class="left-arrow"></span> </div>
<ul>
<li class="slider-item">
<div class="app">
<img src="./images/movies.jpg" alt="">
<ul>
<li>Name: Movies WebApp</li>
<li>Description: Manage movise stock Lorem, ipsum dolor sit amet consectetur adipisicing elit. Molestiae asperiores obcaecati quaerat fugit nisi dolore optio possimus facere ratione, maiores dicta earum aut tempora unde facilis vitae vero, quas totam.</li>
<li>Backend: -</li>
<li>Frontend: Angular, CSS, Html</li>
<li>DB: -</li>
</ul>
</li>
</ul>
<div class="right"><span class="right-arrow"></span></div>
<ol class="pagination">
</ol>
</div>
</div>
</section>
CSS:
.slider {
min-width: 100%;
flex-wrap: wrap;
display: flex;
justify-content: center;
}
.slider ul {
flex-grow: 10;
min-height: 300px;
justify-content: center;
}
.slider ul .slider-item {
min-height: 300px;
display: flex;
position: relative;
}
.app {
padding: 20px;
width: 100%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background-color: rgb(0, 0, 0);
overflow: hidden;
box-sizing: border-box;
}
.app img {
min-width: 500px;
height: 300px;
flex-grow: 3;
}
.app ul {
overflow: hidden;
display: flex;
flex-direction: column;
margin-left: 20px;
color: black;
width: 100%;
flex-grow: 3;
justify-content: center;
background-color: aqua;
}
.app ul li {
flex-grow: 1;
}
.right,
.left {
padding: 20px;
flex-grow: 1;
position: relative;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
transition: 0.3s;
position: relative;
min-width: 40px;
flex-wrap: nowrap;
}
.left-arrow {
position: absolute;
left: 30px;
width: 20px;
height: 20px;
border-left: 2px solid rgb(163, 163, 163);
border-bottom: 2px solid rgb(163, 163, 163);
transform: rotate(45deg);
cursor: pointer;
transition: 0.3s;
}
.right-arrow {
position: absolute;
right: 30px;
width: 20px;
height: 20px;
border-right: 2px solid rgb(163, 163, 163);
border-bottom: 2px solid rgb(163, 163, 163);
transform: rotate(-45deg);
cursor: pointer;
transition: 0.5s;
}
解决方案
.slider {
min-width: 100%;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.slider > ul {
padding-left: 0;
width: calc(100% - 160px);
}
.slider ul {
flex-grow: 10;
min-height: 300px;
justify-content: center;
}
.slider ul .slider-item {
min-height: 300px;
display: flex;
position: relative;
}
.app {
padding: 20px;
width: 100%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background-color: rgb(0, 0, 0);
overflow: hidden;
box-sizing: border-box;
}
.app img {
min-width: 500px;
height: 300px;
flex-grow: 3;
}
.app ul {
overflow: hidden;
display: flex;
flex-direction: column;
margin-left: 20px;
color: black;
width: 100%;
flex-grow: 3;
justify-content: center;
background-color: aqua;
}
.app ul li {
flex-grow: 1;
}
.right,
.left {
padding: 20px;
flex-grow: 1;
position: relative;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
transition: 0.3s;
position: relative;
min-width: 40px;
flex-wrap: nowrap;
}
.left-arrow {
position: absolute;
left: 30px;
width: 20px;
height: 20px;
border-left: 2px solid rgb(163, 163, 163);
border-bottom: 2px solid rgb(163, 163, 163);
transform: rotate(45deg);
cursor: pointer;
transition: 0.3s;
}
.right-arrow {
position: absolute;
right: 30px;
width: 20px;
height: 20px;
border-right: 2px solid rgb(163, 163, 163);
border-bottom: 2px solid rgb(163, 163, 163);
transform: rotate(-45deg);
cursor: pointer;
transition: 0.5s;
}
<section id='portfolio'>
<h1>My Projects</h1>
<div class="slider">
<div class="left">
<span class="left-arrow"></span> </div>
<ul>
<li class="slider-item">
<div class="app">
<img src="./images/movies.jpg" alt="">
<ul>
<li>Name: Movies WebApp</li>
<li>Description: Manage movise stock Lorem, ipsum dolor sit amet consectetur adipisicing elit. Molestiae asperiores obcaecati quaerat fugit nisi dolore optio possimus facere ratione, maiores dicta earum aut tempora unde facilis vitae vero, quas totam. </li>
<li>Backend: -</li>
<li>Frontend: Angular, CSS, Html</li>
<li>DB: -</li>
</ul>
</li>
</ul>
<div class="right"><span class="right-arrow"></span></div>
<ol class="pagination">
</ol>
</div>
</div>
</section>
推荐阅读
- jquery - 我想在我的 wordpress 网站中使用社交媒体插件获取详细信息
- python - 我重新启动后,Gmail SMTP 服务器已停止发送电子邮件
- mysql - 如何在不丢失 Mysql 中的数据的情况下更改列数据类型
- r - R中指定的向量大小太大
- python - 具有不同持续时间的事件的直方图(给定它们的开始和结束时间)
- java - 带有 Microsoft 错误的 Firebase 身份验证
- c++ - 即使文件在该位置不存在,ifstream::is_open 也会返回 true
- autodesk-forge - 使用滚轮时如何设置枢轴点?
- google-sheets - 包含日期操作的查询函数 [DATE + X 月数]
- java - 如何修复 tzdb.dat 在 java 中未找到错误?