스마트 인재개발원/HTML - CSS - JS

(스마트인재개발원) CSS 기초 글자정렬 , absolute, top button

앨런튜링_ 2021. 5. 28. 17:19
HTML
<!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>
    <style>
        #parent{
            width: 150px;
            height: 450px;
            background-color: rgb(219, 217, 217);
        }
        .child{
            color: white;
            /* 글자의 정렬  */
            text-align: center;
            /* 줄간격 스타일
            - 한줄일 경우에만 가운데정렬가능*/
            line-height: 150px;
            width: 150px;
            height: 150px;
        }

        .ch1{
            background-color: red;
            position: relative;

        }
        .ch2{
            background-color: yellow;
            position: relative;
        
            left: 150px;
        }
        .ch3{
            background-color: blue;
            position: relative;
            top: -75px;
            left: 75px;
        }

    </style>
</head>
<body>
    
    
    <div id="parent">
        <div class="child ch1">
            Child
        </div>
        <div class="child ch2">
            Child
        </div>
        <div class="child ch3">
            Child   
        </div>

    </div>



</body>
</html>

HTML
<!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>
    <style>
        #parent{
            width: 150px;
            height: 450px;        
        }
        .child{
            position: absolute;
            color: white;
            /* 글자의 정렬  */
            text-align: center;
            /* 줄간격 스타일
            - 한줄일 경우에만 가운데정렬가능*/
            line-height: 150px;
            width: 150px;
            height: 150px;      
        }

        /* absolute가 되면 부모의 관계를 벗어남.. 어려움 */
        .ch1{
            background-color: red;
        }
        .ch2{
            background-color: yellow;
        
            left: 800px;
        }
        .ch3{
            background-color: blue;
            top: 500px;       
        }

        .ch4{
            background-color: rgb(63, 218, 109);
            top: 500px;
            left: 800px;       
        }

    </style>
</head>
<body>
    
    
    <div id="parent">
        <div class="child ch1">
            Child
        </div>
        <div class="child ch2">
            Child
        </div>
        <div class="child ch3">
            Child   
        </div>
        <div class="child ch4">
            Child   
        </div>

    </div>



</body>
</html>

HTML
<!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>
    <style>

        #top{
            border: 1px solid black;
            width: 50px; 
            height: 50px;
            background-color: whitesmoke;
            text-align: center;
            line-height: 50px;
            position: fixed;
            right: 20px;
            bottom: 20px;  
        }

    </style>
</head>
<body>
    <h1 id="top1">Top</h1>
    <div id="top">
        <a href="#top1">TOP</a> 
    </div>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

</body>
</html>