[CSS] ๊ณผ์ œ

Coastbyยท2022๋…„ 8์›” 30์ผ
0

๊ฒฐ๊ณผ ์˜ˆ์‹œ


๐Ÿ‘‰ ์™„์„ฑ๋ฌผ
https://github.com/coastby/Gallery-Project

โญ๏ธ ์–ด๋ ค์› ์ง€๋งŒ ํ•ด๊ฒฐํ•œ ๊ฒƒ

โ—‹ font-size๋Š” rem์œผ๋กœ

์ ˆ๋Œ€๊ฐ’์œผ๋กœ ํ•˜๋‹ˆ ํ™”๋ฉด์„ ์ค„์ด๊ฑฐ๋‚˜ ํ•˜๋‹ˆ ํŠ€์–ด๋‚˜์™€์„œ ์•ˆ์ด์˜๋‹ค.

โ—‹ div์•ˆ์—์„œ ํ…์ŠคํŠธ ๊ฐ€์šด๋ฐ ์ •๋ ฌ

  • ๊ฐ€๋กœ

text-align : center; text-align ์†์„ฑ์€ ๊ฐ€๋กœ์ •๋ ฌ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์†์„ฑ์ด๋‹ค.์—ฌ๊ธฐ์„œ๋Š”, ๊ฐ€์šด๋ฐ ์ •๋ ฌ์„ ํ•˜๊ธฐ ์œ„ํ•ด ์†์„ฑ๊ฐ’์„ 'center'๋กœ ์„ค์ •ํ•œ๋‹ค.
justify-content : center; display ์†์„ฑ์ด flex๋กœ ์„ค์ •๋˜์–ด ์žˆ์œผ๋ฉด,text-align ์†์„ฑ์„ ์ง€์ •ํ•ด๋„ ๊ฐ€์šด๋ฐ ์ •๋ ฌ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค.์ด ๋•Œ๋Š”, ์œ„ ์˜ˆ์ œ์™€ ๊ฐ™์ดjustify-content ์†์„ฑ์„ ์„ค์ •ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

  • ์„ธ๋กœ

padding : 100px 0; ์—ฌ๊ธฐ์„œ๋Š” div์˜ padding์„ ์ง€์ •ํ•˜์—ฌ,๋ฌธ์ž์—ด์„ div์˜ ๊ฐ€์šด๋ฐ(์„ธ๋กœ)์— ์˜ค๋„๋ก ํ•œ๋‹ค.padding ์†์„ฑ์— 2๊ฐœ์˜ ๊ฐ’์ด ์ž…๋ ฅ๋˜์—ˆ๋Š”๋ฐ,์ฒซ๋ฒˆ์งธ ๊ฐ’์€ ์œ„, ์•„๋ž˜์˜ padding์„ ์„ค์ •ํ•œ๋‹ค.๋‘๋ฒˆ์งธ ๊ฐ’์€ ์™ผ์ชฝ, ์˜ค๋ฅธ์ชฝ์˜ padding์„ ์„ค์ •ํ•œ๋‹ค.

line-height : 200px;์—ฌ๊ธฐ์„œ๋Š” line-height์˜ ๊ฐ’์„ div์˜ height ๊ฐ’๊ณผ ๋˜‘๊ฐ™์ด ์ง€์ •ํ•˜์—ฌ ๋ฌธ์ž์—ด์„ ๊ฐ€์šด๋ฐ(์„ธ๋กœ) ์ •๋ ฌํ•˜์˜€๋‹ค.

align-items : center;๊ฐ€๋กœ ์ •๋ ฌ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœdisplay ์†์„ฑ์ด flex๋กœ ์ง€์ •๋˜๋ฉด,์•ž์—์„œ ์†Œ๊ฐœํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ๋Š” ์„ธ๋กœ ์ •๋ ฌ์ด ์–ด๋ ต๋‹ค.๋”ฐ๋ผ์„œ, ์ด ๋•Œ๋Š” ์œ„ ์˜ˆ์ œ์ฒ˜๋Ÿผalign-items ์†์„ฑ์„ center๋กœ ์ง€์ •ํ•˜์—ฌ ์„ธ๋กœ ๊ฐ€์šด๋ฐ ์ •๋ ฌ์„ ํ•ด์•ผํ•œ๋‹ค.

โ—‹ div์•ˆ์— div ์„ธ๋กœ ๊ฐ€์šด๋ฐ ์ •๋ ฌ

  1. margin
    child div ํƒœ๊ทธ๋ฅผ inline-block ์†์„ฑ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  margin์„ ์ฃผ๋ฉด๋œ๋‹ค. ํฌ์ง€์…˜์„ ์ง์ ‘ ์กฐ์ •ํ• ๋•Œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ (parent์˜ height - child์˜ height)/2 ๊ฐ’์„ margin-top์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.
.child {
	display : inline-block;
    margin-top : 50px;
}
  1. flex
    parent div ํƒœ๊ทธ์— flex ์†์„ฑ์„ ์ฃผ๋ฉด ์—˜๋ฆฌ๋จผํŠธ ํฌ๊ธฐ๋‚˜ ์œ„์น˜๋ฅผ ์žก์•„์ค„ ์ˆ˜ ์žˆ๋‹ค.
    align-items : center;๋กœ ์ˆ˜์ง ์ •๋ ฌํ•  ์ˆ˜ ์žˆ๋‹ค.
.parent {
	display: flex;
	align-items: center;
}

โ—‹ ๋งํฌ ๋ฐ‘์ค„, ์ƒ‰์ƒ ์—†์• ๊ธฐ

#login-form a {
  text-align: center;
  text-decoration: none; /* ๋งํฌ์˜ ๋ฐ‘์ค„ ์ œ๊ฑฐ */
  color: inherit; /* ๋งํฌ์˜ ์ƒ‰์ƒ ์ œ๊ฑฐ */
}
์ถœ์ฒ˜: https://hyunjungchoi.tistory.com/44 [ํ–‰๋ฝ๐Ÿฅ:ํ‹ฐ์Šคํ† ๋ฆฌ]

โ—‹ ๋ฉ”๋‰ด ์˜†์œผ๋กœ ์ •๋ ฌํ•˜๊ธฐ

.menu-wrap { width:1200px; margin:0 auto;  }
.menu { float:left; text-align:center; }
.menu li { display:inline-block; text-align:center; }
div { overflow:hidden; }
div p{ float:left; }

์ ์šฉ

<header id="toolbar">
      <div id="home-logo" onclick="location.reload();">
        Gallery Portfolio
      </div>
    <nav>
      <ul>
          <li class="gallery on" onclick="setNew('gallery')">์‚ฌ์ง„๋“ค ๋ณด๊ธฐ</li>
          <li class="upload" onclick="setNew('upload')">์‚ฌ์ง„ ์˜ฌ๋ฆฌ๊ธฐ</li>
          <li class="myinfo" onclick="setNew('myinfo')">๋‚ด ์ •๋ณด</li>
          <li>ํŒ”๋กœ์šฐ ๋ณด๊ธฐ</li>
          <li>ํŒ”๋กœ์›Œ ๋ณด๊ธฐ</li>
      </ul>
    </nav>
    <a href="#">
      <div class="sign">Logout</div>
    </a>
  </header>
nav ul{
  overflow: hidden;
  height: 50px;
  padding-left: 30px;
}

nav li {
  float: left;
  width: 100px;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
}

โ—‹ header์—์„œ top, left, right ์„ค์ •์„ ์•ˆํ•˜๋‹ˆ๊นŒ main์—์„œ ์—ฌ๋ฐฑ์„ ์ฃผ๋‹ˆ๊นŒ ๊ฐ™์ด ๋‚ด๋ ค์˜ด

์•„๋ž˜์—์„œ ๋‚˜์˜ค๊ฒ ์ง€๋งŒ header์—๋Š” grid ์ ์šฉ์ด ์•ˆ๋˜์–ด์„œ 'toolbar'๋ผ๋Š” ์•„์ด๋””๋ฅผ ์ฃผ๊ณ  css ์„ ํƒ์ž๋กœ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

#toolbar {
  display: grid;
  grid-template-columns: 350px 1fr 70px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background-color: #2962FF;
  color: #EEEEEE;  
  height: 50px;
  line-height: 50px;
  width: 100%;
  box-shadow: 2px 0 5px #0D47A1 ;
  z-index: 2;
}
header {
	position : fixed;
    top : 0;
    left : 0;
    right : o;
    z-index : 2;
}

.sidebar {
	position : fixed;
    width : 160px;
    z-index : 1;
}

main {
	/*header : 50px, footer : 60px, sidebar : 160px*/
	min-height : calc(100vh - 110px);
    margin-left : 160px;
    padding-bottom : 60px;
}

footer {
	position : absolute;
    bottom : 0;
    left: 0;
    width : 100%;
    height : 60px;
    z-index : 2;
    
}

โ—‹ flex

https://d2.naver.com/helloworld/8540176
https://studiomeal.com/archives/197

โ—‹ div์— img ๊ฝ‰์ฐจ๊ฒŒ ๋„ฃ๊ธฐ

img {
	object-fit : cover;
}

โ—‹ ์ค„๊ธ€์ด ๋„˜์น  ๋•Œ ํ•œ์ค„๋กœ ๋„ฃ๊ณ  ๋’ค์—๋Š” ๋ง์ค„์ž„ํ‘œ๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ

.word {
		/*
        margin:100px;
        outline: 1px solid black;
        display: block;
        color: black;
        width: 630px;
        font-size: 20px;
        font-weight: bolder !important;
        */
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
}

โ—‹ div์•ˆ์— ์ด๋ฏธ์ง€ ๊ฐ€๋กœ, ์„ธ๋กœ ๊ฐ€์šด๋ฐ ์ •๋ ฌ

<div style="align-items:center; display: flex; justify-content:center;">
/* footer ํ•˜๋‹จ ๊ณ ์ • [S] */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

#body-wrapper {
    min-height: 100%;
    position: relative;
}

#body-content {
    margin-top: 100px;
    padding-bottom: 99999px; /* footer์˜ ๋†’์ด */
}

footer {
    width: 100%;
    height: 99999px; /* footer์˜ ๋†’์ด */
    position: absolute;  
    bottom: 0;
    left: 0;
}
/* footer ํ•˜๋‹จ ๊ณ ์ • [E] */

โญ๏ธ ํ•ด๊ฒฐํ•˜์ง€ ๋ชปํ•œ ๊ฒƒ

โ—‹ grid์˜ css selector

css selector๋กœ header๋ฅผ ํ•˜๋ฉด ๋‹ค๋ฅธ ์Šคํƒ€์ผ์€ ์ ์šฉ์ด ๋˜๋Š”๋ฐ, gird ๊ด€๋ จ๋œ ๊ฒƒ์€ ์ ์šฉ์ด ์•ˆ ๋˜๋Š” ๋“ฏํ•˜๋‹ค. display : grid๋ฅผ ์ ์šฉํ•  ๋•Œ๋Š” ์„ ํƒ์ž๊ฐ€ id ๋˜๋Š” class ์—ฌ์•ผํ•˜๋Š”์ง€ ์ฐพ์•„๋ดค๋Š”๋ฐ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ์ฐพ์ง€ ๋ชปํ–ˆ๋‹ค.

profile
ํ›ˆ์ด์•ผ ํ™”์ดํŒ…

0๊ฐœ์˜ ๋Œ“๊ธ€