CSS Properties: How to specify that division elements should have padding and border included in the element?
Solution:
HTML Code:
Explanation:
- The .div1 CSS rule defines the styling for elements with class "div1".
- The .div2 CSS rule defines the styling for elements with class "div2".
- Both rules set the width and height of the elements to 300 pixels by 100 pixels respectively.
- .div1 sets a red border with 1 pixel width.
- .div2 sets a blue border with 1 pixel width and adds 50 pixels of padding to all sides of the element.
Live Demo:
See the solution in the browser
Supported browser
![]() |
![]() |
![]() |
![]() |
![]() |
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.