π Codepen : μ¦κ°μ μΈ CSS μ μ©μ μ μ©ν μ¬μ΄νΈ
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; } |
β λ²νΌμ ν μ€νΈκ° μΌμͺ½ μλ¨μ μμΉ λμ΄μλ€.
.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;
}
# λ²νΌμ ν μ€νΈ μ€μ μ λ ¬
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;
}
λ§μ°μ€ 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);
}
β
'side-project > GitHub λ°λΌ λ§λ€κΈ°' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[CSS] a νκ·Έ ν΄λ¦ λ²μ νμ₯μν€κΈ° (0) | 2022.04.06 |
---|---|
[CSS] μμ μμ κ°μ΄λ° μ λ ¬ λ° μμ§ μ λ ¬ (0) | 2022.04.05 |
[CSS] ν₯μ€μ½λ μμ, Color Picker (0) | 2022.04.04 |
[CSS] Vendor Prefix (λΈλΌμ°μ μ μ²΄λ³ μ λμ¬) (0) | 2022.03.24 |
[CSS] input (0) | 2022.03.24 |
λκΈ