Write CSS to create a box with border, padding and rounded corners
Description: Create a box that has a 2px green border, 20px padding, 10px rounded corners and a light green background.
Hint:
- Use
border,padding,border-radiusandbackground-color.
CSS for a box with rounded corners
<style>
.box {
width: 300px;
padding: 20px;
border: 2px solid green;
border-radius: 10px;
background-color: #e8f5e9;
}
</style>
<div class="box">This is a box with rounded corners.</div>
Output in the browser:
Output in the browser
This is a box with rounded corners.
How it works
paddingadds space inside the border.border-radiusrounds the corners.
Read CSS Borders and CSS Box Model.
Learn more about the similar topics:
| Tutorials |
|---|
| CSS Borders |
| Rounded Corners in CSS |
| CSS Height and Width |
| CSS Padding |
| CSS Margins |
| CSS Box Model |
| CSS Outline |
| Exercises & Assignments |
|---|
| Write CSS to create a box with border, padding and rounded corners |
| Write CSS to create a circle and a pill-shaped button |
| Write CSS to style a login form |
| Interview Questions & Answers |
|---|
| What is the CSS box model? |
| What is the difference between margin and padding in CSS? |
| What is box-sizing: border-box in CSS? |