Responsive box grid with bootstrap-4 different box heights - css

I tried to make a responsive grid of 6 textboxes with the box class and bootstrap.
My problem is , that with different amount of text in it the box they have different widths / heights, but i want them to have the same max-height / max-width as the box with the most text in it.
Is there a chance to get this done without hard-coding the width / height for all boxes?
Here's a code snippet:
/***** Box *****/
.flex-box {
position: relative;
text-align: center;
margin-top: 10px;
margin-right: auto;
margin-bottom: ;
margin-left: auto;
padding: 40px;
transition: all 0.3s ease;
background-color: rgb(170, 230, 255);
}
.flex-box:hover {
margin-top: 5px;
margin-bottom: 5px;
-webkit-box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.25);
-moz-box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.25);
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.25);
}
<!-- Textbox-Sections -->
<section id="about_me" class="section-padding title">
<div class="container-fluid">
<div class="container pt-4">
<h1 class="title">About me</h1>
<div class="row">
<div class="col col-12 col-sm-6 col-lg-4">
<div class="flex-box">
<h1 class="boxtitle">My way</h1>
<p class="lead">
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti fuga iusto aspernatur magni rem quas deserunt repellendus hic fugit amet tempora labore perferendis, voluptate possimus itaque cum molestias dolores. Omnis?</div>
</p>
</div>
</div>
<div class="col col-12 col-sm-6 col-lg-4">
<div class="flex-box">
<h1 class="boxtitle">My way</h1>
<p class="lead">
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Esse voluptatum soluta cum provident explicabo fugiat dolores odit blanditiis dolorem magni. Quaerat temporibus doloremque beatae voluptatum dignissimos? Eligendi voluptatum similique
incidunt!
</div>
</p>
</div>
</div>
<div class="col col-12 col-sm-6 col-lg-4">
<div class="flex-box">
<h1 class="boxtitle">My way</h1>
<p class="lead">
<div>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptate ipsam neque recusandae similique. Inventore repellendus aliquid delectus explicabo dolore sapiente voluptas nihil dolorem tempore voluptates, nemo ipsum cumque animi quidem.</div>
</p>
</div>
</div>
<div class="col col-12 col-sm-6 col-lg-4">
<div class="flex-box">
<h1 class="boxtitle">My way</h1>
<p class="lead">
<div>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quod illo incidunt nihil praesentium minus itaque hic, soluta dicta cupiditate quos dolorum esse, harum placeat, qui veritatis animi sunt? Ab, nobis.</div>
</p>
</div>
</div>
<div class="col col-12 col-sm-6 col-lg-4">
<div class="flex-box">
<h1 class="boxtitle">My way</h1>
<p class="lead">
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni, fuga vel. Maxime hic tempore quo animi ex vero doloribus dolores quos, sapiente delectus dolor et laborum amet quam aspernatur earum.</div>
</p>
</div>
</div>
<div class="col col-12 col-sm-6 col-lg-4">
<div class="flex-box">
<h1 class="boxtitle">My way</h1>
<p class="lead">
<div>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Dicta, repellendus distinctio ratione autem consequatur rerum libero nesciunt ullam eaque molestias odit architecto nisi incidunt quasi omnis ut. Natus, exercitationem alias.</div>
</p>
</div>
</div>
</div>
</div>
</div>
</section>
Here's a link to the CodePen site
Thanks

Just make the .flex-box height:100% so that it fills the col-*...
https://codepen.io/anon/pen/GQORQV?editors=1100
.flex-box {
position: relative;
text-align: center;
margin-top: 10px;
margin-right: auto;
margin-bottom:;
margin-left: auto;
padding: 40px;
height: 100%;
transition: all 0.3s ease;
background-color: rgb(170, 230, 255);
}

I don't think that is possible with only with css but yes if you are making these boxes vertical I mean one to each other then definitely its possible but not horizontally. Same height possible in the grid if section are align one to each other like --

