本篇文章跟大家介紹CSS中margin屬性的偏移量,有興趣的朋友可以看看。
話不多說,我們直接進入正題~
我們先來看一個具體的例子(相關推薦:CSS學習手冊)
程式碼入下:HTML檔案和CSS檔案。
MarginCollapsing01.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="MarginCollapsing01.css" /> </head> <body> <div class="BaseCanvas"> <div class="MarginFrame1">php中文网margin属性的偏移量</div> <div class="MarginFrame2">php中文网</div> </div> </body> </html>
MarginCollapsing01.css
.BaseCanvas { margin-left: 32px; margin-right: 32px; margin-top: 32px; width: calc(100%-64px); height: 320px; background-color: #E0E0E0; border: solid 1px #202020; } .MarginFrame1 { width: 80%; background-color: #fff2a9; border: solid 1px #ff6a00; margin-top: 40px; margin-bottom: 40px; margin-left: 12px; margin-right: 8px; } .MarginFrame2 { width: 80%; background-color: #9effb5; margin-top: 40px; margin-bottom: 40px; margin-left: 12px; margin-right: 8px; }
效果如下:
MarginFrame1 在底部設定40個像素的邊距,MarginFrame2設定頂部的40個像素的邊距。上框和下框之間的距離等於外框和上框之間的距離,從而不獲取具有每個邊緣的80像素的邊緣,並且可以確認只有40像素的距離。
更改margin大小
#編輯CSS檔案並將MarginFrame 1下方的邊距更改為60像素。
MarginCollapsing01.css
.BaseCanvas { margin-left: 32px; margin-right: 32px; margin-top: 32px; width: calc(100%-64px); height: 320px; background-color: #E0E0E0; border: solid 1px #202020; } .MarginFrame1 { width: 80%; background-color: #fff2a9; border: solid 1px #ff6a00; margin-top: 40px; margin-bottom: 60px; margin-left: 12px; margin-right: 8px; } .MarginFrame2 { width: 80%; background-color: #9effb5; margin-top: 40px; margin-bottom: 40px; margin-left: 12px; margin-right: 8px; }
效果如下:你可以看到上下框架的距離變寬了。
設定float的值
#程式碼如下:
MarginCollapsing02.html
#<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="MarginCollapsing02.css" /> </head> <body> <div class="BaseCanvas"> <div class="MarginFrame1">框架1</div> <div class="MarginFrame2">框架2</div> <div class="MarginFrame3">框架3</div> <div class="MarginFrame4">框架4</div> </div> </body> </html>
MarginCollapsing02.css
.BaseCanvas { margin-left: 32px; margin-right: 32px; margin-top: 32px; width: calc(100%-64px); height: 320px; background-color: #E0E0E0; border: solid 1px #202020; } .MarginFrame1 { width: 160px; float: left; background-color: #fff2a9; border: solid 1px #ff6a00; margin-top: 32px; margin-bottom: 48px; margin-left: 24px; margin-right: 24px; } .MarginFrame2 { width: 160px; float: left; background-color: #fff2a9; border: solid 1px #ff6a00; margin-top: 32px; margin-bottom: 48px; margin-left: 24px; margin-right: 24px; } .MarginFrame3 { width: 160px; float: left; background-color: #fff2a9; border: solid 1px #ff6a00; margin-top: 32px; margin-bottom: 48px; margin-left: 24px; margin-right: 24px; } .MarginFrame4 { width: 160px; float: left; background-color: #fff2a9; border: solid 1px #ff6a00; margin-top: 32px; margin-bottom: 48px; margin-left: 24px; margin-right: 24px; }
效果如下:
本篇文章到這裡就全部結束了,更多相關內容請關注php中文網的CSS影片教學專欄! ! !
以上是CSS中margin屬性的偏移量詳解(程式碼範例)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

React生態系統為我們提供了許多庫,所有庫都集中在拖放的相互作用上。我們有反應,反應,可愛dnd,

我可以說我經常使用背景折疊。 IT Wager IT幾乎從未在日常CSS工作中使用。但是在斯特凡·朱迪斯(Stefan Judis)的帖子中,我想起了它,

使用RequestAnimationFrame進行動畫化應該很容易,但是如果您還沒有徹底閱讀React的文檔,那麼您可能會遇到一些事情

聽著,我不是GraphQL專家,但我確實喜歡與之合作。作為前端開發人員,它向我曝光數據的方式非常酷。它就像一個菜單


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

記事本++7.3.1
好用且免費的程式碼編輯器

WebStorm Mac版
好用的JavaScript開發工具

Dreamweaver Mac版
視覺化網頁開發工具

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