5 5

Heim  >  Artikel  >  Web-Frontend  >  Ein Beispiel dafür, wie der Marge ein negativer Wert zugewiesen wird

Ein Beispiel dafür, wie der Marge ein negativer Wert zugewiesen wird

零下一度
零下一度Original
2017-06-28 09:44:581601Durchsuche

1. Margin-Top ist ein negatives Pixel. Der Offset-Wert ist relativ zu sich selbst und nachfolgende Elemente sind betroffen:

 1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4     <meta charset="UTF-8" /> 5     <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6     <title>margin不同赋值情况(负值,百分数)</title> 7     <style type="text/css"> 8         *{ 9             margin: 0;10             padding: 0;11         }12         /*父元素样式*/13         .p{14             margin: 100px;15             width: 500px;16             height: 500px;17             border: 1px solid red;18         }19         .c1{20             width: 200px;21             height: 200px;22             border: 1px solid blue;23             /*margin-top为负值像素,偏移值相对于自身,其后元素受影响*/24             margin-top: -20px;25         }26         .c2{27             width: 200px;28             height: 200px;29             border: 1px solid blue;30         }31     </style>32 </head>33 <body>34     <div class="p">35         <div class="c1">36             子元素137         </div>38         <div class="c2">39             子元素2(元素2跟着上移了)40         </div>41     </div>42 </body>43 </html>
Effekt:

2. Rand-links ist ein negatives Pixel

Rand- left ist Bei negativen Pixeln ist der Offsetwert relativ zu sich selbst und nachfolgende Elemente sind nicht betroffen. Siehe den folgenden Code:

 1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4     <meta charset="UTF-8" /> 5     <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6     <title>margin不同赋值情况(负值,百分数)</title> 7     <style type="text/css"> 8         *{ 9             margin: 0;10             padding: 0;11         }12         /*父元素样式*/13         .p{14             margin: 100px;15             width: 500px;16             height: 500px;17             border: 1px solid red;18         }19         .c1{20             width: 200px;21             height: 200px;22             border: 1px solid blue;23             /*margin-left为负值像素,偏移值相对于自身,其后元素不受影响*/24             margin-left: -20px;25         }26         .c2{27             width: 200px;28             height: 200px;29             border: 1px solid blue;30         }31     </style>32 </head>33 <body>34     <div class="p">35         <div class="c1">36             子元素137         </div>38         <div class="c2">39             子元素2(子元素2不受影响)40         </div>41     </div>42 </body>43 </html>
Effekt:

3. Margin-top ist ein negativer Prozentsatz

margin-top ist ein negativer Prozentsatz sind betroffen. Siehe folgenden Code:

 1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4     <meta charset="UTF-8" /> 5     <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6     <title>margin不同赋值情况(负值,百分数)</title> 7     <style type="text/css"> 8         *{ 9             margin: 0;10             padding: 0;11         }12         /*父元素样式*/13         .p{14             margin: 100px;15             width: 500px;16             height: 500px;17             border: 1px solid red;18         }19         .c1{20             width: 200px;21             height: 200px;22             border: 1px solid blue;23             /*margin-top为负值百分数,偏移值相对于父元素,其后元素受影响*/24             margin-top: -20%;25         }26         .c2{27             width: 200px;28             height: 200px;29             border: 1px solid blue;30         }31     </style>32 </head>33 <body>34     <div class="p">35         <div class="c1">36             子元素137         </div>38         <div class="c2">39             子元素2(子元素2受影响)40         </div>41     </div>42 </body>43 </html>
Effekt:

4. margin-left ist ein negativer Prozentsatz

Rand links ist ein negativer Prozentsatz. Nachfolgende Elemente sind nicht betroffen :

 1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4     <meta charset="UTF-8" /> 5     <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6     <title>margin不同赋值情况(负值,百分数)</title> 7     <style type="text/css"> 8         *{ 9             margin: 0;10             padding: 0;11         }12         /*父元素样式*/13         .p{14             margin: 100px;15             width: 500px;16             height: 500px;17             border: 1px solid red;18         }19         .c1{20             width: 200px;21             height: 200px;22             border: 1px solid blue;23             /*margin-left为负值百分数,偏移值相对于父元素,其后元素不受影响*/24             margin-left: -20%;25         }26         .c2{27             width: 200px;28             height: 200px;29             border: 1px solid blue;30         }31     </style>32 </head>33 <body>34     <div class="p">35         <div class="c1">36             子元素137         </div>38         <div class="c2">39             子元素2(子元素2不受影响)40         </div>41     </div>42 </body>43 </html>
5
margin-right ist ein negatives Pixel und legt keine Breite fest

margin-right ist ein negatives Pixel und legt keine Breite und keinen Versatzwert fest, nachfolgende Elemente werden nicht beeinflusst und ihre eigene Breite wird größer. Siehe den folgenden Code:

Effekt:

 1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4     <meta charset="UTF-8" /> 5     <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6     <title>margin不同赋值情况(负值,百分数)</title> 7     <style type="text/css"> 8         *{ 9             margin: 0;10             padding: 0;11         }12         /*父元素样式*/13         .p{14             margin: 100px;15             width: 500px;16             height: 500px;17             border: 1px solid red;18         }19         .c1{20             /*关键点:不设置宽度*/21             /*width: 200px;*/22             height: 200px;23             border: 1px solid blue;24             /*margin-right为负值像素且不设置宽度,无偏移值,其后元素不受影响*/25             margin-right: -100px;26         }27         .c2{28             width: 200px;29             height: 200px;30             border: 1px solid blue;31         }32     </style>33 </head>34 <body>35     <div class="p">36         <div class="c1">37             子元素138         </div>39         <div class="c2">40             子元素2(子元素2不受影响)41         </div>42     </div>43 </body>44 </html>

6. Margin-right ist ein negativer Prozentsatz und legt nicht die Breite fest ist ein negativer Prozentsatz und legt die Breite nicht fest und die Breite selbst wird breiter (Der Breitenwert ist der Breitenwert des übergeordneten Elements * Prozentsatz), und nachfolgende Elemente sind nicht betroffen :

Effekt:

 1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4     <meta charset="UTF-8" /> 5     <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6     <title>margin不同赋值情况(负值,百分数)</title> 7     <style type="text/css"> 8         *{ 9             margin: 0;10             padding: 0;11         }12         /*父元素样式*/13         .p{14             margin: 100px;15             width: 500px;16             height: 500px;17             border: 1px solid red;18         }19         .c1{20             /*关键点:不设置宽度*/21             /*width: 200px;*/22             height: 200px;23             border: 1px solid blue;24             /*margin-right为负值百分数且不设置宽度,无偏移值,自身宽度变宽(宽度值为父元素宽度值*百分比),其后元素不受影响*/25             margin-right: -20%;26         }27         .c2{28             width: 200px;29             height: 200px;30             border: 1px solid blue;31         }32     </style>33 </head>34 <body>35     <div class="p">36         <div class="c1">37             子元素138         </div>39         <div class="c2">40             子元素2(子元素2不受影响)41         </div>42     </div>43 </body>44 </html>
7 >
margin-bottom: ein negatives Pixel ohne Versatzwert, und nachfolgende Elemente sind betroffen (nach oben verschieben), siehe folgenden Code:

Wirkung:

 1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4     <meta charset="UTF-8" /> 5     <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6     <title>margin不同赋值情况(负值,百分数)</title> 7     <style type="text/css"> 8         *{ 9             margin: 0;10             padding: 0;11         }12         /*父元素样式*/13         .p{14             margin: 100px;15             width: 500px;16             height: 500px;17             border: 1px solid red;18         }19         .c1{20             width: 200px;21             height: 200px;22             border: 1px solid blue;23             /*margin-bottom:为负值像素,自身无偏移值,,其后元素受影响(上移了)*/24             margin-bottom: -100px;25         }26         .c2{27             width: 200px;28             height: 200px;29             border: 1px solid blue;30         }31     </style>32 </head>33 <body>34     <div class="p">35         <div class="c1">36             子元素137         </div>38         <div class="c2">39             子元素2(子元素2受影响,上移了)40         </div>41     </div>42 </body>43 </html>
8

, margin-bottom: ist ein negativer Prozentsatz

margin-bottom: ist ein negativer Prozentsatz, hat keinen Versatzwert und nachfolgende Elemente sind betroffen (nach oben verschoben, die nach oben verschobene Größe ist der Breitenwert des übergeordneten Elements * 20 %), siehe folgenden Code:

Wirkung:

 1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4     <meta charset="UTF-8" /> 5     <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6     <title>margin不同赋值情况(负值,百分数)</title> 7     <style type="text/css"> 8         *{ 9             margin: 0;10             padding: 0;11         }12         /*父元素样式*/13         .p{14             margin: 100px;15             width: 800px;16             height: 500px;17             border: 1px solid red;18         }19         .c1{20             width: 200px;21             height: 200px;22             border: 1px solid blue;23             /*margin-bottom:为负值百分数,自身无偏移值,,其后元素受影响(上移了,上移大小为父元素宽度值*20%)*/24             margin-bottom: -20%;25         }26         .c2{27             width: 200px;28             height: 200px;29             border: 1px solid blue;30         }31     </style>32 </head>33 <body>34     <div class="p">35         <div class="c1">36             子元素137         </div>38         <div class="c2">39             子元素2(子元素2受影响,上移了)40         </div>41     </div>42 </body>43 </html>

Zusammenfassung: Das Obige ist der Fall, bei dem dem Rand ein negativer Wert zugewiesen wird, der sich selbst versetzen kann (oder nicht versetzen kann), nachfolgende Elemente betroffen sind (oder nicht betroffen sind) und die Breite von sich selbst zunimmt (oder erhöht sich nicht). Es wird viele verschiedene Anwendungsszenarien geben, bitte wählen Sie mit Bedacht aus.

Das obige ist der detaillierte Inhalt vonEin Beispiel dafür, wie der Marge ein negativer Wert zugewiesen wird. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn