Div height follow smaller div height - html

I have two divs, one beside the other. The left one will have a lot of content, so i want to put scrollbar on it. The right div will have less content so left div should follow height of right div.
Content of right div is dynamic so I can't set max-height of left div. I tried with display:table-cell but unsuccessfully.
.container {
display: table;
border: 2px solid red;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
width: 30px;
border: 2px solid blue;
}
<div class="container">
<div class="row">
<div class="cell">CELL1: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus a facilis saepe. Commodi exercitationem, provident nemo ea distinctio dolor ullam ab facere blanditiis inventore debitis nobis vitae maxime suscipit accusantium.</div>
<div class="cell">CELL2: lorem lorem lorem lorem</div>
</div>
</div>
JSFIDDLE DEMO

You can do this by wrapping the first cell (I call it with first class here) and calling it absolute.
<div class="cell first">
<div>
CELL1: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus a facilis saepe. Commodi exercitationem, provident nemo ea distinctio dolor ullam ab facere blanditiis inventore debitis nobis vitae maxime suscipit accusantium.
</div>
</div>
and apply this:
.cell.first div{
position: absolute;
top: 0;
left: 0;
width: 100%;
}
and overflow-y: auto for each cell.
Maybe you have to adjust the widths. See example below:
.container {
display: table;
border: 2px solid red;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
width: 30px;
border: 2px solid blue;
position: relative;
overflow-y: auto;
}
.cell.first div{
position: absolute;
top: 0;
left: 0;
width: 100%;
}
<div class="container">
<div class="row">
<div class="cell first">
<div>
CELL1: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus a facilis saepe. Commodi exercitationem, provident nemo ea distinctio dolor ullam ab facere blanditiis inventore debitis nobis vitae maxime suscipit accusantium.
</div>
</div>
<div class="cell">CELL2: lorem lorem lorem lorem</div>
</div>
</div>
Cheers! Let me know your feedback on this. Thanks!

try this,
HTML
<div class="container">
<div class="row">
<div class="cell">
<div class="cell-content">
CELL1: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus a facilis saepe. Commodi exercitationem, provident nemo ea distinctio dolor ullam ab facere blanditiis inventore debitis nobis vitae maxime suscipit accusantium.
</div>
</div>
<div class="cell">
<div class="cell-content">CELL2: lorem lorem lorem lorem </div>
</div>
</div>
</div>
CSS
.container {
display: table;
border: 2px solid red;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
width: 30px;
border: 2px solid blue;
}
.cell-content{
max-height:200px; /* as per your requirement */
overflow:auto;
}

Related

aligning multiple div headings in same height

I'm writing an HTML page that has 3 divs in it. and each div has a heading and a para. currently, the para is getting aligned as per the heading content height. How can I make sure that the paras in all the divs start at the same position irrespective of the h2 content?
Here is my current code.
.parent{
display: flex;
}
.child{
border: 1px solid black;
margin: 1em;
padding: 1em;
}
.child h2{
border-bottom: 1px solid;
min-height: max-content;
}
<div class="parent">
<div class="child">
<h2>Proper heading with more co</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam,</p>
</div>
<div class="child">
<h2>large heading that is bigger than proper heading</h2>
<p>labore odio minima cumque molestiae amet vitae! Voluptatum</p>
</div>
<div class="child">
<h2>small</h2>
<p>
cupiditate unde vel culpa veritatis eius dicta, quia, quas dolores
similique hic! Iure.
</p>
</div>
</div>
if you set the height of h2 to a specific value, it will be right!
for example:
.parent{
display: flex;
}
.child{
border: 1px solid black;
margin: 1em;
padding: 1em;
}
.child h2{
border-bottom: 1px solid;
height: 60px;
}
<div class="parent">
<div class="child">
<h2>Proper heading with more co</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam,</p>
</div>
<div class="child">
<h2>large heading that is bigger than proper heading</h2>
<p>labore odio minima cumque molestiae amet vitae! Voluptatum</p>
</div>
<div class="child">
<h2>small</h2>
<p>
cupiditate unde vel culpa veritatis eius dicta, quia, quas dolores
similique hic! Iure.
</p>
</div>
</div>

