Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Responsive Div's with margin and aligning?

Tags:

html

css

I'm trying to create a page that would have a few Div's which would be responsive.

I have created the divs and they are sort of responsive but I cannot get the margin right!

basically, I need to put some space between the divs so they are not stuck together.

This is what I've done and this is the CSS:

.holder {
    width : 45%;
    height : auto;
    border : 1px solid red;
    display : inline-table;
    float : left;
}

@media (max-width: 600px) 
{
 #container {
     width : 100%;
  }
 .holder {
     width : 100%;
  }
}

I Can simply put .holder {margin:4%; */OR ANY OTHER VALUES HERE*/} but that would mean the first div would be pushed away from its original place which is not what I want.

Could someone please advise on this issue?

Thanks in advance.

like image 859
H.HISTORY Avatar asked Sep 07 '26 04:09

H.HISTORY


2 Answers

How about adding margin only on the right side?

Something like .holder { margin-right: 4%; margin-bottom:4% }.

like image 120
Kartik Sreenivasan Avatar answered Sep 10 '26 00:09

Kartik Sreenivasan


try replacing this class..

.holder {
    width : 45%;
    height : auto;
    border : 1px solid red;
    display : inline-table;
    float : left;
    margin:0% 3% 2% 0%; /* margin for the div*/
}

here is the FIDDLE

like image 34
Sarath Avatar answered Sep 10 '26 00:09

Sarath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!