亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.430618.com 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

CSS 代表層疊樣式表。 HTML用于創(chuàng)建網(wǎng)頁,在網(wǎng)頁中添加文本、圖像、視頻等。之后,我們需要設(shè)置文本和圖像的樣式,這只能使用 CSS 來完成。基本上,我們可以使用CSS向HTML元素添加背景、顏色、尺寸、方向等樣式。

有三種方法可以為網(wǎng)頁添加樣式。第一種是內(nèi)聯(lián)樣式,直接將樣式添加到HTML元素中。第二種是嵌入式樣式表,在“html”文件中使用標(biāo)簽添加樣式。外部CSS文件是第三種為網(wǎng)頁添加樣式的方法。

語法

用戶可以按照以下語法將嵌入樣式表添加到 HTML 網(wǎng)頁。

<style>
   /* add CSS here */
</style>

登錄后復(fù)制

用戶可以在上述語法中的<style>標(biāo)簽之間添加CSS。

Example 1

的中文翻譯為:

示例1

在下面的示例中,我們有一個帶有“container”類的 div 元素。我們在 div 元素內(nèi)添加了兩個

元素。此外,我們還在

元素內(nèi)添加了文本內(nèi)容。

在部分,我們添加了標(biāo)簽。在 標(biāo)簽內(nèi),我們添加了容器 div 元素的 CSS。此外,我們還使用了“nth-child()”CSS 函數(shù)來對兩個

元素設(shè)置不同的樣式。

<html>
<head>
   <style>
      .container {
         border: 2px solid black;
         padding: 10px;
         margin: 10px;
         background-color: lightblue;
         height: 100px;
         width: 500px;
      }
      .container p:nth-child(1) {
         color: red;
         font-size: 20px;
      }
      .container p:nth-child(2) {
         color: green;
         font-size: 25px;
      }
   </style>
</head>
<body>
   <h2> Embedding the <i> Styles to the HTML document </i> </h2>
   <div class = "container">
      <p> This is a paragraph. </p>
      <p> This is another paragraph. </p>
   </div>
</body>
</html>

登錄后復(fù)制

Example 2

的中文翻譯為:

示例2

在下面的示例中,我們添加了 div 元素的懸停效果。

首先,我們創(chuàng)建了“容器”div 元素,并添加了三個 div 元素作為其子元素。此外,我們?yōu)槊總€ div 元素賦予了不同的背景顏色。當(dāng)用戶將鼠標(biāo)懸停在 div 元素上時,每個 div 元素的顏色都會發(fā)生變化。

<html>
<head>
   <style>
      .container {
         display: flex;
         background-color: aqua;
         height: 200px;
         width: 400px;
         justify-content: space-around;
         align-items: center;
         border-radius: 12px;
      }
      .div1,
      .div2,
      .div3 {
         color: white;
         font-size: 2rem;
         border-radius: 12px;
         height: 100px;
         width: 100px;
      }
      .div1 {
         background-color: red;
      }
      .div2 {
         background-color: green;
      }
      .div3 {
         background-color: blue;
      }
      .div1:hover {
         background-color: pink;
      }
      .div2:hover {
         background-color: yellow;
      }
      .div3:hover {
         background-color: orange;
      }
   </style>
</head>
<body>
   <h2> Embedding the <i> Style sheet to the HTML document </i> </h2>
   <div class = "container">
      <div class = "div1">
         Div 1
      </div>
      <div class = "div2">
         Div 2
      </div>
      <div class = "div3">
         Div 3
      </div>
   </div>
</body>
</html>

登錄后復(fù)制

示例 3

我們已將下面示例中的樣式表嵌入到 HTML 文件中。我們使用 CSS 創(chuàng)建了圓圈。此外,我們還向圓圈添加了動畫。

我們已經(jīng)創(chuàng)建了“l(fā)arger”關(guān)鍵幀,通過50%改變圓的尺寸以及背景顏色,用戶可以在輸出中觀察到。

<html>
<head>
   <style>
      .circle {
         height: 200px;
         width: 200px;
         border-radius: 50%;
         background-color: red;
         animation: larger 2s linear infinite;
         margin: 120px;
      }
      @keyframes larger {
         0% {
            transform: scale(1);
            background-color: red;
         }
         50% {
            transform: scale(1.5);
            background-color: green;
         }
         100% {
            transform: scale(1);
            background-color: red;
         }
      }
   </style>
</head>
<body>
   <h2> Embedding the <i> Style sheet to the HTML document </i> </h2>
   <div class = "circle">
   </div>
</body>
</html>

登錄后復(fù)制

用戶學(xué)會了在 CSS 中嵌入樣式表。用戶需要在 標(biāo)簽之間添加 CSS,將 CSS 嵌入到整個網(wǎng)頁的 HTML 文件中,而不是使用外部 CSS 文件。不過,不建議在實時開發(fā)中使用嵌入式CSS,因為它會使代碼變得更加復(fù)雜。

以上就是CSS 中嵌入樣式表的使用的詳細(xì)內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!

分享到:
標(biāo)簽:CSS 嵌入 樣式表
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運動步數(shù)有氧達(dá)人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定