I am working on a project with a fluid percentage-based horizontal grid and I want to have the same vertical margins as my horizontal ones.
This is the code I have:
.block_12_24{
display:inline-block;
vertical-align:top;
width:48%;
margin-right:2%;
margin-left:0;
/* Now I want the margin-top to be the same as margin-right: */
margin-top: 17px; //instead of that
}
Now, I am looking for a way to make the margin-top value equal to margin-right. I am thinking of recalculating the 2% into an absolute value like pixels and then assigning that value to margin-top. I don't want to keep checking it manually, so I am considering using JavaScript to achieve this:
- Setting margin-top to a rough value like 17px
- Allowing the page to load
- Using JavaScript to check the browser's width in pixels
- Calculating a new margin value based on that width
- Adjusting the margin-top of .block_12_24 accordingly
Is there a way to achieve this using only CSS? Thanks