• <table id="4yyaw"><kbd id="4yyaw"></kbd></table>
  • <td id="4yyaw"></td>
  • 發布時間:2020-09-29 09:30 原文鏈接: 一篇文章帶你了解CSS3背景知識(三)

    三、屬性1. background-origin 屬性

    CSS3 background-origin 屬性指定在背景圖像定位在哪里.

    這個屬性有三個不同的值:

    border-box   :背景圖像從邊框的左上角開始。

    padding-box :(默認)背景圖像從左上角的填充邊緣。

    content-box :背景圖像從左上角的內容

    下面的例子說明了background-origin屬性:

    #example1 {        border: 10px solid black;        padding: 35px;        background: url(img/fy_indexBg.jpg);        background-repeat: no-repeat;    }
       #example2 {        border: 10px solid black;        padding: 35px;        background: url(img/fy_indexBg.jpg);        background-repeat: no-repeat;        background-origin: border-box;    }
       #example3 {        border: 10px solid black;        padding: 35px;        background: url(img/fy_indexBg.jpg);        background-repeat: no-repeat;        background-origin: content-box;    }

    完整代碼:

    <!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>編程字典</title>  <style>    #example1 {        border: 10px solid black;        padding: 35px;        background: url(img/fy_indexBg.jpg);        background-repeat: no-repeat;    }
       #example2 {        border: 10px solid black;        padding: 35px;        background: url(img/fy_indexBg.jpg);        background-repeat: no-repeat;        background-origin: border-box;    }
       #example3 {        border: 10px solid black;        padding: 35px;        background: url(img/fy_indexBg.jpg);        background-repeat: no-repeat;        background-origin: content-box;    }                </style></head><body>
     <p>沒有 background-origin (padding-box 默認):</p>  <div id="example1">  <h2>Lorem Ipsum Dolor</h2>  <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>  <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>  </div>
     <p>background-origin: border-box:</p>  <div id="example2">  <h2>Lorem Ipsum Dolor</h2>  <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>  <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>  </div>
     <p>background-origin: content-box:</p>  <div id="example3">  <h2>Lorem Ipsum Dolor</h2>  <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>  <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>  </div>
    </body></html>          2. background-clip 屬性

    CSS3 background-clip 屬性指定背景的繪制面積.

    該屬性有三個不同的值:

    border-box - (默認) 背景是畫的邊框外邊緣 padding-box-背景被顯示到填充物的外緣。content-box - 背景是畫在內容框內

    下面舉例演示了background-clip屬性:

    #example1 {    border: 10px dotted black;    padding: 35px;    background: yellow;    background-clip: content-box;}

    四、總結

    本文主要介紹了CSS背景,通過CSS實現多背景顯示,自定義某一些尺寸顯示格式,background-origin等多個屬性的應用,豐富的案例幫助大家更好的理解。

    希望大家自己去嘗試一下,實現的時候,總會有各種各樣的問題,切勿眼高手低,勤動手,才可以理解的更加深刻。


  • <table id="4yyaw"><kbd id="4yyaw"></kbd></table>
  • <td id="4yyaw"></td>
  • 调性视频