css中圖片左右邊距
CSS保證金屬性 (CSS margin property)
CSS Margins are used to space around any element, for this we use "margin" property in the CSS.
CSS邊距用于在任何元素之間留出空間,為此,我們在CSS中使用“ margin”屬性 。
Syntax:
句法:
Element{
margin: length|auto|initial|inherit;
}
保證金崩潰 (Margin Collapsing)
When two margins are touching each other vertically, they are collapsed. But when they touch horizontally, they do not collapse.
當兩個邊距垂直相互接觸時,它們將被折疊。 但是,當它們水平接觸時,它們不會塌陷。
Example:
例:
<!DOCTYPE html>
<head>
<style>
div {
margin: 20px;
}
</style>
</head>
<html>
<body>
<div>
Some content
</div>
<div>
Some more content
</div>
</body>
</html>
Output
輸出量
They will be 20px apart since vertical margins collapse over one and other. (The spacing will not be the sum of two margins.)
由于垂直邊距會彼此重疊,因此相距20px 。 (間距將不是兩個邊距的總和。)
在給定邊上應用保證金 (Apply Margin on a Given Side)
In CSS you can specify a given side to apply a margin too. The four properties provided for this purpose are,
在CSS中,您也可以指定給定邊以應用邊距。 為此目的提供的四個屬性是:
margin-left
左邊距
margin-right
右邊距
margin-top
上邊距
margin-bottom
底邊
Example:
例:
<!DOCTYPE html>
<head>
<style>
#myDiv {
margin-left: 30px;
height: 100px;
width: 100px;
background-color: red;
}
</style>
</head>
<html>
<body>
<div id="myDiv">
Some content
</div>
</body>
</html>
Output
輸出量
負邊距 (Negative Margins)
CSS has properties that can be set to negative values. This property can be used to overlap elements without absolute positioning.
CSS具有可以設置為負值的屬性。 此屬性可用于重疊元素而無需絕對定位。
Example:
例:
<!DOCTYPE html>
<head>
<style>
.over {
margin-left: -20px;
background-color: #f40;
color: #fff;
}
</style>
</head>
<html>
<body>
<div class="over">
Some content
</div>
</body>
</html>
Output
輸出量

保證金屬性簡化 (Margin property simplification)
Here the shorthand is used to specify margin in every direction without writing for every direction.
在這里,速記用于指定每個方向上的邊距,而無需為每個方向編寫。
Example:
例:
<!DOCTYPE html>
<head>
<style>
p {
margin: 1px;
/* 1px margin in all directions */
background-color: #f40;
color: #fff;
}
</style>
</head>
<html>
<body>
<p>
Some content
</p>
</body>
</html>
Output
輸出量

邊距CSS:length | auto | initial | inherit (CSS for margin: length|auto|initial|inherit)
margin: 1px;
margin: 1px 1px;
margin: 1px 1px 1px;
margin: 1px 1px 1px 1px;
左,右,上和下邊距 (Left, Right, Top and Bottom Margins)
To provide margins for left, right, top and bottom to an object, we can use margin-left, margin-right, margin-top and margin-bottom properties respectively.
要為對象的左側,右側,頂部和底部提供邊距,我們可以分別使用margin-left , margin-right , margin-top和margin-bottom屬性。
Example:
例:
<!DOCTYPE html>
<head>
<style>
p {
margin-left: 10px;
margin-right: 10px;
margin-top: 20px;
margin-bottom: 30px;
/* 1px margin in all directions */
background-color: #f40;
color: #fff;
}
</style>
</head>
<html>
<body>
<p>This is line One.</p>
<p>This is line Two.</p>
<p>This is line Three.</p>
<p>This is line Four.</p>
</body>
</html>
Output
輸出量
翻譯自: https://www.includehelp.com/code-snippets/margins-in-css.aspx
css中圖片左右邊距