【CSS】float - 浮動(要素の回り込み)

【CSS】float - 浮動(要素の回り込み)

CSSのfloatプロパティについて解説します。

検証環境

float

floatは“要素の回り込み”のプロパティです。

基本構文

float: 値;

代表的な値は次の通りです。

意味
none なし。
left 左側に回り込む。
right 右側に回り込む。

サンプル

left

<style>
img {
    ___ih_hl_start
    float: left;
    ___ih_hl_end
}
</style>

<div>
    <img src="https://it-hack.net/storage/app/media/document/development/programming/css/properties/float/hacker-commandline.jpeg">
    <p>
        CSS : Cascading Style Sheets.
    </p>
    <p>
        CSS is a programming language that decorates elements such as HTML and XML.
    </p>
    <p>
        You can set various properties such as text color, background, and size.
    </p>
</div>

right

<style>
img {
    ___ih_hl_start
    float: right;
    ___ih_hl_end
}
</style>

<div>
    <img src="https://it-hack.net/storage/app/media/document/development/programming/css/properties/float/hacker-commandline.jpeg">
    <p>
        CSS : Cascading Style Sheets.
    </p>
    <p>
        CSS is a programming language that decorates elements such as HTML and XML.
    </p>
    <p>
        You can set various properties such as text color, background, and size.
    </p>
</div>