我的CSS搞乱了滚动工作正常

时间:2020-07-03 20:10:49

标签: html css

我有此设置https://codepen.io/saraLance/pen/LYGevXW,但遇到了一些问题。

  1. summarize_all的覆盖范围超过了父宽度。
  2. 滚动工作很奇怪,似乎在按钮header之后停了下来,然后我不得不再次滚动。

我试图解决滚动问题,使play固定为header,但是position: fixed; width: 100%的覆盖范围比父div还要多。

我也不知道为什么header的高度与父screen的高度不同。

理想情况下,screens应该在sit-container之后,并且header应该是固定的。

header
div {
  width: auto;
}

.screens {
  background: green;
  height: 100vh;
  display: flex;
  overflow-x: hidden;
  overflow-y: auto;
}

.screen {
  background: red;
}

.header {
  border: solid 1px black;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-evenly;
  padding: 12px;
  background: white;
}

.sit-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 1rem;
  overflow: auto;
}

.strip {
  width: 100vw;
}

.view {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 300px;
  min-width: 300px;
  animation-delay: 0.2s;
  overflow-y: scroll;
  flex-direction: column;
}

.view-1 {
  height: 300px;
  width: 300px;
  flex: 0 0 auto;
  margin: 0 auto;
  margin-top: 1rem;
  border: solid 1px black;
}

.button-section {
  display: flex;
  flex-direction: column;
  text-align: center;
  margin-top: 1rem;
  width: 100%;
}

.play-button {
  height: 1.25rem;
  display: flex;
  justify-content: center;
  align-items: center;
  color: black;
  border: 1px solid black;
  text-decoration: none;
  padding: 1rem 1.25rem;
  line-height: 1rem;
  border-radius: 0.375rem;
  font-size: 1rem;
  font-style: normal;
  font-weight: normal;
  text-align: center;
  text-transform: uppercase;
  margin: 1rem;
}

.quit-button {
  color: black;
  text-decoration: none;
  font-size: 1.2rem;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid black;
}

1 个答案:

答案 0 :(得分:0)

screens类应为width: auto,而overflow-x:hidden应在button-section
全屏查看输出

div {
  width: auto;
}

@media (min-width: 768px) {
  width:35%;
  margin:auto;
}

.screens {
  background: green;
  height:"auto";
  display: flex;
}

.screen {
  background: red;
}

.header {
  border: solid 1px black;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-evenly;
  padding: 12px;
  background: white;
}

.sit-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 1rem;
  overflow: auto;
}

.strip {
  width: 100vw;
  @media (min-width: 768px) {
    width: 35vw;
  }
}

.view {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 300px;
  min-width: 300px;
  animation-delay: 0.2s;
  overflow-y: scroll;
  flex-direction: column;
}

.view-1{
  height: 300px;
  width: 300px;
  flex: 0 0 auto;
  margin: 0 auto;
  margin-top: 1rem;
  border: solid 1px black;
}

.button-section{  
  display: flex;
  flex-direction: column;
  text-align: center;
  margin-top: 1rem;
  width: 100%;
  overflow-x:hidden;
}

.play-button {
  height: 1.25rem;
  display: flex;
  justify-content: center;
  align-items: center;
  color: black;
  border: 1px solid black;
  text-decoration: none;
  padding: 1rem 1.25rem;
  line-height: 1rem;
  border-radius: 0.375rem;
  font-size: 1rem;
  font-style: normal;
  font-weight: normal;
  text-align: center;
  text-transform: uppercase;
  margin: 1rem;
}

.quit-button {
  color: black;
  text-decoration: none;
  font-size: 1.2rem;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid black;
}
<div class="screens">
  <div class="screen">
    <div class="header">
      <div class="div-1">Div-1</div>
      <div class="div-1">Div-2</div>
    </div>
    <div class="sit-container">
      <div class="strip">
        <div class="view">
          <div class="view-1">View-1</div>
          <div class="view-1">View-2</div>
          <div class="view-1">View-3</div>
          <div class="view-1">View-4</div>
        </div>
      </div>
      <div class="button-section">
        <a class="play-button">Play</a>
        <a class="quit-button">Quit</a>
      </div>
    </div>
  </div>
</div>