Need Help, how to create same height div elements

Hello everybody,

i have following issue, that i can not solve some days, i not so long in coding, so i do not cnow how i should solve this problem, i have had search many hours, but i do not find the solution.
The problem is that i need to create

blocks, that shoud have same height, but they should be responsive to the body and stay under each other.
Here i create with paint some examples, how it should see and that is should be responsive to the width of the webpage, the div elements should expand in height, if the width of the page get smaller.
I hope somebody have the solution.
(p.s flex-box do not solve the problem, i do not nead div elements in the same line and it should be pure css and html.)

1 Like

and if the page goes smaller:

1 Like

hello @Daniel4 im a newbie here.
i think @media technique can be a solution to be used on your div

here is the references from w3 https://www.w3schools.com/css/css_rwd_mediaqueries.asp

1 Like

here is the code that i tried, seems working tho

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
div {
  background-color: lightgreen;
}

@media only screen and (max-width: 600px) {
  div {
    background-color: lightblue;
    max-height:600px;
    max-width:100px;
  }
}
</style>
</head>
<body>
<div>
<p>Resize the browser window. When the width of this document is 600 pixels or less, the background-color is "lightblue", otherwise it is "lightgreen".</p>
</div>
<div>
<p>Resize the browser window. When the width of this document is 600 pixels or less, the background-color is "lightblue", otherwise it is "lightgreen".</p>
</div>


</body>
</html>
1 Like

Flex-box will do exactly what you want to accomplish.
There’s a property called flex-direction that you can set as “column” so you will enforce your flex item to sit one on top of the other, opposed to the default value of “row” that will place your element on the same line.

Hope it helps :slight_smile:

1 Like

thank you), but this is not what i mean. Marmiz is near to the problem, that i have.

1 Like

i have try it already), flex-box column but the problem is, that the div block have not the same size, i need that they have same height size, for example, the page width change from 1920 to 1650 px width and for example the middle div change his height parameters, because the text break up the line, so the other div blocks shoud get the same height like the middle div element.
I hope you understand what i mean.

1 Like

you can use css grid for that purpose. I used it to make same height grids for product landing page as well as for personal portfolio projects section. Secondly, you can give a height and width to the div class/ id in your css if you do not want to use grid or flexbox

1 Like

Why not a simple min-height property? :thinking:

1 Like

thank you, to set height is not a solution, it should be auto responsive, it should change the div height, if i will set a height, the text will overflow the div box and that is not what i need. i have tryed with grid, but the grid system is not responsive, for example i have line 1 and 2, and the second get heigher, beacuase it have more text, the first grid element will not change its height. Grid example

1 Like

not if you set the min-height as previously suggested.
It’s a common way of having all the items starting with the same height.

If then something dynamically grows, I fear you would need JS for that as you are in need of dynamically calculating the new content.

1 Like

because one div element can have at width of 650px a height of 500px a another 400 px height, and in a resolution of 1920px have the first div element heigth of 500px, the second only 300px, yes i can set the min height, but so i shoud to know the maximum heightpoint of a div element on each pixel width, that is unrealistic and second the div content does change his height, so if it looks good at 650px width and 500px height good, so in fullhd resolution it looks bad. that is the problem.

1 Like

yes, the content grows dynamically. The width of the div elmement changes, ad so the height of div grows.

1 Like

Then I’m afraid that if having all the divs with different height (which btw is the norm :slight_smile: ) then you would need to rely on Javascript to calculate the max height at runtime and enforce it on each element.

1 Like

https://jsfiddle.net/csb3tqju/6/. check out this link. The grid boxes are responsive.

1 Like

thank you too, but here, you set a height to the grid item, if the content gets bigger it overflow the box, like here. And i need that all items get automatically the same height if one element grow in height. here a example: grid overflow

1 Like

@Daniel4 yeah you can do that by setting another grid property:- grid-auto-rows: 1fr;

Check this out:- https://jsfiddle.net/wu025o7m/1/

1 Like

Create a div give it a class add a pragraph and <br>it go to css set the border to block set the margin. I hope it helps.

thank you very much, that is it what i need. Here i modified the width of the grid item, and now it changes in every side, height and width adapt automatically to the size of the webpage: grid responsive.

1 Like

your welcome, happy to help. hope it solved the problem.