CSS Margins
-
في هذه الخاصية تُستخدم الهوامش لإنشاء مساحة حول elements .
الهوامش : تطبق خارج Element
شوف الصورة التالية :

<!DOCTYPE html>
<html>
<style>
div{
border: 2px solid gray;
border-radius: 5px / 8px;
font-size: larger;
margin: 70px;
}
</style>
<body><div> Margins تطبيق </div></body>
</html>

margin:<Value>;
margin: all;
margin: 70px;
margin: top_bottom left_right;
div { margin: 0 auto; }
margin: top right_left bottom;
div { margin: 2px 4px 6px; }
margin: top right bottom left;
في حال توفير أربع قيم، سيتم تطبيق القيمة الأولى على الجزء العلوي. وسيتم تطبيق القيمة الثانية على الجانب الأيمن. وسيتم تطبيق القيمة الثالثة على الجزء السفلي. وسيتم تطبيق القيمة الرابعة على الجانب الايسر.
div { margin: 5px 10px 12px 8px; }
القيمة | الوصف |
fixed | قيمة ثابتة تكون ب px, em امثلة div { margin: 5px; } div { margin: 4em 5px; } div { margin: 2px 5px 10px; } div { margin: 4px 5px 2px 3px; } |
percentage | قيمة بنسبة امثلة div { margin: 8%; } div { margin: 4% 5%; } div { margin: 2% 5% 8%; } div { margin: 4% 5% 2% 3%; } |
fixed and percentage (in combination) | يمكن تطبيق قيمة ثابتة بالإضافة الى نسبة div { margin: 4% 5px; } div { margin: 2em 5% 8px; } div { margin: 4px 5em 2% 3px; } |
auto | تستخدم لتوسيط الكتل blocks امثلة div { margin: 0 auto; } div { margin: 4% auto; } |
inherit | سيرث العنصر الهامش من parent element مثال div { margin: inherit; } |
Div.One {
border-style: solid;
border-width: 5px; /* 5px top and bottom, Left and Right */
border-color: #FF0000; /* #FF0000 color for top and bottom, Left and Right */
margin: 10px;
}
Div.two {
border-style: solid;
border-width: 20px medium; /* 20px top and bottom, medium for left ang right */
border-color: #FF0000 black; /* #FF0000 color for top and bottom, black for Left and Right */
margin: 10px 10px;
}
Div.three {
border-style: solid;
border-width: 25px thin 4px ; /* 25px top, thin for right and left, 4px for bottom */
border-color: #FF0000 black yellow; /* #FF0000 color for top, black for right and left, yellow for bottom */
margin: 10px 10px 5em;
}
Div.four {
border-style: solid;
border-width: 25px thin 4px meduim ; /* 25px top, thin for right 4px for bottom, medium for left */
border-color: rgb(0,0,0) #FF0000 black yellow; /* rgb(0,0,0) for top, #FF0000 for right ,black for bottom ,yellow for left */
margin: 10px 10px 5em 10px;
}
Div.One {
border-style: solid;
border-width: 5px; /* 5px top and bottom, Left and Right */
border-color: #FF0000; /* #FF0000 color for top and bottom, Left and Right */
margin: 10%;
}
Div.two {
border-style: solid;
border-width: 20px medium; /* 20px top and bottom, medium for left ang right */
border-color: #FF0000 black; /* #FF0000 color for top and bottom, black for Left and Right */
margin: 10% 10%;
}
Div.three {
border-style: solid;
border-width: 25px thin 4px ; /* 25px top, thin for right and left, 4px for bottom */
border-color: #FF0000 black yellow; /* #FF0000 color for top, black for right and left, yellow for bottom */
margin: 10% 10% 5%;
}
Div.four {
border-style: solid;
border-width: 25px thin 4px meduim ; /* 25px top, thin for right 4px for bottom, medium for left */
border-color: rgb(0,0,0) #FF0000 black yellow; /* rgb(0,0,0) for top, #FF0000 for right ,black for bottom ,yellow for left */
margin: 10% 10v 5% 10%;
}
اترك تعليقك