如何在 HTML/CSS 中設定複選框大小?


要設定 HTML/HTML/CSS 中複選框的大小,我們將使用簡單的 CSS 屬性。我們將瞭解三種不同的方法來設定 HTML/CSS 中複選框的大小。

在這篇文章中,我們有兩個複選框,每個複選框都有一個標籤。我們的任務是在 HTML/CSS 中設定複選框的大小。

在 HTML/CSS 中設定複選框大小的方法

以下是在 HTML/CSS 中設定複選框大小的方法列表,我們將在本文中逐步解釋並提供完整的示例程式碼進行討論。

使用 height 和 width 屬性設定複選框大小

要設定 HTML/CSS 中複選框的大小,我們將使用簡單的 CSS 高度寬度 屬性來設定複選框的尺寸。

  • 我們使用 input 標籤和 type 屬性(設定為 checkbox)建立了兩個複選框,並使用了兩個 標籤 來命名複選框。
  • 然後,我們使用了 **"input[type=checkbox]"**,它選擇 HTML 文件中的複選框。
  • 我們使用了 **height** 和 **width** 屬性來設定複選框的尺寸,高度和寬度都設定為 30px。

示例

這是一個完整的示例程式碼,實現了上述步驟,使用 CSS **height** 和 **width** 屬性在 HTML/CSS 中設定複選框的大小。

<!DOCTYPE html>
<html>
<head>
   <style>
      input[type=checkbox] {
         width: 30px;
         height: 30px;
      }
   </style>
</head>
<body>
    <h3>
        To Set Checkbox Size in HTML/CSS
    </h3>
    <p>
        In this example we have used CSS <strong>
        height</strong> and <strong>width</strong>   
        property to set checkbox size in HTML/CSS.
    </p>
   <input type="checkbox" id="checkbox-1" 
          name="checkbox-1" value="1">
   <label for="checkbox-1">Option 1</label>
   <input type="checkbox" id="checkbox-2" 
          name="checkbox-2" value="2">
   <label for="checkbox-2">Option 2</label>
</body>
</html>

使用 transform 屬性設定複選框大小

在這種設定 HTML/CSS 中複選框大小的方法中,我們將使用 scale 函式和 transform 屬性。CSS scale() 函式在二維平面上調整元素的大小。

  • 前兩個步驟與方法一相同,用於建立和選擇複選框。
  • 然後,我們使用了 **"transform: scale(3);"** 屬性,它將複選框的大小縮放三倍。

示例

這是一個完整的示例程式碼,實現了上述步驟,使用 CSS **transform** 屬性在 HTML/CSS 中設定複選框的大小。

<!DOCTYPE html>
<html>
<head>
    <title>
        Set the size of checkbox
    </title>
    <style>
        input[type="checkbox"] {
            transform: scale(3);
            margin: 15px;
        }
    </style>
</head>
<body>
    <h3>
        To Set Checkbox Size in HTML/CSS
    </h3>
    <p>
        In this example we have used CSS <strong>
        transform</strong> property to set checkbox  
        size in HTML/CSS.
    </p>
    <input type="checkbox" id="option1">
    <label for="option1">Option 1</label>
    <br><br>
    <input type="checkbox" id="option2">
    <label for="option2">Option 2</label>
</body>
</html>

使用 zoom 屬性設定複選框大小

在這種方法中,我們使用了 CSS zoom 屬性在 HTML/CSS 中設定複選框的大小。CSS zoom 屬性類似於 transform 屬性的 scale 函式。它是非標準的,可以使用 scale() 函式代替 zoom 屬性。

  • 前兩個步驟與方法一相同,用於建立和選擇複選框。
  • 然後,我們使用了 **"zoom: 3;"** 屬性,它將複選框的大小縮放三倍。

示例

這是一個完整的示例程式碼,實現了上述步驟,使用 CSS **zoom** 屬性在 HTML/CSS 中設定複選框的大小。

<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        input[type="checkbox"] {
            zoom: 3; 
        }
    </style>
</head>
<body>
    <h3>
        To Set Checkbox Size in HTML/CSS
    </h3>
    <p>
        In this example we have used <strong>zoom
        </strong> property to set checkbox size 
        in HTML/CSS.
    </p>
    <input type="checkbox" id="option1">
    <label for="option1">Option 1</label>
    <br><br>
    <input type="checkbox" id="option2">
    <label for="option2">Option 2</label>
</body>
</html>

結論

在 HTML/CSS 中設定複選框的大小是一個簡單的過程。在這篇文章中,我們討論了三種不同的方法來設定 HTML/CSS 中複選框的大小,它們分別是:使用 CSS **height** 和 **width**,使用 **transform** 屬性以及使用 **zoom** 屬性。

更新於: 2024年9月9日

5K+ 瀏覽量

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.