Hello Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.

CSS Box Model

+6
coetphbrth
Clyntt
EzequielGo
JasonOmeter
jennielym
Admin
10 posters

Page 1 of 2 1, 2  Next

Go down

CSS Box Model Empty CSS Box Model

Post by Admin Wed Oct 11, 2017 12:46 pm

The CSS Box Model

In CSS, the term "box model" is used when talking about design and layout. The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content.

The image below illustrates the box model:

CSS Box Model Captur15

Explanation of the different parts:

   Content - The content of the box, where text and images appear
   Padding - Clears an area around the content. The padding is transparent
   Border - A border that goes around the padding and content
   Margin - Clears an area outside the border. The margin is transparent

The box model allows us to add a border around elements, and to define space between elements.

Example
div {
   width: 300px;
   border: 25px solid green;
   padding: 25px;
   margin: 25px;
}  

For any clarifications you can leave your comment below. Laughing


Last edited by Admin on Wed Oct 11, 2017 12:53 pm; edited 2 times in total

Admin
Admin

Posts : 28
Join date : 2017-09-15

http://kaylajem.forumotion.asia

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by jennielym Wed Oct 11, 2017 9:02 pm

is CSS is really important in creating a website? Very Happy Smile

jennielym
Newbie
Newbie

Posts : 2
Join date : 2017-10-11

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Admin Thu Oct 12, 2017 3:01 pm

jennielym wrote:is CSS is really important in creating a website? Very Happy Smile

Yes of course! Smile CSS are an important way to control how your Web pages look. CSS can control the fonts, text, colors, backgrounds, margins, and layout.

Admin
Admin

Posts : 28
Join date : 2017-09-15

http://kaylajem.forumotion.asia

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by JasonOmeter Fri Oct 13, 2017 7:37 pm

Good Evening Ma'am Kayla,

How can i compute the max total width and height of this box model?

,,
width: 300px;
border: 25px solid green;
padding: 25px;
margin: 25px;
,,

JasonOmeter
Master
Master

Posts : 7
Join date : 2017-10-13

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Admin Fri Oct 13, 2017 7:39 pm

JasonOmeter wrote:Good Evening Ma'am Kayla,

How can i compute the max total width and height of this box model?

,,
 width: 300px;
 border: 25px solid green;
 padding: 25px;
 margin: 25px;
,,

Hello Jason! In order to set the width and height of an element correctly in all browsers, you need to know how the box model works.

For example: Assume we want to style a <div> element to have a total width of 350px:

Here is the computation:

320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px

Admin
Admin

Posts : 28
Join date : 2017-09-15

http://kaylajem.forumotion.asia

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by JasonOmeter Fri Oct 13, 2017 8:00 pm

I have a question ma'am, what property if i want to have a margin of 100px top and 50px bottom, what should property i use? with a single declaration only.
And what are those individual property for margin.
tnx maam Smile

JasonOmeter
Master
Master

Posts : 7
Join date : 2017-10-13

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Admin Fri Oct 13, 2017 8:07 pm

JasonOmeter wrote:I have a question ma'am, what property if i want to have a margin of 100px top and 50px bottom, what should property i use? with a single declaration only.
And what are those individual property for margin.
tnx maam Smile

There's a CSS topic about margin. According to my research, it is possible to specify all the margin properties in one property. The margin property is a shorthand property for the following individual margin properties like, margin-top, margin-right,
margin-bottom and margin-left.

Here is the example:

p {
margin: 100px 150px 100px 80px;
}

Admin
Admin

Posts : 28
Join date : 2017-09-15

http://kaylajem.forumotion.asia

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by JasonOmeter Fri Oct 13, 2017 8:19 pm

Here's the output of what I've learned about the topic CSS Box Model.
tnx maam! Smile
<!DOCTYPE html>
<html>
<head>
<style>

div {
   height: 50px;
width: 500px;
   border: 20px inset cyan;
   padding-top:5px;
   margin-left:350px;
margin-top:150px;
text-align:center;
}

</style>
</head>
<body>
<div><h3>
Box Model Example
</h3></div>

</body>
</html>
CSS Box Model Boxmod12

JasonOmeter
Master
Master

Posts : 7
Join date : 2017-10-13

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Admin Fri Oct 13, 2017 8:24 pm

JasonOmeter wrote:Here's the output of what I've learned about the topic CSS Box Model.
tnx maam! Smile
<!DOCTYPE html>
<html>
<head>
<style>

div {
   height: 50px;
width: 500px;
   border: 20px inset cyan;
   padding-top:5px;
   margin-left:350px;
margin-top:150px;
text-align:center;
}

</style>
</head>
<body>
<div><h3>
Box Model Example
</h3></div>

</body>
</html>
CSS Box Model Boxmod12

Wow! Thank you for sharing your work Jason. Smile Feel free to share some of basic works in CSS especially in CSS Box Model Smile

Admin
Admin

Posts : 28
Join date : 2017-09-15

http://kaylajem.forumotion.asia

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by EzequielGo Sat Oct 14, 2017 2:00 pm

Admin wrote:
JasonOmeter wrote:Good Evening Ma'am Kayla,

How can i compute the max total width and height of this box model?

,,
 width: 300px;
 border: 25px solid green;
 padding: 25px;
 margin: 25px;
,,

Hello Jason! In order to set the width and height of an element correctly in all browsers, you need to know how the box model works.

For example: Assume we want to style a <div> element to have a total width of 350px:

Here is the computation:

320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px

Can you please elaborate this computation on how we can compute box model?

EzequielGo
Master
Master

