iT邦幫忙

2024 iThome 鐵人賽

DAY 14
0

繼上一篇有提到內邊距padding,邊界間距也不僅只有內部,當然還有外部啦~
而外部邊距我們就是用margin~也就是我們今天的主角!!

<margin>主要負責元素與元素之間的間距,也就是元素外部的邊界間距
他主要也有分上下左右
margin-top: 外部上方邊距
margin-bottom: 外部下方邊距
margin-left: 外部左邊邊距
margin-right: 外部右邊邊距

https://ithelp.ithome.com.tw/upload/images/20240921/20168468ACEtBpB6hW.png

那我們就直接用例子來看看margin該如何使用吧~

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>padding</title>
    <style>
        .txt{
            display: flex;
        }
    </style>
</head>
<body>
    <div class="txt">
        <button class="bt1">按鈕1</button>
        <button class="bt2">按鈕1</button>
        <button class="bt3">按鈕1</button>
    </div>
</body>
</html>

https://ithelp.ithome.com.tw/upload/images/20240921/20168468j7lLLOlm2R.png

如果沒有使用margin就會呈現所有元素之間都沒有間距,都是連在一起的
那如果使用了之後,就會出現間距,像以下這張圖
https://ithelp.ithome.com.tw/upload/images/20240921/20168468pC1c6tUk7n.png

    .bt1{
        margin-left: 20px;
        margin-top: 10px;
    }
    .bt2{
        margin-left: 20px;
        margin-top: 10px;
    }
    .bt3{
        margin-left: 20px;
        margin-top: 10px;
    }

而我主要加上了margin-topmargin-left這兩個,在調整頁面時,不一定上下左右都會使用到,
margin-topmargin-left是最常使用到的

最後,透過這張圖來了解paddingmargin之間的差別吧
https://ithelp.ithome.com.tw/upload/images/20240921/20168468DwdulMK5wr.png

今天就先到這啦~~~~/images/emoticon/emoticon11.gif


上一篇
Day13.CSS<padding>標籤
下一篇
Day15.CSS<display>標籤
系列文
Web前端的探索:30天的驚奇之旅22
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言