html

HTML & CSS - Flex

Jun 14, 2020

플렉스란?

flex

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Flex</title>
    <style>
      .parents {
        display: flex;
      }
      .box {
        background-color: red;
        height: 200px;
        width: 200px;
      }
    </style>
  </head>
  <body>
    <div class="parents">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
    </div>
  </body>
</html>
<style>
  html,
  body {
    height: 100%;
  }
  .parents {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    flex-direction: column;
  }
  .box {
    background-color: red;
    height: 200px;
    width: 200px;
  }
</style>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Flex</title>
    <style>
      html,
      body {
        height: 100%;
      }
      .parents {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        flex-direction: row-reverse;
        flex-wrap: wrap;
        height: 100%;
      }
      .box {
        background-color: red;
        height: 200px;
        width: 200px;
        border: black;
        border-style: solid;
        border-width: 1px;
        display: flex;
        justify-content: center;
        align-items: center;
        color: white;
      }
    </style>
  </head>
  <body>
    <div class="parents">
      <div class="box">1</div>
      <div class="box">2</div>
      <div class="box">3</div>
      <div class="box">4</div>
      <div class="box">5</div>
      <div class="box">6</div>
      <div class="box">7</div>
      <div class="box">8</div>
      <div class="box">9</div>
      <div class="box">10</div>
    </div>
  </body>
</html>

Selector

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Selectors</title>
    <style>
      input[type="submit"] {
        background-color: red;
      }
      input[type="password"] {
        background-color: blue;
      }

      input[required="required"] {
        background-color: palegreen;
      }
      input {
        border: 1px solid yellow;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box">
        <input type="password" />
        <input type="submit" />
        <input required="required" />
      </div>
    </div>
  </body>
</html>
<style>
  .box:last-child{
    blabla..
  }
  .fist-child, .nth-child(2) // 2번째 자식
  .nth-child(2n) { // 2의 배수 위치한 자식에게 스타일 적용
    asdfasdfasd
  }
</style>
<style>
  input + box { // 서로 형제다
    asdfasdf
  }

  input > box { // direct child 직계

  }
</style>

CSS State

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=f, initial-scale=1.0" />
    <title>css state</title>
    <style>
      .box {
        background-color: red;
        font-size: 40px;
      }
      .box:hover {
        background-color: pink;
      }
      .box:active {
        background-color: green;
      }
      .box:focus {
        background-color: blue;
      }
    </style>
  </head>
  <body>
    <textarea class="box">lalalalala</textarea>
  </body>
</html>

CSS 요약