I'm struggling to achieve responsive column. Currently all columns are not the same height. When the screen gets smaller, the paragraphs are not the same level, I am trying to make them the same level no matter what screen size. My next problem is the button will also not be the same level in all columns.
Bellow is currently my HTML:
<div class="container">
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" /> <h2>Fencing and Gates</h2>
<h2>test heading text long</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. Maecenas id leo at elit vestibulum sagittis at in ex. Cras vulputate laoreet dictum. Vestibulum nec quam placerat, blandit orci in, hendrerit ante. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text longer </h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text longer longer </h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>Block Paved Driveways and Paths</h2>
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. Maecenas id leo at elit vestibulum sagittis at in ex. Cras vulputate laoreet dictum. Vestibulum nec quam placerat, blandit orci in, hendrerit ante. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
</div>
Below is my CSS:
.container:after { /*clear float*/
content: "";
display: table;
width: 100%;
clear: both;
}
.container {
margin-left: 100px;
margin-right: 100px;
text-align: center;
padding-top: 30px;
}
.section {
float: left;
width: 33.3333%;
padding-bottom: 50px;
border: 1px solid;
box-sizing: border-box;
display: table-cell;
}
.section p {
padding-bottom: 50px;
text-align: center;
font-family: "Montserrat", sans-serif;
font-size: 19px;
padding-left: 25px;
padding-right: 25px;
}
.section h2 {
text-align: center;
font-family: "Slabo 27px", serif;
font-size: 24px;
font-weight: 700;
text-align: center;
padding-left: 25px;
padding-right: 25px;
}
#media (max-width: 768px) {
.section {
float: none;
width: auto;
}
}
below is a js fiddle of what I currently have
https://jsfiddle.net/b147rmdh/
Any help on this would be greatly appreciated!
You need to specify a height for each column for them to all be the same height. If you don't then the columns will size themselves based on the amount of content they contain (which is currently what is happening in your code). More specifically relating to your code, if you add a specific height to your .section class, then all the columns should be the same height.
Once you have done this, you could use absolute positioning on all of the elements within the columns (the headers, paragraphs, buttons, etc) so that they all line up. If you aren't very familiar with absolute positioning and the position property in general, here is a great reference that explains positioning well. Definitely recommend giving it a read and taking the time to get a good understanding of positioning since it's one of the most fundamental CSS skills.
I'd suggest a Flexbox with wrapping.
.container {
display: flex;
flex-wrap: wrap;
}
.section {
width: 33.3333%;
}
Once you've done that, you can use a similar method vertically if you wrap the upper content in one element and keep the button separate. Set your flex-direction to column and justify-content to space-between.
Related
I need an image (image container to be precise) to resize according to container height and maintain its aspect ratio. Longer the text = bigger the image. Right now its ether image getting out of container or just staying still.
article,
.information,
.image {
margin: 8px;
border: 2px solid black;
}
article {
display: flex;
}
.information {
flex-grow: 1;
}
.image {
font-size: 0;
}
<article>
<div class="information">
<h3>too much text. image must be resized to fill whole height and stay square</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer congue, turpis in sollicitudin fringilla, sapien augue consectetur augue, id lacinia nibh massa at justo. Praesent pellentesque nunc elementum cursus faucibus. Donec vel diam scelerisque,
pharetra velit a, pharetra quam. Ut tristique justo id justo pharetra, eget sollicitudin libero mattis.</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
<hr/>
<article>
<div class="information">
<h3>too little text</h3>
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
article,
.information,
.image {
margin: 8px;
border: 2px solid black;
}
.image{
width:50%;
}
.image img{
height:100%;
width:100%;
}
article {
display: flex;
}
.information {
width:50%;
flex-shrink:0;
}
.image {
font-size: 0;
}
<article>
<div class="information">
<h3>too much text. image must be resized to fill whole height and stay square</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer congue, turpis in sollicitudin fringilla, sapien augue consectetur augue, id lacinia nibh massa at justo. Praesent pellentesque nunc elementum cursus faucibus. Donec vel diam scelerisque,
pharetra velit a, pharetra quam. Ut tristique justo id justo pharetra, eget sollicitudin libero mattis
pellentesque nunc elementum cursus faucibus. Donec vel diam scelerisque,
pharetra velit a, pharetra quam. Ut tristique justo id justo pharetra, eget sollicitudin libero mattis.</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
<hr/>
<article>
<div class="information">
<h3>too little text</h3>
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
I'm trying to build a grid that contains card-like items. The cells of each type (headline, image, text, button, ...) should have equal height in each row, determined by the content of the largest cell, as in the code snippet below.
Now I'm trying to limit the number of columns, and let the cards wrap, as if I used flex-wrap: wrap; in a flexbox-based solution. The number of columns should be determined via media query. Is this possible without using the not-yet-supported subgrids?
Additionally, how would a solution using subgrids look like? I guess it will degrade to cells with non-equal height in current browsers?
.grid {
display: grid;
grid-template-rows: repeat(4, auto);
grid-gap: 10px;
grid-auto-flow: column;
grid-auto-columns: auto;
}
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">text
</p>
<button class="d">Button</button>
<h2 class="a">Header 2 is longer and may span multiple lines</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget. Suspendisse pulvinar arcu massa, quis
varius velit facilisis tincidunt. Proin sed cursus orci.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<button class="d">Button</button>
</div>
This is a good example of a situation when we need sub-grids - aligning the grid cousins is essential in layouts such as in this question.
Until browsers implement the proposed Level 2 spec of Subgrids, we can only wrap each column in an element and then wrap it using an outer grid container.
The below is an excerpt from the Editor's Draft for CSS Grid Layout Module Level 2:
2. Subgrids
A grid item can itself be a grid container by giving it display: grid; in this case the layout of its contents will be
independent of the layout of the grid it participates in.
In some cases it might be necessary for the contents of multiple grid
items to align to each other. A grid container that is itself a grid
item can defer the definition of its rows and columns to its parent
grid container, making it a subgrid. In this case, the grid items of
the subgrid participate in sizing the grid of the parent grid
container, allowing the contents of both grids to align.
A good read that discussed this problem can be found here.
Here's a mock-up using nested grid containers (sub-grids can look like this but without breaking the non-equal cousins rule) - see demo below:
.wrapper {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
}
.grid {
display: grid;
grid-template-rows: repeat(4, 1fr);
justify-items: flex-start;
border: 1px solid #07c;
}
img {
width: 100%;
}
button {
align-self: center;
justify-self: center;
}
p {
padding: 0 10px;
}
<div class="wrapper">
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">text
</p>
<button class="d">Button</button>
</div>
<div class="grid">
<h2 class="a">Header 2 is longer and may span multiple lines</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est.
</p>
<button class="d">Button</button>
</div>
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget.
</p>
<button class="d">Button</button>
</div>
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget. Suspendisse pulvinar arcu massa, quis
varius velit facilisis tincidunt. Proin sed cursus orci.
</p>
<button class="d">Button</button>
</div>
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<button class="d">Button</button>
</div>
</div>
A possible definition could be:
.wrapper {
display: grid; /* outer grid */
/* sets a wrapping grid container with items of width around 400px */
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
}
.grid {
grid-row: span 4; /* span 4 rows */
display: grid;
/* magic is here */
grid-template-rows: subgrid; /* create a sub-grid with the 4 parent grid rows */
}
You have already a solution now, with a not ideal browser support, but anyway working, that is display: content
You need to wrap your elements in an auxiliary div, I set those to the class card. Then, make card disappear of the layour with the display : content:
.grid {
display: grid;
grid-gap: 10px;
grid-auto-columns: 1fr;
grid-auto-flow: dense;
}
.card {
display: contents;
}
.card:nth-child(odd) * {
grid-column-start: 1;
}
.card:nth-child(even) * {
grid-column-start: 2;
}
#media screen and ( min-width: 1300px) {
.card:nth-child(3n + 0) * {
grid-column-start: 3;
}
.card:nth-child(3n + 1) * {
grid-column-start: 1;
}
.card:nth-child(3n + 2) * {
grid-column-start: 2;
}
}
<div class="grid">
<div class="card">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">text
</p>
<button class="d">Button</button>
</div>
<div class="card">
<h2 class="a">Header 2 is longer and may span multiple lines</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est.
</p>
<button class="d">Button</button>
</div>
<div class="card">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget.
</p>
<button class="d">Button</button>
</div>
<div class="card">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget. Suspendisse pulvinar arcu massa, quis
varius velit facilisis tincidunt. Proin sed cursus orci.
</p>
<button class="d">Button</button>
</div>
<div class="card">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<button class="d">Button</button>
</div>
</div>
I just missed the easiest solution:
Since you have already a flat HTML, and are intending to use media queries, you can just use the same idea, (nth- selectors) but on the flat HTMl
.grid {
display: grid;
grid-gap: 10px;
grid-auto-flow: dense;
grid-auto-rows: 1fr;
}
.card {
display: contents;
}
h2,
img,
p,
button {
grid-column-start: 1;
}
h2:nth-of-type(even),
img:nth-of-type(even),
p:nth-of-type(even),
button:nth-of-type(even) {
grid-column-start: 2;
}
#media screen and ( min-width: 1300px) {
h2:nth-of-type(3n + 1),
img:nth-of-type(3n + 1),
p:nth-of-type(3n + 1),
button:nth-of-type(3n + 1) {
grid-column-start: 1;
}
h2:nth-of-type(3n + 2),
img:nth-of-type(3n + 2),
p:nth-of-type(3n + 2),
button:nth-of-type(3n + 2) {
grid-column-start: 2;
}
h2:nth-of-type(3n),
img:nth-of-type(3n),
p:nth-of-type(3n),
button:nth-of-type(3n) {
grid-column-start: 3;
}
}
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">text
</p>
<button class="d">Button</button>
<h2 class="a">Header 2 is longer and may span multiple lines</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget. Suspendisse pulvinar arcu massa, quis
varius velit facilisis tincidunt. Proin sed cursus orci.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<button class="d">Button</button>
</div>
.header {
margin: 0 auto;
text-align: center
}
<div class="header">
<h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit
</h1>
<h3>
Duis dictum eget lacus nec molestie Integer non nisl leo
</h3>
<h5>
Quisque eu luctus tellus. Mauris et dictum ante
</h5>
</div>
when I run this in my browser,
my h1element has 16.080 px of margin on the top and bottom
my h3element has 14.040 px of margin on the top and bottom
my h5element has 16.633 px of margin on the top and bottom
The result I want is this:
.title {
margin: 0;
text-align: center;
}
<div class="header">
<h1 class="title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit
</h1>
<h3 class="title">
Duis dictum eget lacus nec molestie Integer non nisl leo
</h3>
<h5 class="title">
Quisque eu luctus tellus. Mauris et dictum ante
</h5>
</div>
This gives me the result I want, but I do not want to have the class="title" for all my helements.
How do I do this WITHOUT USING three class="title"s?
Headings tags (h1, h2, h3 etc) come with default styles. See here - https://www.w3schools.com/cssref/css_default_values.asp
One of the default styles is margin. You can easily remove this with css.
<!DOCTYPE html>
<html>
<head>
<style>
.header {
text-align: center
}
h1, h3, h5 {
margin: 0;
}
</style>
</head>
<body>
<div class="header">
<h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit
</h1>
<h3>
Duis dictum eget lacus nec molestie Integer non nisl leo
</h3>
<h5>
Quisque eu luctus tellus. Mauris et dictum ante
</h5>
</div>
</body>
</html>
Inside your CSS use:
h1 {
margin: 0 auto;
text-align: center;
}
I'm trying to setup a section of my page with 3 columns using Flexbox.
The 3 columns are set up just fine, the issue I am having is with the section1 div not being as tall as the children elements.
I have tried height: auto, height:100%, overflow: auto, overflow:visible, etc. The only time the section1 div changes height is when I specifically state a pixel height. It seems as though the flexbox items are acting as floats so I tried a clear:both to no avail.
I have searched both stackoverflow and other sites and have not found an answer which leads me to believe it is something I am doing wrong with flexbox.
body {
background: lightgrey;
}
.body {
position: relative;
width: 75% /* 747.75px */;
margin: auto;
top: -3.5em;
background-color: white;
border-top: 3px solid #ff8400;
}
.top-border {
display: block;
position: relative;
top: 2em;
border-top: 1px solid #eef3f0;
width: 95%;
left: 2.5%;
}
.section1 {
position: relative;
display: flex;
justify-content: space-around;
top: 5em;
height: auto;
}
<div class="body">
<div class="top-border"></div>
<div class="section1">
<div class="what-i-do">
<img class="what-i-do-icon" src="images/what-i-do.png" />
<h1 class="what-i-do-title">What I Do</h1>
<p class="what-i-do-desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam semper quam arcu,
a consequat tellus cursus vel. Vivamus lacus massa, feugiat non malesuada sed, efficitur eu elit. </p>
<p class="view-more-btn">View More</p>
</div>
<div class="development">
<img class="development-icon" src="images/development.png" />
<h1 class="development-title">Development</h1>
<p class="development-desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam semper quam arcu,
a consequat tellus cursus vel. Vivamus lacus massa, feugiat non malesuada sed, efficitur eu elit. </p>
</div>
<div class="design">
<img class="design-icon" src="images/design.png" />
<h1 class="design-title">Design</h1>
<p class="design-desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam semper quam arcu, a
consequat tellus cursus vel. Vivamus lacus massa, feugiat non malesuada sed, efficitur eu elit. </p>
</div>
</div>
</div>
See Relative positioning
Once a box has been laid out according to the normal flow or
floated, it may be shifted relative to this position. This is called
relative positioning. Offsetting a box (B1) in this way has no effect on the box (B2) that follows: B2 is given a position as if B1
were not offset and B2 is not re-positioned after B1's offset is
applied. This implies that relative positioning may cause boxes to
overlap.
Here you don't want to shift a single box, you want it to push following content too. Then, you should use margins for that.
body {
background: lightgrey;
}
.body {
width: 75% /* 747.75px */;
margin: auto;
margin-top: -3.5em;
background-color: white;
border-top: 3px solid #ff8400;
}
.top-border {
top: 2em;
border-top: 1px solid #eef3f0;
width: 95%;
margin-left: 2.5%;
}
.section1 {
display: flex;
justify-content: space-around;
margin-top: 5em;
}
<div class="body">
<div class="top-border"></div>
<div class="section1">
<div class="what-i-do">
<img class="what-i-do-icon" src="images/what-i-do.png" />
<h1 class="what-i-do-title">What I Do</h1>
<p class="what-i-do-desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam semper quam arcu,
a consequat tellus cursus vel. Vivamus lacus massa, feugiat non malesuada sed, efficitur eu elit. </p>
<p class="view-more-btn">View More</p>
</div>
<div class="development">
<img class="development-icon" src="images/development.png" />
<h1 class="development-title">Development</h1>
<p class="development-desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam semper quam arcu,
a consequat tellus cursus vel. Vivamus lacus massa, feugiat non malesuada sed, efficitur eu elit. </p>
</div>
<div class="design">
<img class="design-icon" src="images/design.png" />
<h1 class="design-title">Design</h1>
<p class="design-desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam semper quam arcu, a
consequat tellus cursus vel. Vivamus lacus massa, feugiat non malesuada sed, efficitur eu elit. </p>
</div>
</div>
</div>
I have problems in CSS with the property Padding or Border. I have an image within a div that fits perfect, but to add margin exceeds the div that contains it.
<div class="content">
<div class="row" />
<div class="ima">
<h1>Titulo 1</h1>
<img class="img" src="https://sites.google.com/site/cnetuc/imagen-04.jpg" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas laoreet mattis arcu eget euismod. Donec eget purus et enim cursus feugiat sit amet in diam.
<p>
</div>
<div class="ima">
<h1>Titulo 1</h1>
<img class="img" src="https://sites.google.com/site/cnetuc/imagen-04.jpg" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas laoreet mattis arcu eget euismod. Donec eget purus et enim cursus feugiat sit amet in diam.
<p>
</div>
<div class="ima">
<h1>Titulo 1</h1>
<img class="img" src="https://sites.google.com/site/cnetuc/imagen-04.jpg" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas laoreet mattis arcu eget euismod. Donec eget purus et enim cursus feugiat sit amet in diam.
<p>
</div>
</div>
</div>
Attached fiddle
Add box-sizing: border-box; to the image.
.ima img{
width:100%;
border:10px solid rgba(0, 0, 0, 0.3);
box-sizing: border-box;
}
Try to
box-sizing: border-box;
Or
width: calc(100% - 20px);