shape-image-threshold
Baseline 廣泛可用 *
shape-image-threshold CSS 屬性設定用於從影像中提取形狀的 alpha 通道閾值,其中影像用作 shape-outside 的值。
試一試
shape-outside: linear-gradient(
50deg,
rgb(77 26 103),
transparent 80%,
transparent
);
shape-image-threshold: 0.2;
shape-outside: linear-gradient(
50deg,
rgb(77 26 103),
transparent 80%,
transparent
);
shape-image-threshold: 0.4;
shape-outside: linear-gradient(
50deg,
rgb(77 26 103),
transparent 80%,
transparent
);
shape-image-threshold: 0.6;
<section class="default-example" id="default-example">
<div class="example-container">
<div class="transition-all" id="example-element"></div>
We had agreed, my companion and I, that I should call for him at his house,
after dinner, not later than eleven o’clock. This athletic young Frenchman
belongs to a small set of Parisian sportsmen, who have taken up “ballooning”
as a pastime. After having exhausted all the sensations that are to be found
in ordinary sports, even those of “automobiling” at a breakneck speed, the
members of the “Aéro Club” now seek in the air, where they indulge in all
kinds of daring feats, the nerve-racking excitement that they have ceased to
find on earth.
</div>
</section>
.example-container {
text-align: left;
padding: 20px;
}
#example-element {
float: left;
width: 150px;
height: 150px;
margin: 20px;
background-image: linear-gradient(
50deg,
rgb(77 26 103),
transparent 80%,
transparent
);
}
任何 alpha 分量值大於閾值的畫素都被視為形狀的一部分,用於確定其邊界。例如,值為 0.5 意味著形狀將包含所有不透明度超過 50% 的畫素。
語法
css
/* <number> value */
shape-image-threshold: 0.7;
/* Global values */
shape-image-threshold: inherit;
shape-image-threshold: initial;
shape-image-threshold: revert;
shape-image-threshold: revert-layer;
shape-image-threshold: unset;
值
<alpha-value>-
設定用於從影像中提取形狀的閾值。形狀由 alpha 值大於閾值的畫素定義。超出 0.0(完全透明)到 1.0(完全不透明)範圍的值將被限制在此範圍內。
正式定義
正式語法
shape-image-threshold =
<opacity-value>
<opacity-value> =
<number> |
<percentage>
示例
文字與漸變對齊
此示例建立了一個帶有漸變背景影像的 <div> 塊。漸變使用 shape-outside 建立為 CSS 形狀,以便漸變中至少 20% 不透明(即 alpha 分量大於 0.2 的畫素)的畫素被視為形狀的一部分。
HTML
html
<div id="gradient-shape"></div>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vel at commodi
voluptates enim, distinctio officia. Saepe optio accusamus doloribus sint
facilis itaque ab nulla, dolor molestiae assumenda cum sit placeat adipisci,
libero quae nihil porro debitis laboriosam inventore animi impedit nostrum
nesciunt quisquam expedita! Dolores consectetur iure atque a mollitia dicta
repudiandae illum exercitationem aliquam repellendus ipsum porro modi, id nemo
eligendi, architecto ratione quibusdam iusto nisi soluta? Totam inventore ea
eum sed velit et eligendi suscipit accusamus iusto dolore, at provident eius
alias maxime pariatur non deleniti ipsum sequi rem eveniet laboriosam magni
expedita?
</p>
CSS
css
#gradient-shape {
width: 150px;
height: 150px;
float: left;
background-image: linear-gradient(30deg, black, transparent 80%, transparent);
shape-outside: linear-gradient(30deg, black, transparent 80%, transparent);
shape-image-threshold: 0.2;
}
此處使用帶有線性漸變的 background-image 而不是影像檔案來建立形狀。相同的漸變也用作影像,從中派生形狀以建立浮動區域,使用 shape-outside 屬性。
然後使用 shape-image-threshold 並將其值設定為 0.2 來建立將漸變畫素視為形狀一部分的 20% 不透明度閾值。
結果
規範
| 規範 |
|---|
| CSS Shapes Module Level 1 # shape-image-threshold-property |
瀏覽器相容性
載入中…