aboutsummaryrefslogtreecommitdiff
path: root/files/fa/web/css/margin/index.html
blob: c29a75ea06b44cf14e7f005cbd56066550b70ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
---
title: margin
slug: Web/CSS/margin
translation_of: Web/CSS/margin
---
<div dir="rtl">{{CSSRef()}}</div>

<h2 dir="rtl" id="خلاصه_مطلب">خلاصه مطلب</h2>

<p dir="rtl">خواصیت margin درCSS حاشیه را برای چهار طرف عنصر مشخص می کند. این خواصیت خلاصه شده چهار خواصیت {{ Cssxref("margin-top") }} ،  {{ Cssxref("margin-right") }} ، {{ Cssxref("margin-bottom") }} و {{ Cssxref("margin-left") }} می باشد که برای جلوگیری از مقدار دهی به هر کدام از این خواص تعبیه شده است.</p>

<p dir="rtl">همچنین قابلیت مقداردهی با مقادیر منفی را نیز داراست.</p>

<h2 dir="rtl" id="روش_استفاده">روش استفاده</h2>

<pre class="brush:css" dir="rtl">/* به هر چهار جهت این مقدار اعمال می گردد */
margin: 1em;

/*افقی (قسمت چپ و راست) | عمودی (قسمت بالا و پایین) */
margin: 5% auto;

/* پایین | افقی(چپ و راست) | بالا */
margin: 1em auto 2em;

/* چپ | پایین | راست | بالا */
margin: 2px 1em 0 auto;

margin: وارث;
</pre>

<h3 dir="rtl" id="مقادیر">مقادیر</h3>

<p dir="rtl">یک، دو، سه و یا چهار عدد از مقادیر زیر را می پذیرد:</p>

<dl>
 <dt dir="rtl"><code>&lt;length&gt;</code></dt>
 <dd dir="rtl">مقدار ثابتی را مشخص می کند. مقادیر منفی مورد قبول هستند. مقادیر قابل قبول را در {{cssxref("&lt;length&gt;")}} مشاهده کنید.</dd>
 <dt dir="rtl"><code>&lt;percentage&gt;</code></dt>
 <dd dir="rtl">A {{cssxref("&lt;percentage&gt;")}} relative to the <strong>width</strong> of the containing block. Negative values are allowed.</dd>
 <dt dir="rtl"><code>auto</code></dt>
 <dd dir="rtl"><code>auto </code>is replaced by some suitable value, e.g. it can be used for centering of blocks.<br>
 <code>div { width:50%;  margin:0 auto; }</code> centers the div container horizontally.</dd>
</dl>

<ul dir="rtl">
 <li><strong>One</strong> single value applies to all <strong>four sides</strong>.</li>
 <li><strong>Two</strong> values apply first to <strong>top and bottom</strong>, the second one to <strong>left and right</strong>.</li>
 <li><strong>Three</strong> values apply first to <strong>top</strong>, second to <strong>left and right</strong> and third to <strong>bottom</strong>.</li>
 <li><strong>Four</strong> values apply to <strong>top</strong>, <strong>right</strong>, <strong>bottom</strong> and <strong>left</strong> in that order (clockwise).</li>
</ul>

<h3 dir="rtl" id="Formal_syntax">Formal syntax</h3>

<pre class="syntaxbox" dir="rtl">{{csssyntax("margin")}}</pre>

<h2 dir="rtl" id="Examples">Examples</h2>

<h3 dir="rtl" id="Simple_example">Simple example</h3>

<h4 dir="rtl" id="HTML">HTML</h4>

<pre class="brush: html" dir="rtl">&lt;div class="ex1"&gt;
  margin:     auto;
  background: gold;
  width:      66%;
&lt;/div&gt;
&lt;div class="ex2"&gt;
  margin:     20px 0 0 -20px;
  background: gold;
  width:      66%;
&lt;/div&gt;</pre>

<h4 dir="rtl" id="CSS">CSS</h4>

<pre class="brush: css; highlight:[2,7]" dir="rtl">.ex1 {
  margin: auto;
  background: gold;
  width: 66%;
}
.ex2 {
  margin: 20px 0px 0 -20px;
  background: gold;
  width: 66%;
}</pre>

<p dir="rtl">{{ EmbedLiveSample('Margin_Exemples') }}</p>

<h3 dir="rtl" id="Another_example">Another example</h3>

<pre class="brush: css" dir="rtl">margin: 5%;                /* all sides 5% margin */

margin: 10px;              /* all sides 10px margin */

margin: 1.6em 20px;        /* top and bottom 1.6em, left and right 20px margin */

margin: 10px 3% 1em;       /* top 10px, left and right 3%, bottom 1em margin */

margin: 10px 3px 30px 5px; /* top 10px, right 3px, bottom 30px, left 5px margin */

margin: 1em auto;          /* 1em margin on top and bottom, box is horizontally centered */

margin: auto;              /* box is horizontally centered, 0 margin on top and bottom */
</pre>

<h2 dir="rtl" id="Horizontal_centering_with_margin_0_auto">Horizontal centering with <code>margin: 0 auto;</code></h2>

<p dir="rtl">To center something horizontally in modern browsers, use <code><a href="/en-US/docs/Web/CSS/display">display</a>: flex; <a href="/en-US/docs/Web/CSS/justify-content">justify-content</a>: center;</code> .</p>

<p dir="rtl">However, in older browsers like IE8-9, these are not available. In order to center an element inside its parent, use <code>margin: 0 auto;</code></p>

<h2 dir="rtl" id="Specifications">Specifications</h2>

<table class="standard-table" dir="rtl">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('CSS3 Box', '#margin', 'margin') }}</td>
   <td>{{ Spec2('CSS3 Box') }}</td>
   <td>No significant change.</td>
  </tr>
  <tr>
   <td>{{ SpecName('CSS3 Transitions', '#animatable-css', 'margin') }}</td>
   <td>{{ Spec2('CSS3 Transitions') }}</td>
   <td>Defines <code>margin</code> as animatable.</td>
  </tr>
  <tr>
   <td>{{ SpecName('CSS2.1', 'box.html#margin-properties', 'margin') }}</td>
   <td>{{ Spec2('CSS2.1') }}</td>
   <td>Removes its effect on inline elements.</td>
  </tr>
  <tr>
   <td>{{ SpecName('CSS1', '#margin', 'margin') }}</td>
   <td>{{ Spec2('CSS1') }}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 dir="rtl" id="Browser_compatibility">Browser compatibility</h2>

<p dir="rtl">{{ CompatibilityTable() }}</p>

<div dir="rtl" id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0</td>
   <td>{{ CompatGeckoDesktop("1") }}</td>
   <td>3.0</td>
   <td>3.5</td>
   <td>1.0 (85)</td>
  </tr>
  <tr>
   <td><code>auto</code> value</td>
   <td>1.0</td>
   <td>{{ CompatGeckoDesktop("1") }}</td>
   <td>6.0 (strict mode)</td>
   <td>3.5</td>
   <td>1.0 (85)</td>
  </tr>
 </tbody>
</table>
</div>

<div dir="rtl" id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0</td>
   <td>{{ CompatGeckoMobile("1") }}</td>
   <td>6.0</td>
   <td>6.0</td>
   <td>1.0</td>
  </tr>
 </tbody>
</table>
</div>

<h2 dir="rtl" id="See_also">See also</h2>

<ul>
 <li dir="rtl"><a class="internal" href="/en/CSS/margin_collapsing" title="en/CSS/margin collapsing">Margin collapsing</a></li>
</ul>