Flexbox布局无法响应

时间:2016-12-01 20:31:29

标签: css layout flexbox

我正在努力使这个响应,并在我更改屏幕尺寸时缩小它们。然而,对齐不能正常工作,我不知道问题是什么。

#noteUIContainer {
  display: flex;
  position: absolute;
  bottom: 0px;
  top: 55px;
  width: 100%
}
#noteList {
  width: 175px;
  flex: 1;
  /* The below change allows you to scroll the note preview */
  overflow-y: auto;
  background-color: rgb(242, 242, 242);
  border-right: 1px rgb(30, 30, 30) solid;
  /* Make changes below this line */
}
#note {
  flex: 3;
  padding-left: 20px;
  /* Make changes below this line */
}
#header {
  background-color: black;
  color: white;
  padding: 18px;
  /* Make changes below this line */
}
.notePreview {
  height: 70px;
  border-bottom: 1px rgb(30, 30, 30) solid;
  line-height: 90%;
  border-top: 15px rgb(209, 209, 209) solid;
}
.notePreview h3 {
  font-size: 12pt;
  line-height: inherit;
  font-weight: 400;
}
.notePreviewText {
  font-size: 9pt;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  padding-bottom: 26px;
  border-bottom: 1px rgb(30, 30, 30) solid;
}
#dateModified {
  color: rgb(128, 128, 128);
  font-size: 10pt;
  padding-top: 20px;
}
body {
  margin: auto;
  font-family: sans-serif;
}
/*
    Add any relevant styles below here.
    */

#note h3 {
  font-weight: bold;
  padding-top: 20px;
  border-bottom: 1px rgb(30, 30, 30) solid;
}
<div id="header">
  Elephant - Your Notes
</div>
<div id="noteUIContainer">
  <div id="noteList">
    <div class="notePreview">
      <h3>HTML Notes</h3>
      <p class="notePreviewText">
        In HTML, you will always want to have the html, body, and head tag.
      </p>
    </div>
    <div class="notePreview">
      <h3>CSS Notes</h3>
      <p class="notePreviewText">
        CSS offers some great features in stylizing your HTML.
      </p>
    </div>
    <div class="notePreview">
      <h3>FlexBox Notes</h3>
      <p class="notePreviewText">
        With flexbox, you can create some pretty awesome layouts!
      </p>
    </div>
    <div class="notePreview">
      <h3>JavaScript Notes</h3>
      <p class="notePreviewText">
        JavaScript can really bring a web page to life.
      </p>
    </div>
    <div class="notePreview">
      <h3>PHP Notes</h3>
      <p class="notePreviewText">
        PHP is a very flexible language and easy to learn!
      </p>
    </div>
    <div class="notePreview">
      <h3>Database Notes</h3>
      <p class="notePreviewText">
        We have to be careful when creating our database schema.
      </p>
    </div>
    <div class="notePreview">
      <h3>Session State Notes</h3>
      <p class="notePreviewText">
        HTTP does not remember anything, so we have to do it with session.
      </p>
    </div>
  </div>
  <div id="note">
    <h3>HTML Notes</h3>
    <span id="dateModified">Date Modified: July 12th 2054</span>
    <br />
    <p>
      In HTML, you will always want to have the html, body, and head tag.
    </p>
    <textarea rows="15" cols="75">
    </textarea>
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

您应该将flex-wrap设置为主容器,然后min-width而不是width设置为第一个容器:

#noteUIContainer {
  display: flex;
  flex-wrap: wrap;
}
#noteList {
  min-width: 175px;
  flex: 1;
  overflow-y: auto;
  background-color: rgb(242, 242, 242);
  border-right: 1px rgb(30, 30, 30) solid;
  /* Make changes below this line */
}
#note {
  flex: 3;
  padding-left: 20px;
  /* Make changes below this line */
}
#header {
  background-color: black;
  color: white;
  padding: 18px;
  /* Make changes below this line */
}
.notePreview {
  height: 70px;
  border-bottom: 1px rgb(30, 30, 30) solid;
  line-height: 90%;
  border-top: 15px rgb(209, 209, 209) solid;
}
.notePreview h3 {
  font-size: 12pt;
  line-height: inherit;
  font-weight: 400;
}
.notePreviewText {
  font-size: 9pt;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  padding-bottom: 26px;
  border-bottom: 1px rgb(30, 30, 30) solid;
}
#dateModified {
  color: rgb(128, 128, 128);
  font-size: 10pt;
  padding-top: 20px;
}
body {
  margin: auto;
  font-family: sans-serif;
}
/*
    Add any relevant styles below here.
    */

#note h3 {
  font-weight: bold;
  padding-top: 20px;
  border-bottom: 1px rgb(30, 30, 30) solid;
}
<div id="header">
  Elephant - Your Notes
