<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.paragraph-one{
background-color:red;
width: 80px;
height: 80px;
display:inline-block;
margin: 20px;
}
#paragraph-two{
background-color: blue;
width: 80px;
height: 80px;
display: inline-block;
margin:20px;
}
</style>
</head>
<body>
<div class="paragraph-one"></div>
<div id="paragraph-two"></div>
<div class="paragraph-one"></div>
</body>
</html>
مهمة التدرب على Class
اكواد html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Class مهمة التدرب على ال</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="Red"></div>
<div id="Green"></div>
<div class="Red"></div>
</body>
</html>
اكواد css
div{
display: inline-block;
width: 400px;
height: 400px;
margin: 30px;
}
.Red{
background-color: red;
}
#Green{
background-color: green;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.redbox{
border: 10px solid red;
width :150px;
height: 100px;
background: red ;
margin: 10px ;
display: inline-block;
}
#second-box{
border: 10px solid green;
width :150px;
height: 100px;
background: green;
margin :10px ;
display :inline-block;
}
}
</style>
</head>
<body>
<div class="redbox"></div>
<div id="second-box"></div>
<div class="redbox"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div{
width: 80px;
height: 80px;
margin: 10px;
display: inline-block;
}
.one{
background-color: red;
}
.tow{
background-color: green;
}
.three{
background-color: red;
}
</style>
</head>
<body>
<div class="one"></div>
<div class="tow"></div>
<div class="three"></div>
</body>
</html>
رائع ي شباب كله مضبوط
بسام لاحظ ان التنسيقات الي في الكلاسين one
و two
متطابقة، حيث كلاً من الكلاسين بيعطوا لون خلفية احمر لذا لا داعي لان تكرر كلاس اخر بنفس التنسيقات وبإمكانك إستخدام كلاس واحد فهذه هي فكرة الكلاسات مثلاً هكذا:
<div class="one"></div>
<div class="tow"></div>
<div class="one"></div>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div{
width:150px;
height:150px;
display:inline-block;
margin:50px;
}
.red{
background-color:red;
}
.green{
background-color:green;
}
.red{
background-color:red;
}
</style>
</head>
<body>
<div class="red"></div>
<div class=green></div>
<div class="red"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>class</title>
<style>
div{
width: 150px;
height: 150px;
display: inline-block;
margin: 30px;
}
.red{
background-color: red;
}
.green{
background-color: green;
}
</style>
</head>
<body>
<div class="red"></div>
<div class="green"></div>
<div class="red"></div>
</body>
</html>
عمل رائع سالم
ملاحظة واحدة:
لا داعي لتكرار الكلاس .red
مرتين في الكود التالي:
.red{
background-color:red;
}
.green{
background-color:green;
}
.red{
background-color:red;
}
يكفي تعريفة مرة واحدة فقط وإستخدامة كم ما اردت بالشكل التالي:
.red{
background-color:red;
}
.green{
background-color:green;
}
Perfect
شكرا على التنبيه
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div{
width:150px;
height:150px;
display:inline-block;
margin:50px;
}
.red{
background-color:red;
}
.green{
background-color:green;
}
</style>
</head>
<body>
<div class="red"></div>
<div class=green></div>
<div class="red"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title> مهمة التدرب على الـ class</title>
</head>
<style>
div{
display: inline-block;
height: 300px;
width: 300px;
margin: 30px;
}
.one{
background-color: red;
}
.two{
background-color: green;
}
</style>
<body>
<div class="one"></div>
<div class="two"></div>
<div class="one"></div>
</body>
</html>
سؤال إذا قمنا بوضع background -color; green داخل div ولم نقم بتحديد class=two للصندوق الأخضر هل ستكون طرقة كتابة الكود سليمة.
نعم ستكون سليمة ، غالباً تقوم بعمل تنسيق افتراضي ليقوم تنسيق اخر بالطغيان عليه.
لكن في بعض الحالات فصلها يجعل الكود اكثر تنظيماً ومقرؤ فعندما تلاقي div عندة كلاس باسم deleted مثلاً في اكواد ال html تعرف بأن هذا ال div سيتم تطبيق عليه تنسيقات معينه بدون الحاجة لأن تقوم بعمل تحليل لاكواد ال css وهذا هو الانسب في حال كان حجم التطبيق كبير
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Id</title>
<style>
div{
width:200px;
height:200px;
margin:30px 30px 0 30px;
display:inline-block;
}
.One-Three{
background-color:red
}
.center{
background-color:green
}
</style>
</head>
<body>
<div class="One-Three"></div>
<div class="center"></div>
<div class="One-Three"></div>
</body>
</html>
ممتاز
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>projectx</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="one"> </div>
<div id="two"> </div>
<div class="one"> </div>
</body>
</html>
CSS
div{
width: 200px;
height: 200px;
display: inline-block;
margin: 10px;
}
.one{
background-color: red;
}
#two{
background-color: blue;
}
مية مية
<!DOCTYPE html>
<html>
<head>
<title>class</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
div{
display:inline-block;
width:200px;
height:200px;
margin:30px ;
}
.red{
background-color:red;
}
#green{
background-color:green;
}
</style>
</head>
<body>
<div class="red"></div>
<div id="green"></div>
<div class="red"></div>
</body>
</html>
Hi There!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div{
float: left;
height: 50px;
width: 50px;
margin: 10px;
}
.red{
background-color: red;
}
.green{
background-color: green;
}
</style>
</head>
<body>
<div class="red"></div>
<div class="green"></div>
<div class="red"></div>
</body>
</html>