πŸ”Έ 가상객체

forStudingΒ·2022λ…„ 1μ›” 5일
0

CSS

λͺ©λ‘ 보기
3/4

πŸ”Έ 가상객체 μ•Œμ•„λ³΄κΈ°

κ°μ²΄λž€ 속성과 μ†μ„±κ°’μ˜ 집합을 객체라고 ν•©λ‹ˆλ‹€.
예) h1νƒœκ·ΈλŠ” μ—¬λŸ¬κ°€μ§€ 속성과 속성값을 가지고 μžˆμŠ΅λ‹ˆλ‹€. λ”°λΌμ„œ h1도 ν•˜λ‚˜μ˜ κ°μ²΄μž…λ‹ˆλ‹€.
htmlλ¬Έμ„œμ— 직접 μž‘μ„±λœ 객체λ₯Ό 싀쑴객체라 ν•œλ‹€λ©΄, κ°€μƒκ°μ²΄λŠ” htmlλ¬Έμ„œκ°€ μ•„λ‹Œ css에 λ§Œλ“€μ–΄μ§„ κ°μ²΄μž…λ‹ˆλ‹€.

    <ul>
        <li>ν•­λͺ©1</li>
        <li>ν•­λͺ©2</li>
        <li>ν•­λͺ©3</li>
        <li>ν•­λͺ©4</li>
    </ul>
ul::before{
    display: block; content: '첫번재 μžμ‹μœ„μΉ˜μ˜ 가상객체';
}
ul::after{
    display: block; content: 'λ§ˆμ§€λ§‰ μžμ‹μœ„μΉ˜μ˜ 가상객체';
}
ul li:first-child{
    background-color: #ccc;
}

πŸ”Έ 가상객체 λ§Œλ“€κΈ°

κ°€μƒκ°μ²΄λŠ” cssμ—μ„œ λ§Œλ“€μˆ˜ 있고, νŠΉμ •μš”μ†Œμ˜ μžμ‹ν˜•νƒœλ‘œ λ§Œλ“€μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.
κ°€μƒκ°μ²΄λŠ” νŠΉμ •μš”μ†Œμ˜ 첫번째 μžμ‹μœ„μΉ˜, λ§ˆμ§€λ§‰ μžμ‹μœ„μΉ˜μ— λ§Œλ“€μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.

    <dl>
        <dt>μš©μ–΄νƒœκ·Έ</dt>
        <dd>μ„€λͺ…νƒœκ·Έ1</dd>
        <dd>μ„€λͺ…νƒœκ·Έ2</dd>
        <dd>μ„€λͺ…νƒœκ·Έ3</dd>
    </dl>
    <div class="box">
        <span>Text</span>
    </div>
dl{
    outline: 1px solid blue;
    margin-top: 40px;
}
dl dt,dd{
    outline: 2px dotted deepskyblue;
    height: 40px;
    line-height: 40px;
}
/* dl의 첫번째 μžμ‹μœ„μΉ˜μ— 가상객체λ₯Ό λ§Œλ“­λ‹ˆλ‹€. */
dl::before{
    display: block; content: 'dl의 가상 μžμ‹κ°μ²΄';
}
/* dl의 λ§ˆμ§€λ§‰ μžμ‹μœ„μΉ˜μ— 가상객체λ₯Ό λ§Œλ“­λ‹ˆλ‹€. */
dl::after{
    display: block; content: 'dl의 가상 μžμ‹κ°μ²΄';
}
/* dl의 첫번째 μžμ‹ μœ„μΉ˜μ— μžˆλŠ” ddνƒœκ·Έλ₯Ό μ„ νƒν•˜μ„Έμš”. 
첫번째 μžμ‹μ€ dt μ΄λ―€λ‘œ μ„ νƒμ μš© 뢈λŠ₯ */
dl dd:first-child{
    background-color: #ccc;
}
/* type:μš”μ†Œν˜•νƒœλ₯Ό μ˜λ―Έν•©λ‹ˆλ‹€. dtνƒ€μž…μΈμ§€ ddνƒ€μž…μΈμ§€ μ„ νƒλœ μš”μ†Œμ˜ νƒ€μž…μ„ λ”°λ¦…λ‹ˆλ‹€.
dl의 μžμ‹μš”μ†Œμ€‘ type이 dd인 첫번째 μš”μ†Œλ₯Ό μ„ νƒν•˜μ„Έμš”. */
dl dd:first-of-type{
    background-color: #ccc;
}

.box{
    margin-top: 40px;
    background-color: #ccc;
    line-height: 40px;
    width: 120px;
    text-align: center;
    position: relative;
    color: #000;
    transition: color 0.3s;
}
.box:hover{
    color: #fff;
}
.box span{
    position: relative;
    z-index: 2;
}
.box::after{
    display: block; content: '';
    /* 기본값은 autoμ΄λ‚˜ κ°€μƒκ°μ²΄μ΄λ―€λ‘œ 배경색상 적용이 μ•ˆλ˜μ–΄ 보인닀. */
    /* width: auto; height: auto; */
    background-color: #000;
    /* width: 100%;
    height: 4px;
    position: absolute;
    bottom: 10px;
    width: 0; */
    width: 0; height: 40px;
    position: absolute;
    z-index: 1;
    bottom: 0;
    transition: width 0.3s;
    right: 0;
}
/* 가상객체에 hoverλ₯Ό μ μš©ν• λ•Œμ—λŠ” ν΄λž˜μŠ€μ΄λ¦„μ— 써야함 */
/* .box::after:hover{
    background-color: #f00;
} */
.box:hover::after{
    /* background-color: #f00; */
    width: 100%;
    left: 0;
        /* μ’Œν‘œκ°’μ˜ 기본값은 auto μ΄λ―€λ‘œ λ‹€μ‹œ λŒλ €μ€˜μ•Όν•©λ‹ˆλ‹€. */
    right: auto;
}

0개의 λŒ“κΈ€