λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
side-project/GitHub 따라 λ§Œλ“€κΈ°

[CSS] λ²„νŠΌ λ§Œλ“€κΈ°

by 솑두뢀 2022. 3. 21.
728x90
λ°˜μ‘ν˜•

πŸ”— Codepen : 즉각적인 CSS μ μš©μ— μœ μš©ν•œ μ‚¬μ΄νŠΈ 

https://codepen.io/pen/

 

Create a New Pen

...

codepen.io

 


<div class="btn1">Hello btn1</div>
<div class="btn2">Hello btn2</div>
<div class="btn3">Hello btn3</div>
<div class="btn4">Hello btn4</div>

 

.btn1{
  width :300px;
  height: 60px;
  background: #eee linear-gradient(to bottom, #fcfcfc, #eee);
  border: 1px solid #d5d5d5;
  border-radius: 4px;
}

❔ λ²„νŠΌμ˜ ν…μŠ€νŠΈκ°€ μ™Όμͺ½ 상단에 μœ„μΉ˜ λ˜μ–΄μžˆλ‹€.

btn1

.btn2{

  width :300px;
  height: 60px;
  background: #eee linear-gradient(to bottom, #fcfcfc, #eee);
  border: 1px solid #d5d5d5;
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding : 0 12px; 
  box-sizing: border-box;
}

 

btn2

# λ²„νŠΌμ˜ ν…μŠ€νŠΈ μ€‘μ•™ μ •λ ¬

1 > μ€‘μ•™μœΌλ‘œ λͺ°κΈ° 쒋은 display:flex;

2 > ν…μŠ€νŠΈ 수직 κ°€μš΄λ° μ •λ ¬ align-items:center;

3 >κ°€λ‘œ μ‚¬μ΄μ¦ˆ (width)λ₯Ό μ—†μ• κΈ°

4 > μ—¬λ°±(padding)을 톡해 μˆ˜ν‰μ •λ ¬ 

padding: 0 12px;  (μƒν•˜ 0px 쒌우 12px)

5 > padding/margin이 λ„ˆλΉ„μ™€ 높이에 영ν–₯을 μ£Όμ§€μ•Šλ„λ‘  box-sizing: border-box;

1➑6 > λ²„νŠΌμ˜ widthκ°€ ν…μŠ€νŠΈ λ„ˆλΉ„ 만큼 μ°¨μ§€ν•˜λ„λ‘ display:inline-flex;

 


display : flex; vs  display : inline-flex;

- display:flex; : block μš”μ†Œμ²˜λŸΌ κ°€λ‘œμ‚¬μ΄μ¦ˆ auto (width :100%와 μœ μ‚¬ν•˜κ²Œ λ™μž‘)

 

- display : inline-flex; : inline μš”μ†Œν™” ν•œλ‹€.

block μš”μ†Œμ²˜λŸΌ κ°€λ‘œλ„ˆλΉ„ 전체λ₯Ό μ‚¬μš©ν•˜λŠ” 것이 μ•„λ‹Œ 

컨텐츠 λ„ˆλΉ„λ§ŒνΌλ§Œ μ‚¬μš©

βœ…
display:flex; ( block μš”μ†Œ )➑ display : inline-flex; ( inline μš”μ†Œ )
μ»¨ν…μΈ μ˜ κΈ€μžμ˜ 맞게 λ„ˆλΉ„λ₯Ό μ•Œμ•„μ„œ μžλ™μœΌλ‘œ μ‘°μ ˆλœλ‹€β—

 


.btn3{
  height: 60px;
  background: #eee linear-gradient(to bottom, #fcfcfc, #eee);
  border: 1px solid #d5d5d5;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  padding : 0 12px; 
  box-sizing: border-box;
}


.btn4{
  height: 34px;
  background: #eee linear-gradient(to bottom, #fcfcfc, #eee);
  border: 1px solid #d5d5d5;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  box-sizing: border-box;

  color: #333;
}

btn3 / btn4

 


 

마우슀 hover μƒνƒœ

<div class="btn">default btn</div>

 

κ°€μƒμš”μ†Œ μ„ νƒμž :: before

- λ²„νŠΌ λ‚΄λΆ€ μ•žμ— νŠΉμ •μš”μ†Œλ₯Ό λ§Œλ“ λ‹€.

- μš”μ†ŒλŠ” position: absolute;λ₯Ό μ‚¬μš©ν•œλ‹€.


.btn:hover::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.07);
}


βœ” μ ˆλŒ€μœ„μΉ˜λ₯Ό μ‚¬μš©ν•  λ•Œ λΆ€λͺ¨μš”μ†Œμ— position 값이 μžˆλŠ”μ§€ ν™•μΈν•΄μ•Όν•œλ‹€.

λΆ€λͺ¨μš”μ†Œμ— position 값이 μ—†μ–΄ μΆ”κ°€ν•΄μ€˜μ•Όν•  λ•ŒλŠ” position: relative;  μž‘μ„±ν•΄μ€€λ‹€.
βœ… λΆ€λͺ¨μš”μ†Œ κΈ°μ€€μœΌλ‘œ λ°°μΉ˜ν•˜κ³  κ²€μ •μƒ‰μ˜ 7%투λͺ…λ„λ‘œ hoverμƒνƒœλ₯Ό ν‘œν˜„ν•˜κ² λ‹€.

 

 

.btn{
  height: 34px;
  background: #eee linear-gradient(to bottom, #fcfcfc, #eee);
  border: 1px solid #d5d5d5;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  box-sizing: border-box;
  position: relative;
  color: #333;
}

기본적인 μƒνƒœμ˜ λ²„νŠΌ


<div class="btn btn--primary">primary</div>



.btn.btn--primary {
  border: 1px solid #65b386;
  color: #fff;
  background: #55a532 linear-gradient(#91dd70, #55ae2e);
} 

 


​

primary
hover μƒνƒœ

 

728x90
λ°˜μ‘ν˜•

λŒ“κΈ€