I would like to hide the default checkbox from my light/darkmode toggle featured on my Wordpress blog. (Using single.php)
I inspected the code using the console and adjusted the CSS using the code below in the preview which worked.
However, when I saved and ran it properly, I didn't get the same outcome.
input[type=checkbox], input[type=radio] {
box-sizing: border-box;
padding: 0;
display: none !important;
}
<section id="blog-post">
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-10">
<div class="checkbox mt-3 text-right">
<input type="checkbox" id="darkSwitch">
<label for="darkSwitch"><i class="far fa-lightbulb fa-lg"><i>Light switch</i></i></label>
</div>
<div class="row my-5 justify-content-center">
<div class="col-sm-12 col-md-10 col-lg-8 mt-3">
<h2 class="subheader mt-3">Lorem Ipsum Dolor Amet.</h2>
<div class="dropcap">
<pre></pre>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. <em>This is italic text</em>, <strong>this is bold text</strong>, <em><strong>this is bold italic</strong></em> text. Donec justo massa, imperdiet ac efficitur sit amet, pretium a nunc. Aliquam sem nisi, sagittis a lacus ut, pulvinar molestie magna. Nam aliquam tincidunt erat nec pulvinar. Nullam urna nunc, cursus nec pharetra eu, euismod id dolor. Duis imperdiet, ante iaculis suscipit pharetra, mauris neque ultricies lacus, tincidunt posuere lectus ipsum ac est. Donec odio nunc, feugiat nec mi eget, faucibus euismod urna. Donec pretium sit amet leo eget auctor. Nulla consequat metus at ullamcorper faucibus. Donec ultricies tristique velit sit amet commodo. Morbi bibendum, nulla ut aliquam bibendum, ex lacus lacinia dui, quis sagittis justo neque vel mauris. Phasellus varius dapibus sapien, et euismod turpis. Praesent elit metus, posuere nec ipsum eget, ultricies lobortis massa.</p>
<p>Quisque ornare libero id nibh imperdiet ultrices. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc fringilla urna in mauris consequat, eget lobortis elit sodales. Curabitur ipsum ligula, tincidunt eu venenatis quis, ullamcorper et nunc. Sed in hendrerit felis, eu fermentum mauris. In varius non urna at ullamcorper. Duis at arcu nibh. Vivamus et elementum purus. Nulla a tellus dapibus, tristique libero ut, porta odio. Nulla luctus aliquet tempus. Pellentesque ultrices finibus turpis, non vestibulum metus.</p>
Try the following css rules instead:
input[type='checkbox'], input[type='radio'] {
display: none !important;
visibility: hidden !important;
}
Related
I can't make my flex item be vertically aligned in the remaining space it has.
This is what I currently have:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="parent d-flex flex-column py-2">
<div class="container p-0 flex-grow-1">
<div class="mb-1 d-flex justify-content-center">
<img src="https://dummyimage.com/300x200/000/fff"></img>
<!-- need to vertically center this image -->
</div>
</div>
<div class="container p-0 flex-grow-1">
<div class="mb-1 d-flex justify-content-center">
Suspendisse non nisl sit amet velit hendrerit rutrum. Vestibulum fringilla pede sit amet augue. Praesent nec nisl a purus blandit viverra. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. Proin viverra, ligula sit amet ultrices semper, ligula
arcu tristique sapien, a accumsan nisi mauris ac eros. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Aenean imperdiet. Maecenas nec odio et ante tincidunt tempus. Praesent nonummy mi in odio. Nulla consequat massa quis
enim. Morbi mollis tellus ac sapien. In turpis. Curabitur suscipit suscipit tellus. Cras id dui. Mauris turpis nunc, blandit et, volutpat molestie, porta ut, ligula. Curabitur suscipit suscipit tellus. Nullam nulla eros, ultricies sit amet, nonummy
id, imperdiet feugiat, pede. Aenean viverra rhoncus pede. Maecenas nec odio et ante tincidunt tempus. Vivamus consectetuer hendrerit lacus.
</div>
</div>
</div>
I'm trying to vertically center the image within its container, but it doesn't work.
I tried using align-items-center, align-self-center and even justify-content-center maybe because it's a column direction, in multiple places, but non works. The image always shows at the top of the container.
UPDATED:
I didn't notice you mentioned your code in example it's just a part of content and used as right side of page.
Regarding that, I've simulated height of .parent block to stretch it.
The point is, BS5 .container not flex by itself. You have to add .d-flex class of display: flex; property to handle it in flex-way, see code comments for more details.
/* simulate parent height */
.parent {
min-height: 1000px;
}
/* show containers' area */
.container {
border: 1px solid;
}
/* code for Option-2 */
/* :first-of-type - will be applied only for first .container */
.parent.parent--tmp > .container:first-of-type {
display: flex;
align-items: center;
justify-content: center;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!-- Option-1: changing markup -->
<div class="parent d-flex flex-column py-2">
<!--
update container class list
add "d-flex align-items-center justify-content-center"
-->
<div class="container p-0 flex-grow-1 d-flex align-items-center justify-content-center">
<div class="mb-1 d-flex justify-content-center">
<!-- adjust closing tag for image -->
<img src="https://dummyimage.com/300x200/000/fff" />
<!-- need to vertically center this image -->
</div>
</div>
<div class="container p-0 flex-grow-1">
<div class="mb-1 d-flex justify-content-center">
<p>
Suspendisse non nisl sit amet velit hendrerit rutrum. Vestibulum fringilla pede sit amet augue. Praesent nec nisl a purus blandit viverra. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. Proin viverra, ligula sit amet ultrices semper, ligula
arcu tristique sapien, a accumsan nisi mauris ac eros. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Aenean imperdiet. Maecenas nec odio et ante tincidunt tempus. Praesent nonummy mi in odio. Nulla consequat massa
quis enim. Morbi mollis tellus ac sapien. In turpis. Curabitur suscipit suscipit tellus. Cras id dui. Mauris turpis nunc, blandit et, volutpat molestie, porta ut, ligula. Curabitur suscipit suscipit tellus. Nullam nulla eros, ultricies sit amet,
nonummy id, imperdiet feugiat, pede. Aenean viverra rhoncus pede. Maecenas nec odio et ante tincidunt tempus. Vivamus consectetuer hendrerit lacus.
</p>
</div>
</div>
</div>
<!-- Option-2: update only by CSS rule -->
<!-- added "parent--tmp" just for example purposes -->
<div class="parent parent--tmp d-flex flex-column py-2">
<div class="container p-0 flex-grow-1">
<div class="mb-1 d-flex justify-content-center">
<!-- adjust closing tag for image -->
<img src="https://dummyimage.com/300x200/000/fff" />
<!-- need to vertically center this image -->
</div>
</div>
<div class="container p-0 flex-grow-1">
<div class="mb-1 d-flex justify-content-center">
<p>
Suspendisse non nisl sit amet velit hendrerit rutrum. Vestibulum fringilla pede sit amet augue. Praesent nec nisl a purus blandit viverra. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. Proin viverra, ligula sit amet ultrices semper, ligula
arcu tristique sapien, a accumsan nisi mauris ac eros. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Aenean imperdiet. Maecenas nec odio et ante tincidunt tempus. Praesent nonummy mi in odio. Nulla consequat massa
quis enim. Morbi mollis tellus ac sapien. In turpis. Curabitur suscipit suscipit tellus. Cras id dui. Mauris turpis nunc, blandit et, volutpat molestie, porta ut, ligula. Curabitur suscipit suscipit tellus. Nullam nulla eros, ultricies sit amet,
nonummy id, imperdiet feugiat, pede. Aenean viverra rhoncus pede. Maecenas nec odio et ante tincidunt tempus. Vivamus consectetuer hendrerit lacus.
</p>
</div>
</div>
</div>
Outdated answer:
Check BS grid system and alignment how to make it two rows.
Here is code example:
.parent.d-flex {
flex-direction: row !important;
align-items: center;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<p class="display-6">Without markup changes</p>
<div class="parent d-flex flex-column py-2">
<div class="container p-0 flex-grow-1">
<div class="mb-1 d-flex justify-content-center">
<img src="https://i.picsum.photos/id/237/300/200.jpg?hmac=WSdbBEXvCVSqNN1HnCzm7ohp6DhAJfl9t3TcqBNDn_Q" />
</div>
</div>
<div class="container p-0 flex-grow-1">
<div class="mb-1 d-flex justify-content-center">
<p>Vivamus euismod mauris. In ac felis quis tortor malesuada pretium. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Phasellus viverra nulla ut metus varius laoreet. Curabitur ullamcorper ultricies nisi. Cum sociis natoque penatibus
et magnis dis parturient montes, nascetur ridiculus mus. Sed hendrerit. Nunc egestas, augue at pellentesque laoreet, felis eros vehicula leo, at malesuada velit leo quis pede. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Praesent
vestibulum dapibus nibh. Cras varius. Praesent ac massa at ligula laoreet iaculis. Sed cursus turpis vitae tortor. Curabitur at lacus ac velit ornare lobortis. Maecenas vestibulum mollis diam. Fusce risus nisl, viverra et, tempor et, pretium in,
sapien. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras risus ipsum, faucibus ut, ullamcorper id, varius ac, leo. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas
libero turpis vel mi. Quisque id mi. Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Proin viverra, ligula
sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Phasellus blandit leo ut odio. Curabitur vestibulum aliquam leo.</p>
</div>
</div>
</div>
<hr />
<p class="display-6">BS 5 example</p>
<div class="container">
<div class="row align-items-center">
<div class="col">
<img class="img-fluid" src="https://i.picsum.photos/id/237/300/200.jpg?hmac=WSdbBEXvCVSqNN1HnCzm7ohp6DhAJfl9t3TcqBNDn_Q" />
</div>
<div class="col">
<p>Vivamus euismod mauris. In ac felis quis tortor malesuada pretium. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Phasellus viverra nulla ut metus varius laoreet. Curabitur ullamcorper ultricies nisi. Cum sociis natoque penatibus
et magnis dis parturient montes, nascetur ridiculus mus. Sed hendrerit. Nunc egestas, augue at pellentesque laoreet, felis eros vehicula leo, at malesuada velit leo quis pede. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Praesent
vestibulum dapibus nibh. Cras varius. Praesent ac massa at ligula laoreet iaculis. Sed cursus turpis vitae tortor. Curabitur at lacus ac velit ornare lobortis. Maecenas vestibulum mollis diam. Fusce risus nisl, viverra et, tempor et, pretium in,
sapien. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras risus ipsum, faucibus ut, ullamcorper id, varius ac, leo. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas
libero turpis vel mi. Quisque id mi. Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Proin viverra, ligula
sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Phasellus blandit leo ut odio. Curabitur vestibulum aliquam leo.</p>
</div>
</div>
</div>
I am using the Bootstrap framework and I am absolutely positioning an image in the right column. The idea is to have the image be cut off on the right side on smaller screen sizes and on larger screen sizes the entire image would be visible. This is working correctly except for that on smaller screen sizes there is a horizontal scrollbar due to the overflow. Is it possible to accomplish this without having a horizontal scrollbar while at the same time not cutting the image off where it overflows?
div {
position:relative;
}
.image-container {
position:absolute;
top:50%;
right:-200px;
transform:translateY(-50%);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-6">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eu venenatis dolor. Duis ornare orci id nulla faucibus, vitae tristique lectus fringilla. Phasellus malesuada sem sit amet nisl maximus, sed accumsan ante suscipit. In aliquam tempor lorem eu aliquam. Donec auctor ut felis tincidunt malesuada. Mauris ut velit a quam tempus ultricies. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur malesuada velit libero, at venenatis metus ultricies a. Cras sit amet blandit ante. Nullam malesuada dignissim mauris, pretium lobortis tellus pellentesque sed.</p>
<p>Proin tristique non mauris eu varius. Etiam dictum mattis eros, sed euismod nisl pulvinar vitae. Suspendisse potenti. Aenean at dui lorem. Donec faucibus arcu sit amet turpis commodo accumsan eget vel arcu. Nulla maximus, lectus eu lobortis laoreet, turpis arcu auctor turpis, a aliquet magna ante at ipsum. Vestibulum eu aliquet augue. Curabitur feugiat metus vel euismod bibendum. Duis non cursus sapien. Suspendisse eget tortor ac velit tristique iaculis at eu lectus. Etiam dapibus justo sed placerat eleifend. Curabitur tincidunt, dui non suscipit tincidunt, est libero faucibus lacus, et fringilla diam urna sit amet dolor. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus porttitor erat vel facilisis interdum.</p>
</div>
<div class="d-none d-md-block col-md-6">
<div class="image-container">
<img src="https://via.placeholder.com/600x300" />
</div>
</div>
</div>
</div>
add class img-fluid to your image. That means width: 100% & height: auto. This class is given to the tags like image and video to be responsive.
div {
position: relative;
}
.image-container {
position: absolute;
top: 50%;
right: -200px;
transform: translateY(-50%);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-6">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eu venenatis dolor. Duis ornare orci id nulla faucibus, vitae tristique lectus fringilla. Phasellus malesuada sem sit amet nisl maximus, sed accumsan ante suscipit. In aliquam tempor lorem
eu aliquam. Donec auctor ut felis tincidunt malesuada. Mauris ut velit a quam tempus ultricies. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur malesuada velit libero, at venenatis metus
ultricies a. Cras sit amet blandit ante. Nullam malesuada dignissim mauris, pretium lobortis tellus pellentesque sed.</p>
<p>Proin tristique non mauris eu varius. Etiam dictum mattis eros, sed euismod nisl pulvinar vitae. Suspendisse potenti. Aenean at dui lorem. Donec faucibus arcu sit amet turpis commodo accumsan eget vel arcu. Nulla maximus, lectus eu lobortis laoreet,
turpis arcu auctor turpis, a aliquet magna ante at ipsum. Vestibulum eu aliquet augue. Curabitur feugiat metus vel euismod bibendum. Duis non cursus sapien. Suspendisse eget tortor ac velit tristique iaculis at eu lectus. Etiam dapibus justo sed
placerat eleifend. Curabitur tincidunt, dui non suscipit tincidunt, est libero faucibus lacus, et fringilla diam urna sit amet dolor. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus porttitor erat
vel facilisis interdum.</p>
</div>
<div class="d-none d-md-block col-md-6">
<div class="image-container">
<img src="https://via.placeholder.com/600x300" class="img-fluid" />
</div>
</div>
</div>
</div>
What is the best way to arrange 3 bootstrap cards in the following orders:
Card1 on the left side
Card2 and Card3 are on the right side
Card2 has a fixed height
Card3 is flexible depending on the size of Card2
Card3 has a custom scroll bar
Cards are responsive and placed one after another on mobile screens.
/* width */
::-webkit-scrollbar {
width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #888;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-6 border">
<div class="card shadow m-5">
<div class="card-body" style="height:300px;">
<h3>Card 1</h3>
</div>
</div>
</div>
<div class="col-md-6 border">
<div class="d-flex flex-column">
<div class="d-flex align-items-start">
<div class="card shadow m-5">
<div class="card-body">
<h3>Card 2</h3>
</div>
</div>
</div>
<div class="d-flex align-items-stretch">
<div class="card shadow m-5">
<div class="card-body">
<h3>Card 3</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean finibus massa nec nisl placerat sollicitudin. Phasellus mi massa, sollicitudin eu facilisis sit amet, consequat sit amet urna. Suspendisse laoreet ipsum et varius lobortis. Duis facilisis dui vel finibus dignissim. Nulla facilisi. Donec porttitor nec justo sit amet dapibus. Nam in iaculis purus.
Aliquam at blandit sem. Aenean auctor varius iaculis. In pellentesque orci quis ipsum dapibus, eu mattis nisi feugiat. Cras sollicitudin, magna eget semper placerat, leo dui convallis leo, eget vehicula massa lorem ut orci. Curabitur faucibus nec quam vel vestibulum. Morbi ipsum justo, imperdiet ut laoreet non, feugiat consectetur neque. Pellentesque rutrum bibendum risus, in gravida nisi tristique condimentum. Integer quis varius nulla, sit amet consectetur dui. In rutrum accumsan justo. Maecenas id elementum nisl, nec vulputate justo. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed interdum facilisis varius. Suspendisse potenti. Maecenas lobortis, justo sed facilisis venenatis, lacus dolor semper ex, in interdum risus metus ac velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer eget porta magna.
Vestibulum cursus vitae nulla in aliquam. Vivamus tincidunt ultricies vehicula. Proin nec nunc velit. Nulla sit amet accumsan lacus. Donec nunc purus, egestas ut lorem eget, pretium molestie lectus. Donec pellentesque tempor libero, id sollicitudin tortor finibus at. Donec sagittis nisl eget leo molestie commodo. Nullam posuere felis sed mi euismod, at mattis sapien pellentesque. Morbi sed dui molestie, feugiat sem in, accumsan nisl. Vivamus luctus blandit lacus nec imperdiet. Pellentesque non dapibus risus. Suspendisse vestibulum odio purus, nec placerat eros ultricies nec. Curabitur aliquam sollicitudin ligula, vitae semper ante ornare ac.
Proin gravida bibendum urna id dictum. Morbi nec venenatis odio, nec pulvinar nisi. Sed vehicula nunc augue, eu fringilla magna ornare sed. Curabitur ut eleifend magna. Sed elementum odio dignissim turpis scelerisque, in pulvinar mauris vehicula. Donec dignissim ante velit, vitae imperdiet ipsum placerat at. Etiam id rutrum eros, maximus consectetur ex. Praesent egestas tellus et aliquam rutrum. Praesent eget faucibus odio. Proin quis libero eget risus faucibus faucibus. Curabitur feugiat nibh nec dignissim tempor. Nam ac eros nulla.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
</body>
</html>
You don't need extra CSS. Use the Bootstrap utility classes. In order to make the right columns the height of the left column (the shorter column), you must use position: absolute as explained here.
There are Bootstrap classes for this:
h-100 position-absolute overflow-hidden on right col inner div
overflow-hidden on the Card 3
<div class="container">
<div class="row">
<div class="col-md-6 border">
<div class="card shadow m-5">
<div class="card-body" style="height:300px;">
<h3>Card 1</h3>
</div>
</div>
</div>
<div class="col-md-6 border">
<div class="d-flex flex-column h-100 position-absolute overflow-hidden">
<div class="d-flex align-items-start">
<div class="card shadow m-5">
<div class="card-body">
<h3>Card 2</h3>
</div>
</div>
</div>
<div class="d-flex align-items-stretch overflow-hidden">
<div class="card shadow m-5 overflow-auto">
<div class="card-body">
<h3>Card 3</h3> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean finibus massa nec nisl placerat sollicitudin. Phasellus mi massa, sollicitudin eu facilisis sit amet, consequat sit amet urna. Suspendisse laoreet ipsum et varius lobortis. Duis facilisis dui vel finibus dignissim. Nulla facilisi. Donec porttitor nec justo sit amet dapibus. Nam in iaculis purus. Aliquam at blandit sem. Aenean auctor varius iaculis. In pellentesque orci quis ipsum dapibus, eu mattis nisi feugiat. Cras sollicitudin, magna eget semper placerat, leo dui convallis leo, eget vehicula massa lorem ut orci. Curabitur faucibus nec quam vel vestibulum. Morbi ipsum justo, imperdiet ut laoreet non, feugiat consectetur neque. Pellentesque rutrum bibendum risus, in gravida nisi tristique condimentum. Integer quis varius nulla, sit amet consectetur dui. In rutrum accumsan justo. Maecenas id elementum nisl, nec vulputate justo. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed interdum facilisis varius. Suspendisse potenti. Maecenas lobortis, justo sed facilisis venenatis, lacus dolor semper ex, in interdum risus metus ac velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer eget porta magna. Vestibulum cursus vitae nulla in aliquam. Vivamus tincidunt ultricies vehicula. Proin nec nunc velit. Nulla sit amet accumsan lacus. Donec nunc purus, egestas ut lorem eget, pretium molestie lectus. Donec pellentesque tempor libero, id sollicitudin tortor finibus at. Donec sagittis nisl eget leo molestie commodo. Nullam posuere felis sed mi euismod, at mattis sapien pellentesque. Morbi sed dui molestie, feugiat sem in, accumsan nisl. Vivamus luctus blandit lacus nec imperdiet. Pellentesque non dapibus risus. Suspendisse vestibulum odio purus, nec placerat eros ultricies nec. Curabitur aliquam sollicitudin ligula, vitae semper ante ornare ac. Proin gravida bibendum urna id dictum. Morbi nec venenatis odio, nec pulvinar nisi. Sed vehicula nunc augue, eu fringilla magna ornare sed. Curabitur ut eleifend magna. Sed elementum odio dignissim turpis scelerisque, in pulvinar mauris vehicula. Donec dignissim ante velit, vitae imperdiet ipsum placerat at. Etiam id rutrum eros, maximus consectetur ex. Praesent egestas tellus et aliquam rutrum. Praesent eget faucibus odio. Proin quis libero eget risus faucibus faucibus. Curabitur feugiat nibh nec dignissim tempor. Nam ac eros nulla.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Demo
Some media-queries and custom CSS to get desire output.
🔗 Codepen Example
Code Snippet:
/* width */
::-webkit-scrollbar {
width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #888;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
.card-one .card-body {
height: 200px;
}
.align-items-start .card-body {
height: 200px;
}
.align-items-stretch .card-body {
max-height: 200px;
overflow-x: auto;
}
#media screen and (min-width: 450px) {
.card-container {
display: inline-flex;
}
.card-one .card-body {
height: 450px;
max-height: 450px;
}
}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12 card-container">
<div class="col-md-6 border card-one">
<div class="card shadow m-4">
<div class="card-body">
<h3>Card 1</h3>
</div>
</div>
</div>
<div class="col-md-6 border">
<div class="d-flex flex-column">
<div class="d-flex align-items-start">
<div class="card shadow m-4 container-fluid">
<div class="card-body">
<h3>Card 2</h3>
</div>
</div>
</div>
<div class="d-flex align-items-stretch">
<div class="card shadow m-4">
<div class="card-body" >
<h3>Card 3</h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean finibus massa nec nisl placerat sollicitudin. Phasellus mi massa, sollicitudin eu facilisis sit amet, consequat sit amet urna. Suspendisse laoreet ipsum et varius lobortis. Duis facilisis dui vel finibus dignissim. Nulla facilisi. Donec porttitor nec justo sit amet dapibus. Nam in iaculis purus.
Aliquam at blandit sem. Aenean auctor varius iaculis. In pellentesque orci quis ipsum dapibus, eu mattis nisi feugiat. Cras sollicitudin, magna eget semper placerat, leo dui convallis leo, eget vehicula massa lorem ut orci. Curabitur faucibus nec quam vel vestibulum. Morbi ipsum justo, imperdiet ut laoreet non, feugiat consectetur neque. Pellentesque rutrum bibendum risus, in gravida nisi tristique condimentum. Integer quis varius nulla, sit amet consectetur dui. In rutrum accumsan justo. Maecenas id elementum nisl, nec vulputate justo. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed interdum facilisis varius. Suspendisse potenti. Maecenas lobortis, justo sed facilisis venenatis, lacus dolor semper ex, in interdum risus metus ac velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer eget porta magna.
Vestibulum cursus vitae nulla in aliquam. Vivamus tincidunt ultricies vehicula. Proin nec nunc velit. Nulla sit amet accumsan lacus. Donec nunc purus, egestas ut lorem eget, pretium molestie lectus. Donec pellentesque tempor libero, id sollicitudin tortor finibus at. Donec sagittis nisl eget leo molestie commodo. Nullam posuere felis sed mi euismod, at mattis sapien pellentesque. Morbi sed dui molestie, feugiat sem in, accumsan nisl. Vivamus luctus blandit lacus nec imperdiet. Pellentesque non dapibus risus. Suspendisse vestibulum odio purus, nec placerat eros ultricies nec. Curabitur aliquam sollicitudin ligula, vitae semper ante ornare ac.
Proin gravida bibendum urna id dictum. Morbi nec venenatis odio, nec pulvinar nisi. Sed vehicula nunc augue, eu fringilla magna ornare sed. Curabitur ut eleifend magna. Sed elementum odio dignissim turpis scelerisque, in pulvinar mauris vehicula. Donec dignissim ante velit, vitae imperdiet ipsum placerat at. Etiam id rutrum eros, maximus consectetur ex. Praesent egestas tellus et aliquam rutrum. Praesent eget faucibus odio. Proin quis libero eget risus faucibus faucibus. Curabitur feugiat nibh nec dignissim tempor. Nam ac eros nulla.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
</body>
</html>
I have the following HTML layout:
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
The number of children and their heights can vary. Is it possible to style the parent element to divide the children into two columns, such that the parent takes the minimum possible height?
.parent {
display: flex;
flex-flow: column wrap;
margin: 0 -5px;
width: 500px;
height: 1500px; /* I want to remove this */
}
.child {
margin: 0 5px 10px;
width: 50%;
background: #f2f2f2;
border: 1px #ccc solid;
padding: 20px;
}
<div class="parent">
<div class="child">
<h3>Heading 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et nunc gravida, bibendum magna ut, rutrum dui. Vivamus pulvinar, tellus at tempor imperdiet, elit lectus eleifend dui, in molestie nisi mauris at sem. Nulla varius sapien ipsum, sed semper
nisl lacinia vel. Maecenas aliquet, ante eu feugiat iaculis, massa diam tincidunt est, id ornare nisi massa nec arcu. Nunc porta leo at diam aliquam eleifend. Cras vel diam dignissim, egestas lacus in, egestas ipsum. Aliquam ultricies justo et magna
dignissim auctor.</p>
</div>
<div class="child">
<h3>Heading 2</h3>
<p>Nam scelerisque hendrerit efficitur. Fusce quam mi, viverra ut enim sit amet, viverra dignissim tortor. Quisque laoreet eros sit amet ex rutrum pharetra. </p>
</div>
<div class="child">
<h3>Heading 3</h3>
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi tortor orci, hendrerit vel diam et, rhoncus pellentesque quam. Donec nec porttitor urna. Nam interdum a tellus in bibendum. Etiam ac ultricies elit.
</p>
</div>
<div class="child">
<h3>Heading 4</h3>
<p>Morbi quis tortor interdum, ornare nibh interdum, maximus quam. Praesent elit urna, sodales sed mollis in, euismod quis ex. Maecenas nec tellus eu lectus varius placerat sed id eros. Donec imperdiet vulputate neque at varius. Sed nunc mauris, pretium
pretium fringilla ut, consequat sit amet ligula. Aliquam velit odio, pharetra at tincidunt ut, interdum ut augue. Mauris ultrices, mi et congue accumsan, tellus nisl semper justo, ut consectetur purus tellus ut ipsum. Suspendisse a neque eros. Suspendisse
sit amet lacus id tortor porta lobortis. Nam tincidunt, sem id porta congue, lectus dui iaculis enim, ac tristique erat mauris et mauris. Praesent neque mi, semper ornare ullamcorper eget, commodo a mauris. Curabitur sed commodo diam, a ullamcorper
quam.</p>
</div>
<div class="child">
<h3>Heading 5</h3>
<p>Sed sit amet sem metus. Pellentesque id rhoncus felis, nec condimentum ligula. Aliquam porta erat sapien, ac efficitur nisi blandit a. Nulla congue urna ac nisi tempor ultrices. Nunc eget risus ut tortor iaculis facilisis.</p>
</div>
<div class="child">
<h3>Heading 6</h3>
<p>Fusce malesuada et magna eu dapibus. Vivamus aliquam venenatis libero, quis lobortis ante luctus nec. Nullam vel lectus justo. Etiam diam turpis, auctor in finibus eget, eleifend vel ex. Curabitur sit amet neque ex. Nulla dapibus placerat tortor,
ac viverra arcu finibus mattis. Donec vel sem urna. Phasellus pretium ultricies ipsum, eu mollis magna rutrum sed. Mauris varius accumsan diam, a aliquet nibh tincidunt ac. Proin lobortis nunc eget enim pharetra, eu lobortis nisi placerat. Aliquam
enim tortor, viverra non posuere ut, dapibus sed elit.</p>
</div>
<div class="child">
<h3>Heading 7</h3>
<p>Sed molestie congue lacinia. Proin cursus laoreet magna, a pharetra odio consequat et. Donec et ullamcorper massa. Fusce eu dapibus felis. Cras condimentum purus et eros finibus aliquam. In hac habitasse platea dictumst. Sed sit amet sem metus. Pellentesque
id rhoncus felis, nec condimentum ligula. Aliquam porta erat sapien, ac efficitur nisi blandit a. Nulla congue urna ac nisi tempor ultrices. Nunc eget risus ut tortor iaculis facilisis.</p>
</div>
</div>
http://codepen.io/anon/pen/NqLYjE
In the above example, I was able to achieve the two column layout by setting height for the parent element. I want to do it without setting the height. Is it possible?
Setting flex-direction to row is ugly, as there will be whitespace between two vertical child elements when the height of children on a single row are unequal.
I believe you need the column propertie and not the flex model.
forked pen
.parent {
-moz-column-count:2;
column-count:2;
-moz-column-gap:0;
column-gap:0;
margin: 0 -5px;
width: 500px;
}
.child {
margin: 0 5px 10px;
background: #f2f2f2;
border: 1px #ccc solid;
padding: 20px;
}
<div class="parent">
<div class="child">
<h3>Heading 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et nunc gravida, bibendum magna ut, rutrum dui. Vivamus pulvinar, tellus at tempor imperdiet, elit lectus eleifend dui, in molestie nisi mauris at sem. Nulla varius sapien ipsum, sed semper
nisl lacinia vel. Maecenas aliquet, ante eu feugiat iaculis, massa diam tincidunt est, id ornare nisi massa nec arcu. Nunc porta leo at diam aliquam eleifend. Cras vel diam dignissim, egestas lacus in, egestas ipsum. Aliquam ultricies justo et magna
dignissim auctor.</p>
</div>
<div class="child">
<h3>Heading 2</h3>
<p>Nam scelerisque hendrerit efficitur. Fusce quam mi, viverra ut enim sit amet, viverra dignissim tortor. Quisque laoreet eros sit amet ex rutrum pharetra. </p>
</div>
<div class="child">
<h3>Heading 3</h3>
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi tortor orci, hendrerit vel diam et, rhoncus pellentesque quam. Donec nec porttitor urna. Nam interdum a tellus in bibendum. Etiam ac ultricies elit.
</p>
</div>
<div class="child">
<h3>Heading 4</h3>
<p>Morbi quis tortor interdum, ornare nibh interdum, maximus quam. Praesent elit urna, sodales sed mollis in, euismod quis ex. Maecenas nec tellus eu lectus varius placerat sed id eros. Donec imperdiet vulputate neque at varius. Sed nunc mauris, pretium
pretium fringilla ut, consequat sit amet ligula. Aliquam velit odio, pharetra at tincidunt ut, interdum ut augue. Mauris ultrices, mi et congue accumsan, tellus nisl semper justo, ut consectetur purus tellus ut ipsum. Suspendisse a neque eros. Suspendisse
sit amet lacus id tortor porta lobortis. Nam tincidunt, sem id porta congue, lectus dui iaculis enim, ac tristique erat mauris et mauris. Praesent neque mi, semper ornare ullamcorper eget, commodo a mauris. Curabitur sed commodo diam, a ullamcorper
quam.</p>
</div>
<div class="child">
<h3>Heading 5</h3>
<p>Sed sit amet sem metus. Pellentesque id rhoncus felis, nec condimentum ligula. Aliquam porta erat sapien, ac efficitur nisi blandit a. Nulla congue urna ac nisi tempor ultrices. Nunc eget risus ut tortor iaculis facilisis.</p>
</div>
<div class="child">
<h3>Heading 6</h3>
<p>Fusce malesuada et magna eu dapibus. Vivamus aliquam venenatis libero, quis lobortis ante luctus nec. Nullam vel lectus justo. Etiam diam turpis, auctor in finibus eget, eleifend vel ex. Curabitur sit amet neque ex. Nulla dapibus placerat tortor,
ac viverra arcu finibus mattis. Donec vel sem urna. Phasellus pretium ultricies ipsum, eu mollis magna rutrum sed. Mauris varius accumsan diam, a aliquet nibh tincidunt ac. Proin lobortis nunc eget enim pharetra, eu lobortis nisi placerat. Aliquam
enim tortor, viverra non posuere ut, dapibus sed elit.</p>
</div>
<div class="child">
<h3>Heading 7</h3>
<p>Sed molestie congue lacinia. Proin cursus laoreet magna, a pharetra odio consequat et. Donec et ullamcorper massa. Fusce eu dapibus felis. Cras condimentum purus et eros finibus aliquam. In hac habitasse platea dictumst. Sed sit amet sem metus. Pellentesque
id rhoncus felis, nec condimentum ligula. Aliquam porta erat sapien, ac efficitur nisi blandit a. Nulla congue urna ac nisi tempor ultrices. Nunc eget risus ut tortor iaculis facilisis.</p>
</div>
</div>
Given This markup
CSS
#wrapper {
width: 900px;
}
#column1 {
width: 320px;
float: left;
}
#column2 {
width: 570px;
float: left;
padding-left: 10px;
}
#social {
text-align: center
}
​
HTML
<div id="wrapper">
<div id="column1">
<div id="image">
<a href="http://stackoverflow.com">
<img width="320" src="http://appharbor.com/assets/images/stackoverflow-logo.png">
</a>
</div>
<div id="social">
Some Social Plugins/Buttons Whatever
</div>
</div>
<div id="column2">
<div>
SOME REALLY LONG CONTENT WHICH IS USER-GENERATED (Can't be styled or this structure of divs and br be expected)
</div>
<br />
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ac ante ac dolor interdum tristique vitae sit amet erat. Quisque auctor sagittis augue, vitae eleifend nibh egestas quis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris condimentum varius orci, ac accumsan mauris viverra nec. Nunc ullamcorper dapibus velit, ac vehicula turpis placerat quis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
</div>
<br />
<div>
Vivamus quis sem lectus. Phasellus lobortis semper nulla, ut imperdiet neque aliquam at. In tincidunt, mauris quis condimentum tempor, tellus magna mollis magna, a laoreet purus metus id tellus. Proin sagittis, sapien a tristique consequat, tellus neque feugiat massa, vel vulputate ligula lectus nec enim. Aliquam erat volutpat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
</div>
<br />
<div>
Suspendisse dapibus diam eu felis convallis sed iaculis lorem aliquam. Duis sit amet metus a lectus commodo sodales vel a lacus. Praesent auctor facilisis ligula vitae convallis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam mi leo, ultrices vitae consequat at, luctus in arcu. In tincidunt pellentesque ornare. Sed laoreet porta ante, at euismod ipsum volutpat facilisis. Donec at augue iaculis ligula interdum consequat vitae quis turpis. Donec pulvinar velit nec arcu eleifend faucibus. Praesent placerat magna eget ipsum iaculis nec condimentum nibh egestas. Donec massa tellus, porttitor vitae posuere sed, dapibus quis sapien. Sed elit est, dapibus sit amet pulvinar et, volutpat non quam. Aenean eget est tellus. Mauris at tincidunt dui.
</div>
<br />
<div>
SOME REALLY LONG CONTENT WHICH IS USER-GENERATED (Can't be styled or this structure of divs and br be expected)
</div>
</div>
</div>
Also Hosted At: http://jsfiddle.net/bbQPE/1/
Is It Possible to fill the space in column one with the text in column two?
PS: Without a fixed width and the float for column2 seems to be the answer but seems like a hack more than a pure-css solution or m i wrong.?
Remove floating form column2
#column2 {
width: 570px;
padding-left: 10px;}