首頁  >  文章  >  web前端  >  css怎樣去除按鈕之間的間距

css怎樣去除按鈕之間的間距

WBOY
WBOY原創
2021-12-02 11:58:153212瀏覽

在css中,可以利用「font-size」屬性來移除按鈕之間的間距,按鈕之間有間距是因為元素節點有文字節點,在縮排程式碼時會佔據寬度,只需要給按鈕元素的父元素會新增「font-size:0;」樣式即可移除間距。

css怎樣去除按鈕之間的間距

本教學操作環境:windows7系統、CSS3&&HTML5版、Dell G3電腦。

css怎樣去除按鈕之間的間距

#正常情況下,當我們設定了按鈕之後,按鈕之間會出現間距,範例如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <button>按钮</button>
    <button>按钮</button>
    <button>按钮</button>
</body>
</html>

輸出結果:

css怎樣去除按鈕之間的間距

這時候我們是需要設定按鈕元素的父元素,並為其父元素加上「font-size: 0;”樣式即可。

範例如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    body{
font-size:0;
}
</style>
</head>
<body>
    <button>按钮</button>
    <button>按钮</button>
    <button>按钮</button>
</body>
</html>

輸出結果:

css怎樣去除按鈕之間的間距

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    div{
        font-size:0;
        width:200px;
        height:100px;
        border:1px solid red;
}
</style>
</head>
<body>
    <div>
    <button>按钮</button>
    <button>按钮</button>
    <button>按钮</button>
    </div>
</body>
</html>

輸出結果:

css怎樣去除按鈕之間的間距

(學習影片分享:css影片教學

以上是css怎樣去除按鈕之間的間距的詳細內容。更多資訊請關注PHP中文網其他相關文章!

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