Posts : 13
Join date : 2017-10-14

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Clyntt Sat Oct 14, 2017 2:24 pm

How can I set the padding of the div to 25px?

Clyntt
Master
Master

Posts : 9
Join date : 2017-10-14

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Admin Sat Oct 14, 2017 2:29 pm

EzequielGo wrote:
Admin wrote:
JasonOmeter wrote:Good Evening Ma'am Kayla,

How can i compute the max total width and height of this box model?

,,
 width: 300px;
 border: 25px solid green;
 padding: 25px;
 margin: 25px;
,,

Hello Jason! In order to set the width and height of an element correctly in all browsers, you need to know how the box model works.

For example: Assume we want to style a <div> element to have a total width of 350px:

Here is the computation:

320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px

Can you please elaborate this computation on how we can compute box model?

Hmm, okay. Here is the explanation. The total width of an element should be calculated like this:

Total element width = width + left padding + right padding + left border + right border + left margin + right margin

The total height of an element should be calculated like this:

Total element height = height + top padding + bottom padding + top border + bottom border + top margin + bottom margin

I hope it helps you a lot Smile

Admin
Admin

Posts : 28
Join date : 2017-09-15

http://kaylajem.forumotion.asia

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by coetphbrth Sat Oct 14, 2017 2:31 pm

hi maam kayla! I'm just wondering if you can apply the <marquee> on Css box model? and how? Thank you!

coetphbrth
Newbie
Newbie

Posts : 1
Join date : 2017-10-14

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Admin Sat Oct 14, 2017 2:35 pm

Clyntt wrote:How can I set the padding of the div to 25px?

Inside the div, assume you have background-color: blue, width: 200px and padding which is 25px. Here is the example:

div {
background-color: blue;
width: 200px;
padding: 25px;
}

Admin
Admin

Posts : 28
Join date : 2017-09-15

http://kaylajem.forumotion.asia

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Admin Sat Oct 14, 2017 2:40 pm

coetphbrth wrote:hi maam kayla! I'm just wondering if you can apply the <marquee> on Css box model? and how? Thank you!

I guess the marquee effect is allowed but I don't know how to use it. Is there somebody here in the forum knows how to use the marquee effect in CSS Box Model?

Admin
Admin

Posts : 28
Join date : 2017-09-15

http://kaylajem.forumotion.asia

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Lakura1997 Sat Oct 14, 2017 3:43 pm

Maam , what is the main function or main purpose of box model in css ? Please specify .

Thank you .

Lakura1997
Newbie
Newbie

Posts : 1
Join date : 2017-10-14

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Admin Sat Oct 14, 2017 4:13 pm

Lakura1997 wrote:Maam , what is the main function or main purpose of box model in css ? Please specify .

Thank you .

I must say CSS box model is the foundation of layout on the Web. Each element is represented as a rectangular box, with the box's content, padding, border, and margin built up around one another like the layers of an onion. As a browser renders a web page layout, it works out what styles are applied to the content of each box, how big the surrounding onion layers are, and where the boxes sit in relation to one another. Before understanding how to create CSS layouts, you need to understand the box model.

Admin
Admin

Posts : 28
Join date : 2017-09-15

http://kaylajem.forumotion.asia

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by SarahMae Sat Oct 14, 2017 4:25 pm

Admin wrote:
jennielym wrote:is CSS is really important in creating a website? Very Happy Smile

Yes of course! Smile CSS are an important way to control how your Web pages look. CSS can control the fonts, text, colors, backgrounds, margins, and layout.

If CSS properties are important what is the use of javascript? What's the difference between CSS and javascript?

SarahMae
Master
Master

Posts : 9
Join date : 2017-10-14

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by EzequielGo Sat Oct 14, 2017 4:29 pm

Admin wrote:
EzequielGo wrote:
Admin wrote:
JasonOmeter wrote:Good Evening Ma'am Kayla,

How can i compute the max total width and height of this box model?

,,
 width: 300px;
 border: 25px solid green;
 padding: 25px;
 margin: 25px;
,,

Hello Jason! In order to set the width and height of an element correctly in all browsers, you need to know how the box model works.

For example: Assume we want to style a <div> element to have a total width of 350px:

Here is the computation:

320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px

Can you please elaborate this computation on how we can compute box model?

Hmm, okay. Here is the explanation. The total width of an element should be calculated like this:

Total element width = width + left padding + right padding + left border + right border + left margin + right margin

The total height of an element should be calculated like this:

Total element height = height + top padding + bottom padding + top border + bottom border + top margin + bottom margin

I hope it helps you a lot Smile

Thankyou Admin. Very Happy

EzequielGo
Master
Master

Posts : 13
Join date : 2017-10-14

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by EzequielGo Sat Oct 14, 2017 4:31 pm

SarahMae wrote:
Admin wrote:
jennielym wrote:is CSS is really important in creating a website? Very Happy Smile

Yes of course! Smile CSS are an important way to control how your Web pages look. CSS can control the fonts, text, colors, backgrounds, margins, and layout.

If CSS properties are important what is the use of javascript? What's the difference between CSS and javascript?

Javascript is a programming language, while CSS is a style sheet language. CSS is a design language, it makes the HTML page look good, and javascript makes the page do good stuff. JS or javascript is a client-side programming language, not a design language. Laughing

EzequielGo
Master
Master

Posts : 13
Join date : 2017-10-14

Back to top Go down

CSS Box Model Empty Re: CSS Box Model

Post by Sponsored content


Sponsored content


Back to top Go down

Page 1 of 2 1, 2  Next

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum