λ‘œλ”© μ€‘μž…λ‹ˆλ‹€.
λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

HTML&CSS

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

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

 

::before μš”μ†Œμ˜ 맨 μ•žμ— λ°°μΉ˜ν•˜λŠ” λ§ˆν¬μ—…μ— μ—†λŠ” κ°€μƒμš”μ†Œ
::after μš”μ†Œμ˜ 맨 뒀에 λ°°μΉ˜ν•˜λŠ” λ§ˆν¬μ—…μ— μ—†λŠ” κ°€μƒμš”μ†Œ

 


:::before 와 ::after을 λ§ˆν¬μ—…ν•  경우,
ν•„μˆ˜λ‘œ {content:""; } 이 λ“€μ–΄κ°€μ•Ό ν•œλ‹€.

문자λ₯Ό ν‘œμ‹œν•  λ•ŒλŠ” λ”°μ˜΄ν‘œ μ•ˆμ— 문자λ₯Ό λ„£μœΌλ©΄ λœλ‹€.
λ‹€λ₯Έ κΈ°λŠ₯을 ν•˜λ©΄μ„œ λ¬Έμžκ°€ 없을 경우 λΉˆλ”°μ˜΄ν‘œλ§Œ λ„£μœΌλ©΄ λœλ‹€.
그리고 inline 속성을 가지고 μžˆμœΌλ―€λ‘œ 크기 값을 μ£Όλ €λ©΄  {display: inline-block; }μ΄λ‚˜ {display: block; }속성을 λ„£μ–΄μ€˜μ•Όν•œλ‹€.

.test1::before {display: block; content:"";}

 



예제λ₯Ό ν†΅ν•΄μ„œ ν™•μΈν•΄λ³΄μž.

 

<!doctype html> 
<html>
    <head> 
        <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=0,maximum-scale=10,user-scalable=yes"> 
        <title>κ°€μƒμš”μ†Œ μ„ νƒμž</title> 
        <style>
            .test1 {margin:0 auto; max-width:600px; padding:50px; border:1px solid #ccc;}
            .test1::before {display:block; content: ""; background: pink;padding: 20px;}
            .test1::after {display:block; content: ""; background: skyblue;padding: 20px;}
            .yyy::before {display:block; content: "μ•ž";}
            .yyy::after {display:block; content: "λ’€";}
            
            .test2 {margin: 0 auto; width: 500px; border:1px solid red; height:50px;; position: relative;}
            .test2::before {display:block; content: ""; width:2px; height:50px; background: #000; transform: rotate(45deg); position: absolute; top:0; left:100px;}
            .test2::after {display:block; content: ""; width:2px; height:50px; background: #000; transform: rotate(-45deg); position: absolute; top:0; left:100px;}
        </style> 
    </head> 
    <body> 
        <div class="test1">
            <p class="yyy">*********</p>
        </div>
        <br>
        <div class="test2">
        </div>
    </body> 
</html>

 

.test1에 ::beforeλ₯Ό μ μš©ν•  경우,
.test1이 가지고 μžˆλŠ” λΈ”λŸ­ μ•ˆμ— 맨 μ•žμ— 속성이 μ μš©λœλ‹€.
μ—¬κΈ°μ„œ ν—·κ°ˆλ¦¬μ§€ 말자.
.test1 λΈ”λŸ­ μ•žμ— μ μš©λ˜λŠ” 것이 μ•„λ‹ˆλ‹€.

.test1이 ν¬ν•¨ν•˜κ³  μžˆλŠ” 컨텐츠 맨 μ•žμ— μœ„μΉ˜ν•˜κ²Œ λœλ‹€.
::afterλ₯Ό μ μš©ν•  경우,
.test1이 ν¬ν•¨ν•˜κ³  μžˆλŠ” μ»¨ν…μΈ μ˜ 맨 뒀에 μœ„μΉ˜ν•˜κ²Œ λœλ‹€.



.yyy::beforeκ³Ό .yyy:after을 μ΄μš©ν•΄μ„œ .yyyκ°€ 감싸고 μžˆλŠ” μ»¨ν…μΈ μ˜ 맨 μ•žμ— "μ•ž"κ³Ό 맨 뒀에 "λ’€"κΈ€μžλ₯Ό ν‘œμ‹œν–ˆλ‹€.

 

 

겹쳐질 경우 ::beforeλŠ” 맨 뒀에 λ†“μ΄κ²Œ 되며, ::after은 맨 μœ„μ— λ†“μ΄κ²Œ λœλ‹€.

 

 

 

.test2의 경우 햄버거 메뉴λ₯Ό ν΄λ¦­ν–ˆμ„ λ•Œ λ‚˜μ˜€λŠ” μ°½λ‹«κΈ° X λ²„νŠΌμ„ ::before와 ::after둜 λ§Œλ“€μ—ˆλ‹€.

<!doctype html> 
<html>
    <head> 
        <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=0,maximum-scale=10,user-scalable=yes"> 
        <title>κ°€μƒμš”μ†Œ μ„ νƒμž</title> 
        <style>            
            .test2 {margin: 0 auto; width: 500px; border:1px solid red; height:50px;; position: relative;}
            .test2::before {display:block; content: ""; width:2px; height:50px; background: #000; transform: rotate(45deg); position: absolute; top:0; left:100px;}
            .test2::after {display:block; content: ""; width:2px; height:50px; background: #000; transform: rotate(-45deg); position: absolute; top:0; left:100px;}
        </style> 
    </head> 
    <body> 
        <div class="test2">
        </div>
    </body> 
</html>