w3resource
HTML exercises

CSS Properties: How to specify that division elements should have padding and border included in the element?

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<title>How to specify that division elements should have padding and border included in the element</title>
<style type="text/css">
.div1 {
width: 300px;
height: 100px;
border: 1px solid #FF0000;
}
.div2 {
width: 300px;
height: 100px;    
padding: 50px;
border: 1px solid #4364FF;
}
</style>
</head>
<body>
<p>w3resource Tutorial</p>
<div class="div1">Box-size: smaller (width is 300px and height is 100px).</div>
<br>
<div class="div2">Box size: bigger (width is also 300px ,height is 100px and padding 50px).</div>
</body>
</html>

Live Demo:

See the Pen box-sizing-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes Yes

Go to Exercise page

What is the difficulty level of this exercise?