【CSS】background-clip - 背景画像の表示範囲

【CSS】background-clip - 背景画像の表示範囲

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

検証環境

background-clip

background-clipは“背景画像の表示範囲”のプロパティです。

基本構文

background-clip: 値;

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

意味
border-box 境界ボックス
padding-box パディングボックス
content-box コンテンツボックス

サンプル

border-box

<style>
p {
    color: yellow;
    padding: 30px;
    border: 20px dashed silver;
    background-image: url('https://it-hack.net/storage/app/media/document/development/programming/css/properties/background-clip/hacker-commandline.jpeg');
    background-size: cover;
    ___ih_hl_start
    background-clip: border-box;
    ___ih_hl_end
}
</style>

<p>
    CSS : Cascading Style Sheets.
    CSS is a programming language
    that decorates elements such as HTML and XML.
    You can set various properties
    such as text color, background, and size.
</p>

padding-box

<style>
p {
    color: yellow;
    padding: 30px;
    border: 20px dashed silver;
    background-image: url('https://it-hack.net/storage/app/media/document/development/programming/css/properties/background-clip/hacker-commandline.jpeg');
    background-size: cover;
    ___ih_hl_start
    background-clip: padding-box;
    ___ih_hl_end
}
</style>

<p>
    CSS : Cascading Style Sheets.
    CSS is a programming language
    that decorates elements such as HTML and XML.
    You can set various properties
    such as text color, background, and size.
</p>

content-box

<style>
p {
    color: yellow;
    padding: 30px;
    border: 20px dashed silver;
    background-image: url('https://it-hack.net/storage/app/media/document/development/programming/css/properties/background-clip/hacker-commandline.jpeg');
    background-size: cover;
    ___ih_hl_start
    background-clip: content-box;
    ___ih_hl_end
}
</style>

<p>
    CSS : Cascading Style Sheets.
    CSS is a programming language
    that decorates elements such as HTML and XML.
    You can set various properties
    such as text color, background, and size.
</p>