首頁 web前端 html教學 實例詳解Html5的背景應用

實例詳解Html5的背景應用

Apr 08, 2018 am 10:09 AM
html5 背景

這篇文章主要介紹了淺談Html5的背景屬性,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟著小編過來看看吧

1、背景屬性複習:
#background-image
##background-color
background-repeat
background-position
#background-attachment
2、新增屬性:

#background-size:
background-size:x y;   // 水平垂直方向的尺寸,像素/百分比/auto/⋯
background-size :cover;  //保持寬高比不變,保證佔滿盒子,但不保證能看到全部
background-size:contain; //保持寬高比不變,保證看清全圖,但可能佔不滿盒子

多重背景:
background-image:url(1.jpg),url(2.jpg) ;


background-origin  背景區域定位     border-box: 從border區域開始顯示背景

#  padding-box: 從padding區域開始顯示背景
  content-box:從content內容區域開始顯示背景

background-clip 背景繪製區域




# #  border-box: 從border區域開始繪製背景
  padding-box: 從padding區域開始繪製背景
  content-box: 從content內容區域開始顯示背景

3、背景練習程式碼部分:

<!DOCTYPE HTML>
<html>
  <head>
    <title>your title name</title>
    <meta charset="utf-8">
    <meta name="Author" content="Wilson Xu">
    <style type="text/css">
      *{margin: 0;padding: 0;font-family: "Microsoft yahei";}
      a{text-decoration: none;}
      a img{display: block;border: none;}
      li{list-style: none;}

      .container{
        width: 1200px;
        padding: 20px;
        margin: 10px auto;
        border: 1px dashed #ccc;
      }
      .container h4{padding-bottom: 5px;}
      .container ul{
        width: 1200px;
        overflow: hidden;
      }
      .container ul li{
        float: left;
        width: 331px;
        padding: 20px;
        height: 240px;
        margin-right: 10px;
        border: 10px solid rgba(10,10,10,.3);
        background: url(&#39;images/1.jpg&#39;) no-repeat;
        background-size: 371px auto;
      }
      .container ul li:last-child{margin-right: 0;}

      .container ul.origin li:nth-child(1){
        background-origin: border-box;
      }
      .container ul.origin li:nth-child(2){
        background-origin: padding-box;
      }
      .container ul.origin li:nth-child(3){
        background-origin: content-box;
      }

      .container ul.clip li:nth-child(1){
        background-clip: border-box;
      }
      .container ul.clip li:nth-child(2){
        background-clip: padding-box;
      }
      .container ul.clip li:nth-child(3){
        background-clip: content-box;
      }

      section .pic{
        width: 600px;
        height: 400px;
        margin: 20px auto;
        border: 1px dashed #ddd;
        background: url(&#39;images/3.jpg&#39;) no-repeat center center/auto 200px, url(&#39;images/2.jpg&#39;) no-repeat center center/auto 300px, url(&#39;images/1.jpg&#39;) no-repeat center center/auto 400px;
      }
      section p{
        font-size: 14px;
        color: #f01010;
      }
    </style>
  </head>
  <body>
    <p class="container">
      <section>
        <h4>1、background-origin: border-box | padding-box | content-box</h4>
        <ul class="origin">
          <li></li>
          <li></li>
          <li></li>
        </ul>
      </section>
      <section>
        <h4 style="margin-top: 20px;border-top: 1px dashed #ccc;">2、background-clip: border-box | padding-box | content-box</h4>
        <ul class="clip">
          <li></li>
          <li></li>
          <li></li>
        </ul>
      </section>
      <section>
        <h4 style="margin-top: 20px;border-top: 1px dashed #ccc;">3、多背景:background: url(&#39;images/3.jpg&#39;) no-repeat center center/auto 200px, url(&#39;images/2.jpg&#39;) no-repeat center center/auto 300px, url(&#39;images/1.jpg&#39;) no-repeat center center/auto 400px;
</h4>
        <p class="pic"></p>
        <p>注释:复合写background-size的时候,一定要用/与其他值隔开。</p>
      </section>
    </p>
  </body>
</html>
登入後複製

5、背景練習preview:



### ######6、漸層:############線性漸層:linear-gradient(方位(left/left top/60deg),起始顏色| 百分比30%,終止顏色) ;使用時加內核前綴eg:-webkit-linear-gradient,IE9不支援##########徑向漸層:radial-gradient(中心點位置,擴散程度,色域| 百分比);由中心向四周發散,eg:-webkit-radial-gradient(50px 50px,起始顏色,終止顏色);-webkit-radial-gradient(center,起始顏色,終止顏色);########## IE低版本相容:filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff',endColorstr='#ff0000',GradientType='1');1表示從左到右,0是從上到下,且顏色值只能是6位元雜湊值#########7、漸層練習程式碼部分:###
<!DOCTYPE HTML>
<html>
  <head>
    <title>your title name</title>
    <meta charset="utf-8">
    <meta name="Author" content="Wilson Xu">
    <style type="text/css">
      *{margin: 0;padding: 0;font-family: "Microsoft yahei";}
      a{text-decoration: none;}
      a img{display: block;border: none;}
      li{list-style: none;}

      .container{
        width: 1200px;
        padding: 20px;
        margin: 20px auto;
        border: 1px dashed #ccc;
      }
      .container h4{padding-bottom: 5px;}
      .container ul{
        width: 1200px;
        overflow: hidden;
      }
      .container ul.linear li,
      .container ul.filter li{
        width: 600px;
        height: 40px;
        margin: 10px 0;
      }
      .container ul.linear li:first-child{
        background: -webkit-linear-gradient(60deg,#fff 10%, #f00 30%, #0f0 50%, #00f 70%, #000);
      }
      .container ul.linear li:last-child{
        background: -webkit-linear-gradient(left top, rgba(122,156,233,.6) 30%, rgb(255,12,222) 60%, green 80%, #fff);
      }
      .container ul.filter li:first-child{
        background: filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=&#39;#abcdef&#39;,endColorstr=&#39;#f44add&#39;,GradientType=&#39;0&#39;);
      }
      .container ul.filter li:last-child{
        background: filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=&#39;#ffffff&#39;,endColorstr=&#39;#000000&#39;,GradientType=&#39;1&#39;);
      }

      .container ul.radial li{
        width: 200px;
        height: 200px;
        margin-right: 20px;
        float: left;
        border-radius: 100%;
      }
      .container ul.radial li:nth-child(1){
        background: -webkit-radial-gradient(center, #fff, #000);
      }
      .container ul.radial li:nth-child(2){
        background: -webkit-radial-gradient(left 50px, #fff, #000);
      }
      .container ul.radial li:nth-child(3){
        background: -webkit-radial-gradient(50px 100px,100px 100px, #fff 80%, #000);
      }
      .container ul.radial li:nth-child(4){
        background: -webkit-radial-gradient(left, #fff 20%, #f00 40%, #0f0 60%, #00f 80%, #000);
      }
    </style>
  </head>
  <body>
    <p class="container">
      <section>
        <h4>1、线性渐变:-webkit-linear-gradient(方位,颜色域 | 范围百分比)</h4>
        <ul class="linear">
          <li></li>
          <li></li>
        </ul>
      </section>
      <section>
        <h4>2、线性渐变-兼容IE低版本:filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=&#39;6位哈希值&#39;,endColorstr=&#39;6位哈希值&#39;,GradientType=&#39;1/0&#39;);</h4>
        <ul class="filter">
          <li></li>
          <li></li>
        </ul>
      </section>
      <section>
        <h4>3、径向渐变:radial-gradient(中心点位置,扩散程度,颜色域 | 百分比);</h4>
        <ul class="radial">
          <li></li>
          <li></li>
          <li></li>
          <li></li>
        </ul>
      </section>
    </p>
  </body>
</html>
登入後複製
###8、漸層preview:########### #######

以上是實例詳解Html5的背景應用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

HTML 中的表格邊框 HTML 中的表格邊框 Sep 04, 2024 pm 04:49 PM

HTML 表格邊框指南。在這裡,我們以 HTML 中的表格邊框為例,討論定義表格邊框的多種方法。

HTML 左邊距 HTML 左邊距 Sep 04, 2024 pm 04:48 PM

HTML 左邊距指南。在這裡,我們討論 HTML margin-left 的簡要概述及其範例及其程式碼實作。

HTML 中的巢狀表 HTML 中的巢狀表 Sep 04, 2024 pm 04:49 PM

這是 HTML 中巢狀表的指南。這裡我們討論如何在表中建立表格以及對應的範例。

HTML 表格佈局 HTML 表格佈局 Sep 04, 2024 pm 04:54 PM

HTML 表格佈局指南。在這裡,我們詳細討論 HTML 表格佈局的值以及範例和輸出。

HTML 輸入佔位符 HTML 輸入佔位符 Sep 04, 2024 pm 04:54 PM

HTML 輸入佔位符指南。在這裡,我們討論 HTML 輸入佔位符的範例以及程式碼和輸出。

HTML 有序列表 HTML 有序列表 Sep 04, 2024 pm 04:43 PM

HTML 有序列表指南。在這裡我們也分別討論了 HTML 有序列表和類型的介紹以及它們的範例

在 HTML 中移動文字 在 HTML 中移動文字 Sep 04, 2024 pm 04:45 PM

HTML 中的文字移動指南。在這裡我們討論一下marquee標籤如何使用語法和實作範例。

HTML onclick 按鈕 HTML onclick 按鈕 Sep 04, 2024 pm 04:49 PM

HTML onclick 按鈕指南。這裡我們分別討論它們的介紹、工作原理、範例以及各個事件中的onclick事件。

See all articles