How to Make Full-Width Items in a Container with Padding in CSS?
I'm trying to create a layout where blue and green rectangles (background-color) take the full width of the screen while the text should keeping a padding inside the container. Here is my HTML and CSS code:
https://jsfiddle.net/6hyo07mb/1/
The problem is that the rectangles elements are not taking the full width of the container because of the padding. How can I make these items take the full width of the screen while keeping the container's padding?
https://jsfiddle.net/6hyo07mb/1/
The problem is that the rectangles elements are not taking the full width of the container because of the padding. How can I make these items take the full width of the screen while keeping the container's padding?
<div class="container">
<div class="item">Section 1</div>
<div class="item">Section 2</div>
<div class="item">Section 3</div>
<div class="item">Section 4</div>
<div class="item">Section 5</div>
</div>html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.container {
background-color: red;
width: 100%;
height: 100%;
padding: 0 20px;
}
.item {
width: 100%;
height: 20%;
}
.item:nth-child(odd) {
background-color: blue;
}
.item:nth-child(even) {
background-color: green;
}Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