</div>
<div id="noteUIContainer">
  <div id="noteList">
    <div class="notePreview">
      <h3>HTML Notes</h3>
      <p class="notePreviewText">
        In HTML, you will always want to have the html, body, and head tag.
      </p>
    </div>
    <div class="notePreview">
      <h3>CSS Notes</h3>
      <p class="notePreviewText">
        CSS offers some great features in stylizing your HTML.
      </p>
    </div>
    <div class="notePreview">
      <h3>FlexBox Notes</h3>
      <p class="notePreviewText">
        With flexbox, you can create some pretty awesome layouts!
      </p>
    </div>
    <div class="notePreview">
      <h3>JavaScript Notes</h3>
      <p class="notePreviewText">
        JavaScript can really bring a web page to life.
      </p>
    </div>
    <div class="notePreview">
      <h3>PHP Notes</h3>
      <p class="notePreviewText">
        PHP is a very flexible language and easy to learn!
      </p>
    </div>
    <div class="notePreview">
      <h3>Database Notes</h3>
      <p class="notePreviewText">
        We have to be careful when creating our database schema.
      </p>
    </div>
    <div class="notePreview">
      <h3>Session State Notes</h3>
      <p class="notePreviewText">
        HTTP does not remember anything, so we have to do it with session.
      </p>
    </div>
  </div>
  <div id="note">
    <h3>HTML Notes</h3>
    <span id="dateModified">Date Modified: July 12th 2054</span>
    <br />
    <p>
      In HTML, you will always want to have the html, body, and head tag.
    </p>
    <textarea rows="15" cols="75">
    </textarea>
  </div>
</div>

如果您希望将明细片包裹在1列中,则可以使用:flex-directionorder

#noteUIContainer {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row-reverse;
}
#noteList {
  min-width: 175px;
  flex: 1;
  overflow-y: auto;
  background-color: rgb(242, 242, 242);
  border-right: 1px rgb(30, 30, 30) solid;
  /* Make changes below this line */
}
#note {
  order: -1;
  flex: 3;
  padding-left: 20px;
  /* Make changes below this line */
}
#header {
  background-color: black;
  color: white;
  padding: 18px;
  /* Make changes below this line */
}
.notePreview {
  height: 70px;
  border-bottom: 1px rgb(30, 30, 30) solid;
  line-height: 90%;
  border-top: 15px rgb(209, 209, 209) solid;
}
.notePreview h3 {
  font-size: 12pt;
  line-height: inherit;
  font-weight: 400;
}
.notePreviewText {
  font-size: 9pt;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  padding-bottom: 26px;
  border-bottom: 1px rgb(30, 30, 30) solid;
}
#dateModified {
  color: rgb(128, 128, 128);
  font-size: 10pt;
  padding-top: 20px;
}
body {
  margin: auto;
  font-family: sans-serif;
}
/*
    Add any relevant styles below here.
    */

#note h3 {
  font-weight: bold;
  padding-top: 20px;
  border-bottom: 1px rgb(30, 30, 30) solid;
}
<div id="header">
  Elephant - Your Notes
</div>
<div id="noteUIContainer">
  <div id="noteList">
    <div class="notePreview">
      <h3>HTML Notes</h3>
      <p class="notePreviewText">
        In HTML, you will always want to have the html, body, and head tag.
      </p>
    </div>
    <div class="notePreview">
      <h3>CSS Notes</h3>
      <p class="notePreviewText">
        CSS offers some great features in stylizing your HTML.
      </p>
    </div>
    <div class="notePreview">
      <h3>FlexBox Notes</h3>
      <p class="notePreviewText">
        With flexbox, you can create some pretty awesome layouts!
      </p>
    </div>
    <div class="notePreview">
      <h3>JavaScript Notes</h3>
      <p class="notePreviewText">
        JavaScript can really bring a web page to life.
      </p>
    </div>
    <div class="notePreview">
      <h3>PHP Notes</h3>
      <p class="notePreviewText">
        PHP is a very flexible language and easy to learn!
      </p>
    </div>
    <div class="notePreview">
      <h3>Database Notes</h3>
      <p class="notePreviewText">
        We have to be careful when creating our database schema.
      </p>
    </div>
    <div class="notePreview">
      <h3>Session State Notes</h3>
      <p class="notePreviewText">
        HTTP does not remember anything, so we have to do it with session.
      </p>
    </div>
  </div>
  <div id="note">
    <h3>HTML Notes</h3>
    <span id="dateModified">Date Modified: July 12th 2054</span>
    <br />
    <p>
      In HTML, you will always want to have the html, body, and head tag.
    </p>
    <textarea rows="15" cols="75">
    </textarea>
  </div>
</div>

您可以展示然后在整页中运行两个片段,并调整浏览器的大小,使其看到它从一个col跳到2

P.S。 我删除了绝对定位,没有在这里看到目的:),但如果你把它放回去将会有效