As #Abhijeet stated it is only possible to use css if the boxes are horizontally aligned. Otherwise you can use this jQuery snippet:
var max_height = 0;
var max_width = 0;
$('.equal-size').each(function(e) {
h = $(this).height();
if(typeof(h) != "undefined") {
if(h > max_height) {
max_height = h;
}
}
w = $(this).width();
if(typeof(w) != "undefined") {
if(w > max_width) {
max_width = w;
}
}
});
if(max_height > 0) {
$('.equal-size').height(max_height);
}
if(max_width > 0) {
$('.equal-size').width(max_width);
}
You need to give the elements the class equal-size.
It is looking for the max height/width and applying it to every element.
This is only working if you have only one group of elements that should have same height/width. If you have more you need to give the group numbers and change the classes appropriately (equal-size-1, equal-size-2, ...) and use this snippet:
var numberOfGroups = 2;
for(var i=1; i<numberOfGroups+1; i++) {
var max_height = 0;
var max_width = 0;
$('.equal-size-'+String(i)).each(function(e) {
h = $(this).height();
if(typeof(h) != "undefined") {
if(h > max_height) {
max_height = h;
}
}
w = $(this).width();
if(typeof(w) != "undefined") {
if(w > max_width) {
max_width = w;
}
}
});
if(max_height > 0) {
$('.equal-size-'+String(i)).height(max_height);
}
if(max_width > 0) {
$('.equal-size-'+String(i)).width(max_width);
}
}

Related

Transform rotate is not working in custom angular accordion

I want to rotate icon as Transform: rotate(180deg). This property is not working but background-color: blue; is working perfectly.
The classname iconUp is active while click accordion button. eg: [class.iconUp]="id === 'f1'".
<div class="pricing-accordion">
<div class="pricing-accordion__item pb-30">
<div class="pricing-accordion__item--header" id="f1" (click)="openAccordion('f1')" [class.iconUp]="id === 'f1'">
<button>This is a title <span><i class="flaticon-down-arrow"></i></span></button>
</div>
<div class="pricing-accordion__item--body" *ngIf="id === 'f1'">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime, voluptas quaerat, vitae quisquam
aperiam, consequuntur neque consequatur esse nesciunt cupiditate corporis minima nulla magni
repellendus. Repellendus optio asperiores similique! Magnam.
</p>
</div>
</div>
<div class="pricing-accordion__item pb-30">
<div class="pricing-accordion__item--header" id="f2" (click)="openAccordion('f2')" [class.iconUp]="id === 'f2'">
<button>This is a title <span><i class="flaticon-down-arrow"></i></span></button>
</div>
<div class="pricing-accordion__item--body" *ngIf="id === 'f2'">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime, voluptas quaerat, vitae quisquam
aperiam, consequuntur neque consequatur esse nesciunt cupiditate corporis minima nulla magni
repellendus. Repellendus optio asperiores similique! Magnam.
</p>
</div>
</div>
</div>
.iconUp {
button {
span {
i {
transform: rotate(20deg);
-webkit-transform: rotate(20deg);
-moz-transform: rotate(20deg);
background-color: blue;
font-size: 30px;
}
}
}
}
id:any = 'f1';
openAccordion (ids:any) {
console.log(ids);
if(this.id == ids) {
this.id = '';
}
else {
this.id = ids;
}
}

How to make background text same size

