html

HTML & CSS - Basics

Jun 14, 2020

html & css 기본

사전작업

HTML Basics

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="description" content="welcome to my website" />
    <title>Document</title>
  </head>
  <body>
    <sction>
      <header id="headerNumberOne" class="defaultHeader">
        <h1>Title of a section</h1>
      </header>
    </sction>
    <div>
      <header id="differHeader" class="dafaultHeader">
        Title of unknown container
      </header>
    </div>
  </body>
</html>

CSS Basics

<head>
  <link rel="stylesheet" href="style.css" />
</head>
// style.css
body {
  background-color: aqua;
}

h1 {
  color: azure;
}

boxmodel

.box {
  background-color: yellow;
  width: 50%;
  height: 50%;
  padding-top: 50px;
  padding-left: 50px;
  margin-top: 50px;
  margin-left: 50px;
  margin: 20px; // all
  margin: 20px 10px; // top/bottom, left/right
  margin: 20px 10px 5px 2px; // top, right, bottom, left
}
.inside-box {
  background-color: blue;
  width: 50%;
  height: 50%;

  // border
  border-width: 5px;
  border-color: red;
  border-style: dashed;
}

Display

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Display Example</title>
    <style>
      .box1 {
        background-color: chartreuse;
        width: 50px;
        height: 50px;
        border-style: solid;
        border-color: black;
        border-width: 2px;
      }
      .box2 {
        background-color: royalblue;
        width: 50px;
        height: 50px;
        border-style: solid;
        border-color: black;
        border-width: 2px;
        display: inline;
      }
      .box3 {
        background-color: orange;
        width: 50px;
        height: 50px;
        border-style: solid;
        border-color: black;
        border-width: 2px;
        display: inline-block;
      }
    </style>
  </head>
  <body>
    <h1>Block</h1>
    <div class="box1">1</div>
    <div class="box1">2</div>
    <div class="box1">3</div>
    <h1>inline</h2>
    <span class="box2">1</span>
    <span class="box2">2</span>
    <span class="box2">3</span>
    <h1>inline-block</h1>
    <span class="box3">1</span>
    <span class="box3">2</span>
    <span class="box3">3</span>
  </body>
</html>

display

Position

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style>
      body,
      html {
        /* 브라우저가 갖고 있는 디폴트 값을 상쇄시킴 */
        height: 100%;
        margin: 0;
        padding: 0;
      }
      body {
        height: 400%;
        background-color: red;
      }
      #static {
        height: 300px;
        width: 300px;
        background-color: yellow;
        position: static;
      }
      #fixed {
        height: 300px;
        width: 300px;
        background-color: green;
        position: fixed;
        bottom: 10px;
      }
      #abs-box {
        height: 400px;
        width: 400px;
        background-color: hotpink;
        position: relative;
      }
      #abs-child {
        width: 100px;
        height: 100px;
        background-color: black;
        position: absolute;
        right: 0;
        top: 10px;
      }
    </style>
  </head>
  <body>
    <div id="static">
      <div class="box-chid"></div>
    </div>
    <div id="fixed">
      <div class="box-chid"></div>
    </div>
    <div id="abs-box">
      <div id="abs-child"></div>
    </div>
  </body>
</html>