html - 当在 div 中添加大量文本时,下一个元素会向下移动

标签 html css

我使用的是 flex div。现在,当我在其中添加大量文本时,不知何故会使 div 接近移动并失去它们的位置,希望你们能帮忙。

图一: enter image description here

图二: enter image description here

正如您在图片中看到的那样,没有太多文本的地方一切正常,但有一点点定数,一切都变坏了 - 即使我在每个 flex-grow 上使用 3,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>

关于html - 当在 div 中添加大量文本时,下一个元素会向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53334242/

相关文章:

html - 只运行一次 CSS 动画

jquery - 'Card' 沿Y轴旋转180度

html - <td> 下面不需要的巨大空间

css - Font Awesome 5 在使用 JS+SVG 版本时显示空方 block

security - HTML5 中的注册机标签

jquery - 包含列表(家谱)的可滚动 div

javascript - 使用 AngularJS 如何在 Accordion 中显示新数据而不重新加载页面

html - 如何使用 html 和 css 创建这个特定的投资组合名片

html - 根据高度最大化字体大小

css - Bootstrap 4.0 自定义汉堡图标