i have a box for a text like this
my css is like this for the box,
.bg-text-kol2 {
background-color: #ffffff;
background-size: 10px 10px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
-webkit-box-shadow: 0px 10px 10px -8px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 10px 10px -8px rgba(0,0,0,0.75);
box-shadow: 0px 10px 10px -8px rgba(0,0,0,0.75);
}
because this slider use swipper slider this is the js,
$(document).ready(function() {
(function ($) {
//initialize swiper when document ready
var swiper = new Swiper('.swiper-container', {
slidesPerView: 2,
spaceBetween: 20,
centeredSlides: true,
})(jQuery);
});
the question is how to make the size is same? i want to make the box is 640px x 640px?
I think you can work on from this demo, I tried to replicated your images.
The most important here is you need to set the swiper height, this property helps the plugin to determine the size of the swiper.
Codepen demo: https://codepen.io/DieByMacro/pen/mYxJNo
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
direction: 'horizontal',
slidesPerView: 2,
loop: true,
spaceBetween: 20,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar',
},
})
.swiper-container {
width: 100%;
height: 600px;
}
/**
Using flex to make sure the content expand full. This makes all items height equal
*/
.swiper-item {
display: flex;
flex-flow: column nowrap;
}
.swiper-item .item-image {
flex: 0 0 auto;
background: blue;
height: 250px;
}
.swiper-item .item-content {
flex: 1 1 0px;
height: auto;
background: white;
padding: 20px;
width: 85%;
margin: -30px auto 0;
}
.wrapper {
background: lightgreen;
padding: 10px;
width: 100%;
max-width: 1024px;
margin-left: auto;
margin-right: auto;
position: relative;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/css/swiper.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/js/swiper.min.js"></script>
<div class="wrapper">
<div class="swiper-container">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide swiper-item">
<div class="item-image">
Image
</div>
<div class="item-content">
<div class="item-content__text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Exercitationem, neque!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quia unde placeat fuga reprehenderit temporibus non velit molestiae quam ipsam assumenda, quo dignissimos neque, eligendi ad in, debitis voluptatem. Eos harum praesentium facere? Quo fuga ipsum ut tenetur consequuntur veniam minus, doloremque tempora sunt ipsam dolorum reprehenderit magni excepturi ipsa quaerat voluptatum ea repudiandae assumenda placeat, earum eum cumque quis voluptates corporis! Id quis suscipit molestias, dolor laboriosam laudantium corrupti, ipsa cumque culpa tempore enim veniam saepe accusantium, natus dolores! Blanditiis quo fugiat minus iusto modi, iure earum voluptas, consequuntur qui distinctio maiores esse quae error odio cupiditate nisi veniam ad.</p>
</div>
</div>
</div>
<div class="swiper-slide swiper-item">
<div class="item-image">
Image
</div>
<div class="item-content">
<div class="item-content__text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Exercitationem, neque!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolor sequi placeat reiciendis tenetur, illum est, ipsa esse iusto neque fugiat magnam earum nostrum deserunt, odit animi vel quas assumenda fugit obcaecati nulla! Reprehenderit eum, impedit quibusdam laborum harum unde tempore. A facilis itaque, in maiores nam reiciendis provident ducimus nesciunt, consequuntur dolorum numquam optio quis facere quisquam nemo distinctio saepe?</p>
</div>
</div>
</div>
<div class="swiper-slide swiper-item">
<div class="item-image">
Image
</div>
<div class="item-content">
<div class="item-content__text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Exercitationem, neque!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fuga, tempore!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ex possimus quaerat omnis officiis. Quaerat dignissimos libero porro nesciunt quidem beatae assumenda. Doloremque temporibus quia soluta cum officiis odio, maxime veritatis.</p>
</div>
</div>
</div>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
</div>

Bootstrap grid - extend background color

I need to extend the background-color of the right column outside .container.
this is achieved by using :before. But background shows even if the column is absent.
Is there any better way?
Also I could not extend the background below 767px.
section{
padding: 50px 0;
position: relative;
}
section:before{
background: #f1f1f1;
content: '';
position: absolute;
right: 0;
top: 0;
bottom: 0;
width: 50%;
}
#media (max-width: 767px){
section:before{
display: none;
}
.col-md-4:nth-child(2){
background: #f1f1f1;
padding: t 15px;
padding: b 15px;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<section>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-4">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatum quibusdam repellendus facere aspernatur hic provident, nihil numquam natus exercitationem architecto blanditiis obcaecati reiciendis perferendis placeat consequatur quod fugiat aliquid dicta.</p>
</div>
<div class="col-md-4">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatum quibusdam repellendus facere aspernatur hic provident, nihil numquam natus exercitationem architecto blanditiis obcaecati reiciendis perferendis placeat consequatur quod fugiat aliquid dicta.</p>
</div>
</div>
</div>
</section>
Codepen - https://codepen.io/afelixj/pen/MdVKaq
try this
#media (min-width:768px) {
.width {
max-width: 570px;
display: inline-block;
}
.bg {
background-color: #f2f2f2;
}
}
.width {
padding: 15px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<section>
<div class="row m-0">
<div class="col-md-6 p-0">
<div class="text-right">
<div class="width text-left">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatum quibusdam repellendus facere aspernatur hic provident, nihil numquam natus exercitationem architecto blanditiis obcaecati reiciendis perferendis placeat consequatur quod fugiat aliquid dicta.</div>
</div>
</div>
<div class="col-md-6 p-0">
<div class="bg">
<div class="width">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatum quibusdam repellendus facere aspernatur hic provident, nihil numquam natus exercitationem architecto blanditiis obcaecati reiciendis perferendis placeat consequatur quod fugiat aliquid dicta.</div>
</div>
</div>
</div>
</section>
</section>

Fixed width sidebar on bootstrap 4 where main area disappears on mobile

There are a lot of examples for how to have a fixed width sidebar on Bootstrap 4, but I haven't found one that will cause the main content to disappear on mobile.
I've tried the following:
<div class="row no-gutters flex-nowrap">
<div class="col-md col-12 d-none d-xs-block d-sm-block ">
Main area
</div>
<div class="col-md-4 col-12 sidebar">
Sidebar
</div>
</div>
.sidebar {
max-width: 600px; min-width: 600px
}
And this mostly works, but what happens is that between 768 to 576 pixels the sidebar disappears entirely.
What I'm after is for the sidebar to be a fixed width with the main area shrinking and eventually disappearing.
With few lines of CSS you can achieve this with Flexbox. Please have a look in snippet I added with this answer.
To know more about Flexbox you can checkout those links.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://yoksel.github.io/flex-cheatsheet/
.wrapper {
display: flex;
height: 100vh;
}
.sidebar {
min-width: 150px;
max-width: 150px;
height: 100%;
background: grey;
padding: 20px;
}
.content {
padding: 20px;
height: 100%;
background: lightgrey;
}
<div class="wrapper">
<div class="sidebar">
sidebar
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis modi adipisci autem illo labore ipsum numquam explicabo excepturi similique, perspiciatis doloremque, quo asperiores at veniam culpa aperiam maiores, dolores eligendi. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis modi adipisci autem illo labore ipsum numquam explicabo excepturi similique, perspiciatis doloremque, quo asperiores at veniam culpa aperiam maiores, dolores eligendi.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis modi adipisci autem illo labore ipsum numquam explicabo excepturi similique, perspiciatis doloremque, quo asperiores at veniam culpa aperiam maiores, dolores eligendi.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis modi adipisci autem illo labore ipsum numquam explicabo excepturi similique, perspiciatis doloremque, quo asperiores at veniam culpa aperiam maiores
</div>
</div>
I believe you're looking for this:
#media (min-width:768px) {
.sidebar {
max-width: 600px; min-width: 600px;
}
}
.sidebar {
background-color: #f5f5f5;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row no-gutters flex-nowrap">
<div class="col d-none d-md-block">
Main area
</div>
<div class="col sidebar">
Sidebar
</div>
</div>
I wrapped the fixed size rule in a #media query condition only applying on md and up and I revised classes applied to columns accordingly.
Since you're setting the custom width of your sidebar anyway, you don't need col-* classes on your columns.

How block-stop the padding div child?

I've this example code:
<div class="container">
<div class="row">
<div class="left-block" style="background-color:#000000">menu</div>
<div class="text various">text article</div>
</div>
</div>
the left-block class have a background-color, but the background stop by height menu, but i like backgroud continued and stop end page, but example if insert in left-block padding-bottom=100% tha height left-block increase height by class="row" and class text-various, I like the padding stop height row or height text-various
help me please
As I understand you need something like this:
.row {
display: flex;
}
.left-block {
color: #fff;
padding: 8px;
}
.text {
padding-left: 8px;
}
<div class="container">
<div class="row">
<div class="left-block" style="background-color:#000000">menu</div>
<div class="text various">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit quia aperiam, ex fugiat! Ad odio voluptatem magnam, alias, voluptatibus vero corporis adipisci quos dicta, asperiores consequatur maiores iste unde dolore. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit quia aperiam, ex fugiat! Ad odio voluptatem magnam, alias, voluptatibus vero corporis adipisci quos dicta, asperiores consequatur maiores iste unde dolore.
</div>
</div>
</div>

Resources