[HTML + CSS] 반응형으로 감싸기

jaypyon·2021년 10월 31일
0

감싸고자 하는 태그를 두개의 태그로 감싼다.

	<div class="reactivewrap">
        <div>
            <div class="myback"></div>
        </div>
    </div>

reactivewrap class의 Style

  • position : relative
  • max-height(또는 width)의 지정

하위 태그의 Style

  • padding-bottom으로 유지하고자 하는 비율을 설정 (16:9의 경우 56.25%)

감싸진 기존 태그의 Style

  • px에서 %로 변환
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="reactivewrap">
        <div>
            <div class="myback"></div>
        </div>
    </div>
    
</body>
</html>
<style>
    .reactivewrap{
        max-height: 1200px;
        height:100%;
        position:relative;
    }
    .reactivewrap > div {
        width:100%;
        padding-bottom:100%;
    }
    .myback {
        position:absolute;
        width: 100%;
        height: 100%;
        animation: movebg 10s cubic-bezier(0.57, 0.32, 0.43, 0.7) infinite;
        background: url(./starry.jpg) center 0 / 1000px round;
        transition: all 2.5s ease-in;
    }
    @keyframes movebg {
        0% {
            background-position: 0 0;
        }
        50%{
            background-position: 0 50%;
        }
        100% {
            background-position: 0 100%;
        }
    }
</style>
profile
DGU CSE

0개의 댓글