[CSS] float 속성


[CSS] float 속성 1

플로트 속성

지정된 요소가 정상적인 흐름에서 벗어나도록 하는 속성

상자를 왼쪽 또는 오른쪽으로 이동하여 주변의 인라인 요소를 숨깁니다.

  • float : 없음 – 기본값
  • float : left – 요소를 왼쪽으로 이동
  • float – right – 요소를 오른쪽으로 플로트

플로트 전후 비교


[CSS] float 속성 2

플로팅되지 않은 경우 첫 번째 코드

<!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>
        .box1{
            width: 150px;
            height: 150px;
            border: 1px solid black;
            background-color: crimson;
            color: white;
            text-align: center;
            line-height: 150px;
        }

        .box2{
            width: 300px;
            height: 150px;
            border: 1px solid blue;
            background-color: blue;
            color: white;
            text-align: center;
            line-height: 150px;
        }
    </style>
</head>
<body>
    <div class="box1">box1</div>
    <div class="box2">box2</div>
</body>
</html>

2. float 추가시 코드

<!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>
        .box1{
            width: 150px;
            height: 150px;
            border: 1px solid black;
            background-color: crimson;
            color: white;
            text-align: center;
            line-height: 150px;
            float: left;
        }

        .box2{
            width: 300px;
            height: 150px;
            border: 1px solid blue;
            background-color: blue;
            color: white;
            text-align: center;
            line-height: 150px;
        }
    </style>
</head>
<body>
    <div class="box1">box1</div>
    <div class="box2">box2</div>
</body>
</html>

-> 수영 선수: 왼쪽간단히 !를 입력하여 왼쪽에 상자를 띄울 수 있습니다.