I'm trying to put a divider inbetween the two divs but I can't find a solution without putting the class tag in the div area which I don't want to do.
What I want to do is something like this. Jsfiddle preview
<div class="box1"></div>
<div class="divider"></div>
<div class="box1"></div>
You don't need a divideer you can give right border to the first div as following:
.col-xs-6:first-child //can be md as well{
border-right:1px solid;
}
See the fiddle: "http://jsfiddle.net/ut8dgbxz/4/"
Your question is not clear in the sense of vertical or horizontal divider! So, for horizontal divider, that is a line that is sleeping or parallel to the floor, instead of div.divider use:
<hr />
This is the right way, which is called horizontal rule.
Snippet
#import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css");
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
<hr />
<div class="col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expliabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
</div>
</div>
</div>
If it is supposed to be vertical one, i.e., the standing one, use this way:
Snippet
#import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css");
.divider {border-left: 2px solid #ccc; padding-left: 5px;}
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
<div class="col-md-6">
<div class="divider">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expliabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
</div>
</div>
</div>
</div>
Make sure you do the columns this way: Use two .col-md-6 for equal width columns. And then use the CSS:
.divider {border-left: 2px solid #ccc; padding-left: 5px; margin-left: -5px;}
<div class="col-md-6">
Some content here.
</div>
<div class="col-md-6">
<div class="divider">
Some content here.
</div>
</div>
Snippet
.divider {border-left: 2px solid #ccc; padding-left: 3px; margin-left: -5px; height: 50px; float: left;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-6">Hello</div>
<div class="divider"></div>
<div class="col-md-6">Hello</div>
</div>
</div>
This replaces the margin displaced with the padding. And then you can use it anywhere.
Important Note: Never use the divider with .col-*-* classes as the layout might get screwed up in the responsiveness.
Now try to this way
.box1{
width:50%;
float:left;
background:gray;
}
.container {overflow:hidden;}
.divider{
position:relative;
}
.divider:after{
content:"";
position:absolute;
right:50%;
top:0;
bottom:0;
border-right:dotted 1px red;
}
<div class="container divider"><div class="box1 ">Hello</div>
<div class="box1">Hello two </div></div>
I think you want this kind:
.container{
background:#f5f5f5;
}
.col-md-6{
border-bottom:1px solid grey;
height:auto;
position:relative;
padding:0 0 10px 0;
}
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
<div class="col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expliabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
</div>
</div>
</div>
HTML:
<div class="box1 divider"></div>
<div class="box1"></div>
CSS:
.divider {
position: relative;
}
.divider:after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 1px;
background-color: #000;
}
Just add an extra class to any div you want to be vertically divided then use this CSS. It removes the need for an extra element. This gives you more control when nesting grids
I understand that you don't want to put extra html element in there. What about this solution (this will work with many columns, not just two):
.col-md-6:nth-child(odd) {
border-right: 1px dotted grey;
}
.col-md-6:nth-child(even) {
border-right: none;
}
And HTML:
<div class="row">
<div class="col-md-12">
<div class="col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
<div class="col-md-6">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expliabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
</div>
</div>
jsfiddle
You can use border-left using the sibling selector to act as the vertical divider. This is not dependent on the number of columns in the row so you can use it independently.
.dividers {
display: flex;
display: -ms-flex;
}
.dividers [class^=col] + [class^=col] {
/* To match all the classes prefixed with col and which has a sibling */
border-left: 1px solid gray;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-12 col-xs-12 dividers">
<div class="col-md-3 col-xs-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
<div class="col-md-3 col-xs-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expliabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
<div class="col-md-3 col-xs-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
<div class="col-md-3 col-xs-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expliabo a quisquam earum accusamus iusto quos sunt incidunt laudantium ratione unde veritatis soluta fuga cum hic odit asperiores accusantium nulla libero.</div>
</div>
</div>
</div>
If you want to use the bootstrap .col-* classes, see my Fiddle for a way to put vertical dividers that adjust to the tallest column.
Must view in full-screen for full effect
The borders are not used on mobile since the columns stack when viewed on a mobile platform.
.row {
overflow: hidden;
}
.cols {
padding-bottom: 100%;
margin-bottom: -100%;
overflow: hidden;
}
#media(min-width: 992px) {
.col-md-4:not(:first-child),
.col-md-6:not(:first-child) {
border-left: 1px solid black;
}
.col-md-4:not(:last-child),
.col-md-6:not(:last-child) {
border-right: 1px solid black;
margin-right: -1px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<h1>
.col-md-6
</h1>
<hr>
<div class="row text-center">
<div class="col-md-6 cols">
<p>Enter some text here</p>
</div>
<div class="col-md-6 cols">
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
</div>
</div>
<hr>
<h1>
.col-md-4
</h1>
<div class="row text-center">
<div class="col-md-4 cols">
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
</div>
<div class="col-md-4 cols">
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
</div>
<div class="cols col-md-4 cols">
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
</div>
</div>
</div>
Related
intro
I am creating a simple project in angular and using angular material with flexlayout
problem
the problem is that it doesn't wrap the text correctly on smaller screens, it either clips text or just make it larger than the container.
code
html
<div class="container">
<h2>Normal</h2>
<div class="flex-container" fxLayout="row" fxLayout.xs="column wrap">
<div class="child-1">1. One</div>
<div class="child-2">2. Two</div>
<div class="child-3">3. Three</div>
</div>
<h2>Default</h2>
<div class="flex-container" fxLayout="row" fxLayout.xs="column wrap">
<div class="child-1" fxFlex>
<p>1. One</p>
<p>166.67px</p>
</div>
<div class="child-2" fxFlex>
<p>1. Two</p>
<p>166.67px</p>
</div>
<div class="child-3" fxFlex>
<p>1. Three</p>
<p>166.67px</p>
</div>
</div>
<h2>fxFlex with grow shrink values</h2>
<div class="flex-container" fxLayout="row" fxLayout.xs="column wrap">
<div class="child-1" fxFlex="2 1 auto">
<p> Angular fxFlex flexgrow flexshrink flexbasis</p>
<p>250px</p>
</div>
<div class="child-2" fxFlex>
<p>Angular fxFlex flexgrow flexshrink flexbasis</p>
<p>125px</p>
</div>
<div class="child-3" fxFlex>
<p>125px</p>
</div>
</div>
</div>
<div class="container">
<mat-list>
<div class="flex-container" fxLayout="row wrap" fxLayout.xs="column wrap">
<mat-list-item fxFlex>
<div mat-line> <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Molestias qui assumenda perferendis atque ipsa ipsum enim voluptate voluptas mollitia autem minima deleniti quisquam iste alias, accusantium, eveniet ut, rerum totam.</p></div>
</mat-list-item>
<mat-list-item fxFlex>
<div mat-line>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos molestiae, sequi fugiat tempora dicta numquam ipsam dolorem natus ducimus et expedita cum quaerat porro, cumque necessitatibus odit. Omnis, fugiat officia?</div>
<div mat-line> Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio voluptatibus, rem blanditiis nobis, nemo, soluta velit molestiae repudiandae vel non atque accusantium ipsum deleniti saepe natus quam quasi quae fuga.</div>
</mat-list-item>
</div>
</mat-list>
</div>
CSS
.child-1 {
background-color: orange;
}
.child-2 {
background-color: yellow;
}
.child-3 {
background-color: green;
}
.container {
margin: 15px;
height: auto;
width: 95%;
border: 2px solid red;
text-align: center;
}
what i want
I included another container in the next stack blitz that uses the same CSS and flexlayout that works just fine. I want the other container to be the same using mat-list
stackblitz
stackblitz
This question already has answers here:
Why is nth-child selector not working?
(5 answers)
Closed 2 years ago.
HTML
for each service box i want to change background.
but nth-child() selector is not working.
when each service class changed to nave with respective number its working finly.
.service:nth-child(1) {
background-color: red;
}
<section class="about-us">
<div class="service">
<div class="service-header">
<i class="fas fa-pen-nib"></i>
<h1>Interiar</h1>
</div>
<div class="service-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro corporis modi alias officia quod repudiandae fugit, eveniet ipsum, doloremque facere dolores ex illo hic quidem.</p>
</div>
</div>
<div class="service">
<div class="service-header">
<i class="fas fa-pen-nib"></i>
<h1>Interiar</h1>
</div>
<div class="service-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro corporis modi alias officia quod repudiandae fugit, eveniet ipsum, doloremque facere dolores ex illo hic quidem.</p>
</div>
</div>
</div>
To change the background for each service box to red remove :nth-child() from the css.
.service {
background-color: red;
}
nth-child(#) will get the number(#) of the element. Here 1st element with the match is selected and the style is applied.
To change the background for each try this :
.service:nth-child(1) {
background-color: red;
}
.service:nth-child(2) {
background-color: blue;
}
<section class="about-us">
<div class="service">
<div class="service-header">
<i class="fas fa-pen-nib"></i>
<h1>Interiar</h1>
</div>
<div class="service-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro corporis modi alias officia quod repudiandae fugit, eveniet ipsum, doloremque facere dolores ex illo hic quidem.</p>
</div>
</div>
<div class="service">
<div class="service-header">
<i class="fas fa-pen-nib"></i>
<h1>Interiar</h1>
</div>
<div class="service-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro corporis modi alias officia quod repudiandae fugit, eveniet ipsum, doloremque facere dolores ex illo hic quidem.</p>
</div>
</div>
</div>
Remember to remove background-color from .service. Background-color should be defined in the nth-child property.
If you want it more modular, I would recommend to use even/odd.
.service {
width: 100px;
height: 100px;
border: 1px solid black;
}
.service:nth-child(even) {
background-color: red;
}
.service:nth-child(odd) {
background-color: blue;
}
<div class="service"></div>
<div class="service"></div>
<div class="service"></div>
<div class="service"></div>
<div class="service"></div>
<div class="service"></div>
<div class="service"></div>
But you can also play around if you add different background-colors with for example :nth-child(3n+3), which means: Every third element: 3rd, 6th, 9th, etc, will have that background-color applied.
:nth-child(2n+2) => 2nd, 4th, 6th...
image doesnt fit parent element
here is the full code
https://jsfiddle.net/601q9j7c/1/
<section class="cards">
<div class="card">
<div class="img-data">
<div clas="bgimg"> <img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt=""> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
If you don't set any defined width in either the CSS or the <img> tag, the image will be displayed at full size regardless of its container. This is your issue. So you need to ensure the image is at maximum 100% of it's parent's width.
HTML only
<section class="cards">
<div class="card">
<div class="img-data">
<div clas="bgimg"> <img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt="" width="100%"> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
It is best practise to do this with CSS rather than directly into HTML, but you have not shown any CSS in your question.
A CSS example is below:
CSS example
.bgimg > img {
max-width: 100%;
width: 100%;
height:auto;
}
<section class="cards">
<div class="card">
<div class="img-data">
<div class="bgimg"> <img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt=""> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
First of all ! your spelling your class is wrong, that's why image is not fitting.
Make the width of the image to be 100% and its height is auto so that is don't stretch but then your image may be come out of parent container make there overflow:hidden
.cards {
display: flex;
justify-content: center;
}
.card {
width: 60%;
justify-content: center;
display: grid;
grid-template-columns: 50% 50%;
box-shadow: 10px 0px 20px rgba(0,0,0,0.08);
height: 25rem;
}
.img-data {
height: 100%;
z-index: 1;
background-color: salmon;
display: grid;
grid-template-rows: 50% 50%;
}
.bgimg {
overflow: hidden;
}
.bgimg img {
height: auto;
width: 100%;
}
<section class="cards">
<div class="card">
<div class="img-data">
<div class="bgimg"> <img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt=""> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
This should work and is dynamic:
This gives the image an inherited width and height, which means that it replicates the width of the previous object. It is given with the property style="width: inherit; height: inherit;"
.bgimg {
width: 500px; /*Or whatever you want...*/
}
/* this CSS can be directly inserted in a tag with style="width: 500px;"*/
<section class="cards">
<div class="card">
<div class="img-data">
<div class="bgimg"><!--*NOTE: you wrote <div clas="bgimg">(you missed an 's')--><img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt="" style="width: inherit; height: inherit;"> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
Hope this helps!
I am trying to layout a grid in bootstrap that consists on the desktop of a full 12 column layout, inside that, there is a 8 column grid and a 4 column grid. the 8 column grid is filled with an image/text, the 4 column grid consists in its own of 2 elements below each other containting image/text.
on smaller breakpoint the layout should simply show 3 elements in same size below each other.
I fiddled around but I do not get it to work. Below you also find next to the html a sketch from what I am trying to achieve. Any hints? I do not feel this is possible out of the box with bootstrap 4.
<section>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-8">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Qui illo eaque libero, modi
porro iusto magni sint laboriosam eius. Fugiat non ad pariatur sit libero optio
doloremque molestiae harum! Rem!</p>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Illo
ratione blanditiis tempore tempora non. Neque adipisci maxime aspernatur voluptate
sunt non totam, temporibus provident necessitatibus distinctio impedit nobis aut at!
</div>
<div class="col-md-12">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Illo
ratione blanditiis tempore tempora non. Neque adipisci maxime aspernatur voluptate
sunt non totam, temporibus provident necessitatibus distinctio impedit nobis aut at!
</div>
</div>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Qui illo eaque libero, modi
porro iusto magni sint laboriosam eius. Fugiat non ad pariatur sit libero optio
doloremque molestiae harum! Rem!</p>
</div>
</div>
</div>
</div>
</div>
</section>
As a sketch it looks like this:
You need to specify the smaller col width. You also had an extra unnecessary row and col wrapping it. Below is a working example of what you are looking for. col-12 class was added for any screen smaller than md
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-12 col-md-8">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Qui illo eaque libero, modi porro iusto magni sint laboriosam eius. Fugiat non ad pariatur sit libero optio doloremque molestiae harum! Rem!</p>
</div>
<div class="col-12 col-md-4">
<div class="row">
<div class="col-12">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Illo ratione blanditiis tempore tempora non. Neque adipisci maxime aspernatur voluptate sunt non totam, temporibus provident necessitatibus distinctio impedit nobis aut at!
</div>
<div class="col-12">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Illo ratione blanditiis tempore tempora non. Neque adipisci maxime aspernatur voluptate sunt non totam, temporibus provident necessitatibus distinctio impedit nobis aut at!
</div>
</div>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Qui illo eaque libero, modi porro iusto magni sint laboriosam eius. Fugiat non ad pariatur sit libero optio doloremque molestiae harum! Rem!</p>
</div>
</div>
</div>
Please try this snippet.
.row {
margin: 20px 0;
}
.col .card {
height: calc(100% - 10px);
}
.card{
margin-bottom: 10px;
}
.card img {
width: 100%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col col-sm">
<div class="card">
<img class="card-img-top" src="https://source.unsplash.com/random/300x150" alt="Image">
<div class="card-body">
<p>Some text goes here Some text goes here Some text goes here</p>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<img class="card-img-top" src="https://source.unsplash.com/random/300x150" alt="Image">
<div class="card-body">
<p>Some text Some text goes here Some text goes here Some text goes here</p>
</div>
</div>
<div class="card">
<img class="card-img-top" src="https://source.unsplash.com/random/300x150" alt="Image">
<div class="card-body">
<p>Some text Some text goes here Some text goes here Some text goes here</p>
</div>
</div>
</div>
</div>
</div>
I have two divs on my page; side panel and main panel.
In the side panel I will always have a bunch of blocks on content, the number with change all the time. And the main panel will have some block of content. Generally the side panel will have bigger height than main panel.
I am looking for the main panel height to equal the content in that panel and I am looking for a way to have the height of the side panel equal to the size of the main panel. While the the overflow of the side panel scroll. Im not looking to set a static height for either, because the amount of content changes.
Currently I'm using grid but all for changing that if there is a way to do this.
Here is a Codepen mockup of what I currently have:
https://codepen.io/aculbreth/full/VMjRyx
.box {
display: grid;
grid-template-columns: 1fr 4fr;
grid-gap: 20px;
grid-auto-columns: max-content;
background: #efefea;
margin: 50px auto;
padding: 20px;
box-sizing: border-box;
.side_panel {
background:#fff;
padding:20px;
box-sizing: border-box;
.side_panel_box {
text-align:center;
border: 1px solid #000;
margin-bottom:20px;
}
}
.main_panel {
background:#fff;
padding:20px;
box-sizing: border-box;
display:block;
grid-auto-columns: max-content;
}
}
Here is a rough mockup of what i'm looking for:
As you've tagged your post with jQuery, it can be done via jquery pretty painlessly. As your CSS was questioned, I remade it to be simple css, and the jQuery simply sets the side pane height to the main content height. Hope it helps!
*** Please note, to see either of these work well, view them full-page.
$(document).ready(function() {
var maxHeight = $(".main_panel p").height();
$(".side_panel").height(maxHeight);
})
.box {
display: grid;
grid-template-columns: 1fr 4fr;
grid-gap: 20px;
grid-auto-columns: max-content;
background: #efefea;
margin: 50px auto;
padding: 20px;
box-sizing: border-box;
}
.side_panel {
background: #fff;
padding: 20px;
box-sizing: border-box;
overflow: auto;
}
.side_panel_box {
text-align: center;
border: 1px solid #000;
margin-bottom: 20px;
}
.main_panel {
background: #fff;
padding: 20px;
box-sizing: border-box;
display: block;
grid-auto-columns: max-content;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">
<div class="side_panel">
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
</div>
<div class="main_panel">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi explicabo autem cupiditate, facere quas recusandae itaque voluptates sint accusantium amet illo veniam totam placeat odio magni, quaerat eligendi. Distinctio et cupiditate nemo fugit,
praesentium, ea obcaecati dolores non amet autem sequi laboriosam labore vero fugiat dolorem qui voluptatibus omnis eos architecto, recusandae corporis rerum quod. Ea minus et odio voluptate quaerat facere incidunt, impedit repellat eos nihil quis
modi vel molestiae, eum vitae nam nemo quasi sit aperiam unde ex fugiat. Magnam dolores, enim consectetur veniam illum error eaque ea necessitatibus nam ipsam maxime dolore temporibus animi odio eum molestiae iure. Ut quos cupiditate ad perferendis
dolorum nemo deserunt exercitationem magni ipsa iste ea fugit expedita sapiente numquam reprehenderit dolore, quo minus excepturi asperiores sit voluptatibus accusamus necessitatibus, ipsam. Delectus iste cupiditate asperiores vero repellendus atque
aliquid temporibus perspiciatis reiciendis quibusdam similique, nesciunt accusantium tempora voluptatem optio qui odit ullam amet eveniet illum incidunt quis quia repudiandae animi. Recusandae, consequuntur laboriosam praesentium fugit possimus
nemo ut porro reiciendis quo aperiam et aliquam fuga consectetur fugiat veritatis necessitatibus officiis, officia repellendus, rem. Voluptatem itaque, dolores autem at, culpa cum quam ratione laborum quo totam, nemo sed dolor, hic nisi nobis illo.</p>
</div>
</div>
Doing the same thing in pure CSS, here's the following. Note that this is applied pretty much directly from here, and applied to this particular use case.
.box {
display: flex;
}
.flex-item {
flex: 0 0 50%;
position: relative;
}
.flex-item-inner {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: auto;
}
.side_panel {
background: #fff;
padding: 20px;
box-sizing: border-box;
overflow: auto;
}
.side_panel_box {
text-align: center;
border: 1px solid #000;
margin-bottom: 20px;
}
.main_panel {
background: #fff;
padding: 20px;
box-sizing: border-box;
display: block;
grid-auto-columns: max-content;
}
<div class="box">
<div class="flex-item side_panel">
<div class="flex-item-inner">
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
<div class="side_panel_box">
<h1>Title</h1>
<p>Some text here</p>
</div>
</div>
</div>
<div class="flex-item main_panel">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi explicabo autem cupiditate, facere quas recusandae itaque voluptates sint accusantium amet illo veniam totam placeat odio magni, quaerat eligendi. Distinctio et cupiditate nemo fugit,
praesentium, ea obcaecati dolores non amet autem sequi laboriosam labore vero fugiat dolorem qui voluptatibus omnis eos architecto, recusandae corporis rerum quod. Ea minus et odio voluptate quaerat facere incidunt, impedit repellat eos nihil quis
modi vel molestiae, eum vitae nam nemo quasi sit aperiam unde ex fugiat. Magnam dolores, enim consectetur veniam illum error eaque ea necessitatibus nam ipsam maxime dolore temporibus animi odio eum molestiae iure. Ut quos cupiditate ad perferendis
dolorum nemo deserunt exercitationem magni ipsa iste ea fugit expedita sapiente numquam reprehenderit dolore, quo minus excepturi asperiores sit voluptatibus accusamus necessitatibus, ipsam. Delectus iste cupiditate asperiores vero repellendus atque
aliquid temporibus perspiciatis reiciendis quibusdam similique, nesciunt accusantium tempora voluptatem optio qui odit ullam amet eveniet illum incidunt quis quia repudiandae animi. Recusandae, consequuntur laboriosam praesentium fugit possimus
nemo ut porro reiciendis quo aperiam et aliquam fuga consectetur fugiat veritatis necessitatibus officiis, officia repellendus, rem. Voluptatem itaque, dolores autem at, culpa cum quam ratione laborum quo totam, nemo sed dolor, hic nisi nobis illo.</p>
</div>
</div>