Catalina
Catalina

Reputation: 101

Flexbox layout not being responsive

I am trying to make this responsive and have both of them scale down when I change the screen size. However the alignment doesn't work properly and I don't know what the problem is.

#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>

Upvotes: 0

Views: 6969

Answers (1)

G-Cyrillus
G-Cyrillus

Reputation: 106058

You should set flex-wrap to the main container and then min-width instead width to the first-col:

#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>

if you want the notelist last when wrapping in 1 col, you may use: flex-direction and order

#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>

You can show then run both snippets in full page and resize your browser to see it jumping from one col to 2.

p.s. i removed the absolute positionning, did not see the purpose here :), but will work if you put it back

Upvotes: 1

Related Questions