HTML, CSS 특징

HTML, CSS 특징

February 22, 2020 ( last updated : February 21, 2020 )
html css

https://github.com/gmm117/gmm117.github.io


Abstract

    css 속성 우선순위
    css 마진 중복(collapse)
    box-sizing
    overflow
    font
    float
    position
    flex
    Grid
    background

css 속성 우선순위

<body>
    <div id="color_yellow" class="color_green" style="color : orange;">Hello world</div>
</body>

<!-- div { color : red !imprtant; } /* important */ 
     
     #color_yellow { color : yellow; } /* 아이디 선택자 */

     .color_green { color : green; } /* 클래스 선택자 */

     div { color : blue; } /* 태그 선택자 */

     * { color : darkblue; } /* 전체 선택자 */

     body { color : violet; } /* 상속 */
-->

css 마진 중복(collapse)

개념

마진중복계산

마진중복계산

<body> 
  <div class='child'></div>
  <div class='child'></div>
  <div class='child'></div>
</body>

.child {
  width : 100px;
  height : 100px;
  background : red;
  margin : 20px;
}

마진중복예제

box-sizing

<body> 
  <div class='child'></div>
</body>

.child {
  width : 100px;
  height : 100px;
  background : red;
  padding:20px;
  border:10px solid orange;
  box-sizing : border-box;
}

overflow

<div class='parent'> 
  <div class='child'>1</div>
  <div class='child'>1</div>
  <div class='child'>1</div>
</div>

.parent {
  width : 300px;
  height : 250px;
  border : 4px solid;
  /* overflow : visible; */
  overflow : auto;
}
.child {
  width : 100px;
  height : 100px;
  background : red;
  border:4px solid orange;
  
}

overflow-visible overflow-auto

font

.box {
  font : italic bold 20px / 1.5 "Arial", sans-serif;
}

.box {
  font : 30px / 1.5 sans-serif;
  font : bold 30px sans-serif;
  font : italic 30px / 1.5 "Arial",sans-serif;
}

font-family

글꼴계열

float

<div class="parent clearfix">
  <div class="child>
  /*"" clear:both, display:block*/
</div>

.clearfix::after {
  content:"";
  clear:both;
  display:block; /*after,before inline 요소로 변경*/
}
.child {
  float : left;
}

<span>1</span>
<span>2</span>
<span>3</span>

.span {
  width : 100px;
  height : 100px;
  margin : 10px;
  background : red;
  float : left;
}

position

요소위치

<div class="parent">
  <div class="child"></div>
</div>

.parent { 
  position : relative;
}

.child {
  position : absolute;
  top : 50px;
  left : 100px;
}

/* 배너 광고처럼 뷰포트 기준으로 위치가 고정된다. */
<div class="parent">
  <div class="child"></div>
</div>

.body {
  height : 4000px;
}

.child {
  position : absolute;
  bottom : 50px;
  right : 10px;
}

position 요소 쌓임순서

요소위치

background

 .box1 {
   background : red url("../img/image.jpg") no-repeat left top scroll;
 }
 .box2{
   background : url("../img/image.jpg") no-repeat right 100px;
  }
 .box3 {
   background : red;
 }

background-attachment

flex

<div class="container">
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
</div>
.container {
  border : 2px solid red;
}

 .container .item {
  width : 100px;
  height : 100px;
  border : 2px solid;
  border-radius : 10px;
}

flex를 이용한 정렬방법

  .container {
    border : 2px solid red;
    display : flex;
  } 

기존 수평/수직 정렬방법(대체제)

.container .item {
  ...
  display : inline; 
}
<div class="container clearfix">
  ...
</div>

.clearfix:after {
  content : "";
  display : block;
  clear : both;
}

.container .item {
  ...,
  float : left;
}

flex item center 정렬방법

<div class="container">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
  <div class="item">5</div>
  <div class="item">6</div>
</div>
.container {
  border : 4px solid;
  display : flex;
}

.container .item {
  width : 100px;
  height : 100px;
  background : tomato;
  border : 4px dashed red;
  border-radius : 10px;
  display : flex;
  justify-content : center;
  align-items : center;
}

Grid

 <div class="container">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
  <div class="item">5</div>
</div>

.container {
  display : grid;
  grid-template-rows : repeat(2, 100px) /*100px 100px*/;
  grid-template-columns : repeat(3, 1fr); /* 1:1 비율로 열을 생성*/
  border: 4px solid lightgray;
}

.container .item {
  border: 2px dashed red;
}

Originally published February 22, 2020
Latest update February 21, 2020

Related posts :