How do I make children elements stay within the parent element when view height/width is changed?

colbisaurusrex

Here is a codepen. Pay attention to the purple elements when you change the view height. They overflow. I want to slay this dragon once and for all - and more importantly - understand what is happening so I never have to bother you folks again.

https://codepen.io/colbisaurusrex/pen/WpXVxY

 body {
  background-color: #34495E;
  padding: 5%;
}
.container {
  height: 100vh;
  display: flex;
}
.columnleft {
  background-color: #2ECC71;
  height: 100%;
  width: 30%;
  margin-right: 10%;
}

.leftbox {
  margin: 10%;
  height: 100%;
}

.box {
  display: flex;
  background-color: #1ABC9C;
  margin: 10%;
  height: 40%;
}

.innerbox {
  background-color: #3498DB;
  height: 96%;
  width: 47%;
  margin: 2%;
}


.columnright {
  background-color: #2ECC71; 
  height: 100%;
  width: 60%;
}

.row {
  display: flex;
  height: 40%;
  background-color: #9B59B6;
  width: 80%;
  margin-right: 10%;
  margin-left: 10%;
}

.rowone {
  margin-top: 5%;
  margin-bottom: 5%;
}

.rowtwo {
 margin-bottom: 5%;
}
Anthony Granger

Ok so as I see in your code, you are using flex buuut... not really.

I corrected your columnright but you can do the same with columnleft if you understood.

What you want to achieve is having elements inside column with the same "height" and take the full space.

So here is the corrected CSS :

.columnright {
  background-color: #2ECC71;
  height: 100%;
  width: 60%;
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  flex: 1;
  background-color: #9B59B6;
  width: 80%;
  margin-right: 10%;
  margin-left: 10%;
  margin-top: 20px;
}

.rowtwo {
  margin-bottom: 20px;
}

Remove everything from rowone.

What I used is the flex property that define how much space an element will take. Here, each element will have to take 1 unit of space, so each one the same amount of height. I also added a margin-top to each element to create an "internal" padding and a margin-bottom to the last element.

Also, here is the corrected CodePen : https://codepen.io/anon/pen/vxpBjM

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I move children elements to a new parent element in jQuery?

How do I get only the visible children elements of a parent element?

How do I make a parent with flex have children overflow the parent

How do I make and element stay with another on resize

How to make a fixed-position element inside a clip-path parent stay above all elements?

How do I make the div to stay at the top when rotatingX

How do I get the offsetHeight of an element in a parent component from the children?

How do I make a tab control with children elements?

AngularJS : How do I nest a view within a parent state with parameters?

How do I set up Scroll within an absolute parent View?

How can I get an element to stay within the browser's window width when its content is wider?

How do I make my post content stay within its bootstrap well, or limit line length?

Make children elements render only after parent element transition is over?

How can I make a Flex div and it's (image) children be contained within it's parent?

How do I make a button stay pressed?

How to make children clicked when clicking parent

How do I make a child element toggle when the parent is clicked using jQuery?

how do I make elements not move when other elements do?

How to make elements to stay under a sticky element css?

How do I update elements of the parent view/viewController from a ContainerView?

How can I make the top and bottom elements of my view controller stay in place, while the middle has elements to vertically scroll through?

How to reset values of dependent children when select changed in a parent?

'dragleave' of parent element fires when dragging over children elements

How do I make a div element stay on a same position as before after page reload?

How do I make a simple <audio> element stay at the bottom of the browser window while scrolling?

How can I make the element stay in its place with CSS when hovering

How do I position my element to be sticky (stay on screen when I scroll pass them)

How can I make the tap highlight show only on a parent element, not on children?

In pygame, how do I blit an image when I collide with something and make it stay?