display image in left div on hovering right div

I have two div's float left and right. In the left div there is an image, and in the right div there are paragraphs. The image in the left div is hidden, when I hover the right div the image should be displayed but I can't do this, there is a problem when I attempt to do this.
.lower-container {
padding: 10px;
width: 100%;
text-align: center;
margin-bottom: -70px;
}
.left-logo-container {
width: 40%;
float: left;
padding: 10px;
padding-top: 0 !important;
}
.left-logo-container img {
width: 250px;
padding-bottom: 50px;
}
.right-para-container {
width: 60%;
float: right;
padding: 10px;
margin-top: -200px;
}
.right-para-container p {
color: white;
text-align: left;
padding-left: 0;
padding-right: 120px;
font-family: oh-whale;
}
.clear:after {
clear: both;
content: "";
display: table;
}
/* Display element on hovering */
.hide {
display: none;
}
.myDIV:hover+.hide {
display: block;
}
<section id="welcome_cryptonic_06">
<div class="container">
<div class="vision-container">
<div class="title-container">
</div>
<div class="lower-container">
<div class="left-logo-container myDIV">
<img src="about_image.png">
</div>
<div class="right-para-container hide">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Maiores provident ipsum veritatis quod eveniet aperiam ipsa voluptatibus mollitia deserunt eos itaque assumenda omnis nam animi consequuntur voluptate, placeat velit repudiandae. Lorem, ipsum dolor
sit amet consectetur adipisicing elit. Fugiat, veritatis? Iure dolor consequatur possimus ipsum tenetur quos tempora animi numquam inventore. Pariatur doloremque ut deleniti fugiat enim, laudantium culpa sit.
</p>
</div>
<div style="clear: both;"></div>
</div>
</div>
</div>
</section>
<!-- End welcome_cryptonic -->
Here is the solution !
Run the code in a full screen.
.lower-container {
display: flex;
flex-wrap:wrap;
padding:5rem;
height:20%;
}
.left-logo-container {
order:1;
height:20rem !important;
padding:2rem;
}
.left-logo-container img{
height:20rem;
width:auto;
}
.right-para-container {
order:2;
height:25%
color: black;
width:50%;
text-align: left;
font-family: oh-whale;
padding:5rem;
}
.right-para-container p{
border:2px solid grey;
border-radius:2rem;
padding:2rem;
}
#show {
display: none
}
#main:hover + #show {
display: block
}
<section id="welcome_cryptonic_06">
<div class="container">
<div class="vision-container">
<div class="title-container">
</div>
<div class="lower-container">
<div class="right-para-container " id='main'>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Maiores provident ipsum veritatis quod eveniet aperiam ipsa voluptatibus mollitia deserunt eos itaque assumenda omnis nam animi consequuntur voluptate, placeat velit repudiandae. Lorem, ipsum dolor
sit amet consectetur adipisicing elit. Fugiat, veritatis? Iure dolor consequatur possimus ipsum tenetur quos tempora animi numquam inventore. Pariatur doloremque ut deleniti fugiat enim, laudantium culpa sit.
</p>
</div>
<div class="left-logo-container " id='show'>
<img src="https://images.unsplash.com/photo-1655833266283-af4002bf9ebb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw1fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60">
</div>
</div>
</div>
</div>
</section>

Flex inside flex with overflow-x

I'd like to create 2 columns inline. The first column has fixed width of 200px and second column should take up the rest of the screen. The second column should autoscroll on the x-axis. I've been trying to use flex but I'm very confused by the markup. Can someone please explain what I'm doing wrong.
Path: html
<section className="container">
<div className="container-name">1</div>
<div className="container-time">
<div className="element">
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999
</div>
</div>
</section>
Path: CSS
.container {
flex: 0 0 auto;
}
.container-name {
width: 200px;
border: 1px dotted;
}
.container-time {
flex: 0 0 auto;
border: 1px solid;
}
.element {
display: flex;
overflow-x: auto;
}
You can get the desired output using:
max-width on the container
display: inline-flex; on the container
max-width on the container-time
.container {
max-width: 100%;
display: inline-flex;
}
.container-name {
width: 200px;
border: 1px solid red;
}
.container-time {
flex-grow: 1;
max-width: calc(100% - 200px);
border: 1px solid green;
}
.element {
display: flex;
overflow-x: auto;
}
<section class="container">
<div class="container-name">1</div>
<div class="container-time">
<div class="element">
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
</div>
</div>
</section>
Hope this solution will help you!
* {
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
.container {
position: relative;
width: 100%;
height: 100vh;
display: flex;
min-height: 100vh;
}
.container .split {
position: relative;
width: 100%;
height: 100%;
}
.container .split__left {
max-width: 400px;
background-color: coral;
}
.container .split__right {
padding: 2rem;
overflow-x: scroll;
background-color: pink;
}
.container .split__right p {
white-space: nowrap;
}
<div class="container">
<div class="split split__left"></div>
<div class="split split__right">
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil repellat sapiente assumenda. Ex fugit at amet sed libero eaque. Debitis obcaecati aperiam hic possimus unde. Voluptatibus cumque illo dolores architecto.</p>
</div>
</div>
[NOTE] see this in bigger screen.

Make a flex item grow at hover without affecting the other flex elements, while keep box heights equivalent when not hovered

I have box elements in a flex container. I want the paragraph in a box to display when hovering over the box. However, the hovered box makes the other boxes grow too. Is there a way to avoid affecting the other boxes when hovering one box?
I would try: align-items:flex-start, but I want the boxes to be equivalent in height when they are not hovered.
So align-items:flex-start does not keep the boxes' height equivalent when they are not hovered.
I want the box to enlarge when hovered without affecting the other boxes and turn back to the equivalent height when not hovered.
Codepen link: https://codepen.io/lemour-sudo/pen/yLMQOpE
.container > * {
width: 25em;
padding: 1em;
text-align: center;
}
.container {
display: flex;
justify-content: space-around;
margin: 3em 10em;
border: solid 3px green;
}
p {
display: none;
}
.box {
border: solid 3px red;
}
.box:hover p {
display: block;
}
<div class="container">
<div class="box">
<h1>Box 1</h1>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nam tenetur amet dignissimos, accusantium molestias tempora!
</p>
</div>
<div class="box">
<h1>Box 2</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto voluptatum labore totam natus illo, magni inventore cupiditate hic omnis ipsam vero nobis enim dicta perferendis facilis tenetur quaerat! Voluptas, voluptatum.
</p>
</div>
</div>
I'm not sure exactly how to do what you want but I think this way is better. It's more customizable. I agree with vals answer but If you don't want to make the container to grow all the way down this way is better.
* {
margin: 0;
padding: 0;
box-sizing:border-box;
}
.con {
width: 90%;
display: flex;
align-items: center;
justify-content: space-around;
border: 3px solid black;
}
.item {
border: 3px solid red;
width: 200px;
height: 200px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
background-color: cadetblue;
}
.text-con {
position: absolute;
width: 100%;
top: 100%;
display: none;
background-color: cadetblue;
}
.item:hover .text-con {
display: block;
}
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='style.css'>
</head>
<body>
<div class="con">
<div class="item">
<h1>box1</h1>
<div class="text-con">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis minus consequatur similique quas excepturi dignissimos optio nulla possimus</p>
</div>
</div>
<div class="item">
<h1>box2</h1>
<div class="text-con">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis minus consequatur similique quas excepturi dignissimos optio nulla possimus</p>
</div>
</div>
<div class="item">
<h1>box3</h1>
<div class="text-con">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis minus consequatur similique quas excepturi dignissimos optio nulla possimus</p>
</div>
</div>
</div>
</body>
</html>
May be setting flex-start on hover of the container?
.container > * {
width: 25em;
padding: 1em;
text-align: center;
}
.container {
display: flex;
justify-content: space-around;
margin: 3em 10em;
border: solid 3px green;
}
.container:hover {
align-items: flex-start;
}
p {
display: none;
}
.box {
border: solid 3px red;
}
.box:hover p {
display: block;
}
<div class="container">
<div class="box">
<h1>Box 1</h1>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nam tenetur amet dignissimos, accusantium molestias tempora!
</p>
</div>
<div class="box">
<h1>Box 2 bigger than 1</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto voluptatum labore totam natus illo, magni inventore cupiditate hic omnis ipsam vero nobis enim dicta perferendis facilis tenetur quaerat! Voluptas, voluptatum.
</p>
</div>
</div>
Another solution, with different heights in the initial state
.container > * {
width: 25em;
padding: 1em;
text-align: center;
}
.container {
display: flex;
justify-content: space-around;
margin: 3em 10em;
border: solid 3px green;
}
.container:hover {
align-items: flex-start;
}
p {
display: none;
}
.box {
border: solid 3px red;
height: fit-content;
}
.box:hover p {
display: block;
}
<div class="container">
<div class="box">
<h1>Box 1</h1>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nam tenetur amet dignissimos, accusantium molestias tempora!
</p>
</div>
<div class="box">
<h1>Box 2 bigger than 1</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto voluptatum labore totam natus illo, magni inventore cupiditate hic omnis ipsam vero nobis enim dicta perferendis facilis tenetur quaerat! Voluptas, voluptatum.
</p>
</div>
</div>

Box-sizing: border box; percentage width but pixel padding

I've been creating a grid, which uses padding for gutters. There's times where It's necessary to have no gutters (full width image) so I simply created a class which removed the padding.
The problem is, when using a 50% width, even though it's using border-box, is not truly 50%.
a reduced test case:
JsFiddle
Code
*,
*:before,
*:after {
box-sizing: border-box;
}
.row {
zoom: 1;
&: before, &: after {
content: "";
display: table;
}
&:after {
clear: both;
}
}
.half {
width: 50%;
padding: 10px;
}
.no-pad {
padding: 0;
}
.column {
float: left;
}
img {
max-width: 100%;
height: 100%;
display: block;
}
.eq-height-container {
display: flex;
}
.eq-height-column {
flex: 1;
}
<div class="row eq-height-container">
<div class="column half eq-height-column" style="background-color: red;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa necessitatibus qui ea, quasi pariatur sed esse beatae porro in temporibus ipsum delectus, quisquam. Saepe sapiente, facere repellat tenetur quae aut.</p>
</div>
<div class="column half no-pad eq-height-column">
<img src="http://lorempixel.com/400/200" alt="">
</div>
</div>
<div class="row eq-height-container">
<div class="column half no-pad eq-height-column">
<img src="http://lorempixel.com/400/200" alt="">
</div>
<div class="column half eq-height-column" style="background-color: red;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa necessitatibus qui ea, quasi pariatur sed esse beatae porro in temporibus ipsum delectus, quisquam. Saepe sapiente, facere repellat tenetur quae aut.</p>
</div>
</div>
Is there a simple way around this?
you can set img to width:100% and remove flex:1 and float:left as well if you want to keep display:flex for equal height
body {
margin: 0
}
*,
*:before,
*:after {
box-sizing: border-box;
}
.row::before,
.row::after {
content: "";
display: table;
}
.row::after {
clear: both;
}
.half {
width: 50%;
padding: 10px;
background: red
}
.no-pad {
padding: 0;
}
img {
width: 100%;
height: 100%;
display: block;
}
.eq-height-container {
display: flex;
}
.eq-height-column {
/* flex: 1;*/
}
<div class="row eq-height-container">
<div class="column half eq-height-column">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa necessitatibus qui ea, quasi pariatur sed esse beatae porro in temporibus ipsum delectus, quisquam. Saepe sapiente, facere repellat tenetur quae aut.</p>
</div>
<div class="column half no-pad eq-height-column">
<img src="//lorempixel.com/400/200" alt="">
</div>
</div>
<div class="row eq-height-container">
<div class="column half no-pad eq-height-column">
<img src="//lorempixel.com/400/200" alt="">
</div>
<div class="column half eq-height-column">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa necessitatibus qui ea, quasi pariatur sed esse beatae porro in temporibus ipsum delectus, quisquam. Saepe sapiente, facere repellat tenetur quae aut.</p>
</div>
</div>
That's because you're mixing in flex. If you remove .eq-height-column you'll see that the two columns become the same width.