Unit IV - Lesson 1

4.1.1. Introduction to box model

(d) margin, border, padding, content

4.1.2. Content

<!doctype html>
<html>
	<head>
		<link href="style.css" rel="stylesheet" />
	</head>
	<body>
		<!-- Write your code below -->
		<div class='box1'>Box 1</div>
		<div id='box2'>Box 2</div>
	</body>
</html>

/* Write your code below */
.box1 {
	width: 200px;
	height: 250px;
	background-color: red;
	text-align: center;
	color: white;
}

#box2 {
	width: 150px;
	height: 150px;
	color: white;
	background-color: blue;
	text-shadow: 2px 2px 1px red;
	text-transform: uppercase;
	font-weight: bold;
}

4.1.3. Padding

<!doctype html>
<html>
	<head>
		<link href="style.css" rel="stylesheet" />
	</head>
	<body>
		<!-- Write your code below -->
		<div class="sqr1">Square 1</div>
		<div class="sqr2">Square 2</div>
	</body>
</html>

/* Write your code below */
.sqr1 {
	width: 100px;
	height: 100px;
	color: white;
	background-color: red;
	border: 1px dotted blue;
	padding: 15px 25px;
}
.sqr2 {
	width: 200px;
	height:200px;
	background-color: black;
	color: red;
	text-align: center;
	border: 3px dashed white;
	padding: 30px;
	text-shadow: 1px 1px 2px red;
}

4.1.4. Margin

<!doctype html>
<html>
	<head>
		<link href="style.css" rel="stylesheet" />
	</head>
	<body>
		<!-- Write your code below -->
		<div id="rect1">Rectangle 1</div>
		<div id="rect2">Rectangle 2</div>
	</body>
</html>

/* Write your code below */
#rect1 {
	width: 100px;
	height: 150px;
	border: 2px solid black;
	padding: 20px 10px;
	margin: 30px 20px;
}

#rect2 {
	width: 150px;
	height: 100px;
	border: 1px dashed blue;
	padding-top: 10px;
	padding-left: 50px;
	padding-right: 20px;
	padding-bottom: 30px;
	margin: 50px 10px 10px 30px;
}

4.1.5. content-box

(a) 190px

4.1.6. border-box

(a) 200px

4.1.7. Practice time!

<!doctype html>
<html>
	<head>
		<link href="style.css" rel="stylesheet" />
	</head>
	<body>
		<!-- Write your code below -->
		<div class="c-box">Content box</div>
		<div class="b-box">Border box</div>
	</body>
</html>

/* Write your code below */
.c-box {
	width: 200px;
	height: 200px;
	box-sizing: content-box;
	background-color: red;
	color: white;
	border: 2px dotted black;
	padding-top: 10px;
	padding-left: 20px;
	padding-right: 30px;
	padding-bottom: 40px;
	margin: 10px 20px 30px 20px;
	text-transform: uppercase;
	text-shadow: 2px 3px 1px white;
	font-style: italic;
}

.b-box {
	width: 200px;
	height: 200px;
	box-sizing: border-box;
	background-color: blue;
	color: white;
	border: 5px dashed white;
	padding: 40px 20px;
	margin: 30px;
	text-transform: uppercase;
	text-shadow: 2px 3px 1px white;
	font-style: italic;
}

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.