當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


CSS inset-block用法及代碼示例

CSS中的inset-block屬性用於定義邏輯塊的開始和結束偏移量,而不用於內聯偏移量或邏輯塊。此屬性可以應用於任何writing-mode屬性。

用法:

inset-block:length | percentage | auto | inherit | initial | unset;

屬性值:



  • length:它設置以px,cm,pt等為單位的固定值。也可以使用負值。其默認值為0px。
  • percentage:它與長度相同,但是根據窗口大小的百分比進行設置。
  • auto:當需要瀏覽器確定inset-block時使用。
  • initial:它用於將inset-block屬性的值設置為其默認值。
  • inherit:當需要該元素從其父元素繼承inset-block屬性時使用。
  • unset:它用於取消設置默認的inset-block屬性值。

以下示例說明了CSS中的inset-block屬性:

範例1:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>CSS | inset-block Property</title> 
    <style> 
        h1 { 
            color:green; 
        } 
          
        div { 
            background-color:green; 
            width:200px; 
            height:120px; 
        } 
          
        .one { 
            position:relative; 
            inset-block:30px 50px; 
            background-color:cyan; 
        } 
    </style> 
</head> 
  
<body> 
    <center> 
        <h1>Geeksforgeeks</h1> 
        <b>CSS | inset-block Property</b> 
        <br><br> 
        <div> 
            <p class="one"> 
                A Computer Science Portal for Geeks 
            </p> 
        </div> 
    </center> 
</body> 
  
</html>

輸出:

範例2:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>CSS | inset-block Property</title> 
    <style> 
        h1 { 
            color:green; 
        } 
          
        div { 
            background-color:green; 
            width:200px; 
            height:120px; 
        } 
          
        .one { 
            writing-mode:vertical-rl; 
            position:relative; 
            inset-block:30px 50px; 
            background-color:cyan; 
        } 
    </style> 
</head> 
  
<body> 
    <center> 
        <h1>Geeksforgeeks</h1> 
        <b>CSS | inset-block Property</b> 
        <br><br> 
        <div> 
            <p class="one"> 
                A Computer Science Portal for Geeks 
            </p> 
        </div> 
    </center> 
</body> 
  
</html>                    

輸出:

支持的瀏覽器:下麵列出了inset-block屬性支持的瀏覽器:

  • Firefox
  • 穀歌瀏覽器
  • Edge
  • Opera

參考: https://developer.mozilla.org/en-US/docs/Web/CSS/inset-block




相關用法


注:本文由純淨天空篩選整理自skyridetim大神的英文原創作品 CSS | inset-block Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。