본문 바로가기
HTML&CSS

CSS로 팝업만들기

by 작업자C 2023. 9. 29.
728x90

팝업만들기(예시)

HTML

<div>
    <a href="#open">오늘의 작업</a>
</div>

<div id="open" class="bg">
    <div class="popup">
        <a href="" class="close">닫기</a>
        <div class="inner">
            <p>css로 팝업만들기</p>
        </div>
    </div>
</div>

CSS

.bg{
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.75);
    transition: opacity 300ms;
    z-index: 1;
    opacity: 0;
    visibility: hidden;
}

.bg:target{
    opacity: 1;
    visibility: visible;			
}

.popup{
    display: block;
    position: fixed;		
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.25s, visibility 0s linear 0.25s;
    padding-right: 50px;			
    z-index: 1;			
    overflow-y: auto;
    overflow-x: hidden;
    -ms-overflow-style: none;
    white-space: nowrap;					
    scrollbar-width: none;
}

.popup::-webkit-scrollbar{
    display: none;
}

.popup:target{
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
}

.popup .close{
    position: absolute;
    right: 0;
    top: 0;
    transition: color 0.25s;
    width: 50px;
    height: 50px;
}

.popup .inner{
    width: 350px;
    height: 350px;
    padding: 20px;
    box-sizing: border-box;
    background-color: #fff;
}
728x90