Div's of equal height, flex and height not working? - html

I've creating a block called textCard in WPBakery. The markup for this block is wrapped around default Bakery classes which is rending the markup like this:
.textCard {
border: 1px solid red;
display: flex;
height: 100%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="row justify-content-center">
<div class="container test d-flex">
<div class="col-sm-4">
<div class="vc_column-inner">
<div class="wpb_wrapper">
<div class="textCard">
<div class="textCard__container">
<div class="textCard__content text-left">
<h3>heading</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="vc_column-inner">
<div class="wpb_wrapper">
<div class="textCard">
<div class="textCard__container">
<div class="textCard__content text-left">
<h3>This is heading</h3>
<p>This is content</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="vc_column-inner">
<div class="wpb_wrapper">
<div class="textCard">
<div class="textCard__container">
<div class="textCard__content text-left">
<h3>This is header</h3>
<p>This is content</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Unsure why the above CSS works when the wrappers are removed:
.textCard {
border: 1px solid red;
display: flex;
height: 100%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="row justify-content-center">
<div class="container test d-flex">
<div class="col-sm-4">
<div class="textCard">
<div class="textCard__container">
<div class="textCard__content text-left">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor</p>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="textCard">
<div class="textCard__container">
<div class="textCard__content text-left">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing </p>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="textCard">
<div class="textCard__container">
<div class="textCard__content text-left">
<p>Lorem ipsum dolor </p>
</div>
</div>
</div>
</div>
</div>
</div>
.vc_column-inner and .wpb_wrapper have no styles assigned to them so unsure what may be causing this result?

When you put your textCard in to a wrapper then force it to be 100% height, it will take 100% height of the parent wrapper, which in this case had the default property of height: auto; so it was collapsed.
If height: auto; the element will automatically adjust its height to allow its content to be displayed correctly. - W3Schools
The reason it worked when you took out the 2 wrappers is because the col-sm-4 was full height as it got the property align-items: stretch; by default as its parent is display: flex;.
Simply adding a rule to make the wrappers 100% height of their parents as well as textCard fixes this issue.
View CodePen
.textCard {
border: 1px solid red;
display: flex;
}
.vc_column-inner,
.wpb_wrapper,
.textCard {
height: 100%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="row justify-content-center">
<div class="container test d-flex">
<div class="col-sm-4">
<div class="vc_column-inner">
<div class="wpb_wrapper">
<div class="textCard">
<div class="textCard__container">
<div class="textCard__content text-left">
<h3>heading</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="vc_column-inner">
<div class="wpb_wrapper">
<div class="textCard">
<div class="textCard__container">
<div class="textCard__content text-left">
<h3>This is heading</h3>
<p>This is content</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="vc_column-inner">
<div class="wpb_wrapper">
<div class="textCard">
<div class="textCard__container">
<div class="textCard__content text-left">
<h3>This is header</h3>
<p>This is content</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

This is because your styling is no longer affected by actual height, since it's nested with two <div>elements. Following style should be child of class="col-sm-4"
Change style to
.vc_column-inner {
border: 1px solid red;
display: flex;
height: 100%;
}
or move <div class="textCard"> under <div class="col-sm-4">

If i've understood correctly, you don't need to use the bootstrap .col-4 class if you're using display:flex.
You've set the height of the items to be 100% and as display:flex so that means they'll fit the 100% height.
However this happens by default if you set the .container to display:flex and the children .textCard to flex:1 they'll all display equal. The children are set as align-items: stretch by default due to their flex container.
See codepen here, hope that's what you meant!
https://codepen.io/Robhern135/pen/LKaGVL

Related

Flex one big feather icon on left-side, title and description on right-side

I want to create flex style UI that looks like this
what I can do so far is split the UI using col-5 col-2 col-5 from bootstrap, and use flex to create the col-5 UI section (left and right), here's my code
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-5">
<div class="d-flex align-items-start">
<div class="avatar me-75">
<i data-feather="upload" class=avatar-icon></i>
</div>
<div>
<p class="mb-0">Lorem ipsum</p>
<p>lorem ipsum dolor sit amet lorem ipsum</p>
</div>
</div>
</div>
<div class="col-2">
<div class="d-flex" style="height: 50px;">
<div class="vr"></div>
</div>
</div>
<div class="col-5">
<div class="d-flex align-items-start">
<div class="avatar me-75">
<i data-feather="user-plus" class=avatar-icon></i>
</div>
<div>
<p class="mb-0">Lorem ipsum</p>
<p>lorem ipsum dolor sit amet lorem ipsum</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Here's the result
the results don't match my expectations, is there a class from bootstrap that I haven't added? or is there another way I can get the result like the mockup I want?
I recommend to remove the col-width given to the vertical border and instead add it separately from the css. Also, use the justify-content-center class of Bootstrap in the div with the d-flex class. I hope this is what you are trying to achieve.
.col-6::after {
content: "";
position: absolute;
border-right: 2px dotted #000;
height: 75px;
top: 10px;
left: 50%;
display: block;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-6">
<div class="d-flex justify-content-center">
<div class="avatar me-75">
<i data-feather="upload" class=avatar-icon></i>
</div>
<div>
<p class="mb-0">Lorem ipsum</p>
<p>lorem ipsum dolor sit amet lorem ipsum</p>
</div>
</div>
</div>
<div class="col-6">
<div class="d-flex justify-content-center">
<div class="avatar me-75">
<i data-feather="user-plus" class=avatar-icon></i>
</div>
<div>
<p class="mb-0">Lorem ipsum</p>
<p>lorem ipsum dolor sit amet lorem ipsum</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I also created a separate code if you choose to achieve this without using Bootsrap or Flex and instead use the CSS Grid Layout. :)
.card-section {
display: grid;
grid-template-columns: repeat(2, 1fr);
}
.card-section .card {
display: grid;
grid-template-columns: 100px 1fr;
justify-self: center;
align-items: center;
}
.card-section .card:first-child::after {
content: "";
position: absolute;
border-right: 2px dotted #000;
height: 100px;
top: 10px;
left: 50%;
display: block;
}
.card-section .card .icon-holder {
background: #000;
width: 75px;
height: 75px;
border-radius: 15px;
}
<div class="card-section">
<div class="card">
<div class="icon-holder">
<i class="icon"></i>
</div>
<div class="info">
<h2>
Title
</h2>
<p>
Description
</p>
</div>
</div>
<div class="card">
<div class="icon-holder">
<i class="icon"></i>
</div>
<div class="info">
<h2>
Title
</h2>
<p>
Description
</p>
</div>
</div>
</div>

bootstrap - align nested row vertically within alert-box [duplicate]

This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
Closed 2 years ago.
I'm not sure if my issue is the nested row, but I can't get the inner row vertical aligned centered within it's alert-box. Anyone any hint what I'm doing wrong?
https://jsfiddle.net/d2pg4xta/
<div class="container-fluid">
<div class="row">
<div class="col-md-6 d-flex">
<div class="alert alert-dark">
<div class="row"> <!-- here is my nested row -->
<div class="col-md-6"><p class="mb-0">1:</p></div>
<div class="col-md-6"><p class="mb-0">A</p></div>
<div class="col-md-6"><p class="mb-0">2:</p></div>
<div class="col-md-6"><p class="mb-0">B</p></div>
<div class="col-md-6"><p class="mb-0">3:</p></div>
<div class="col-md-6"><p class="mb-0">C</p></div>
<div class="col-md-6"><p class="mb-0">4:</p></div>
<div class="col-md-6"><p class="mb-0">D</p></div>
</div>
</div>
</div>
<div class="col-md-6 d-flex">
<div class="alert alert-dark text-center">
<p>Lorem ipsum ...Lorem ipsum ...</p>
<p>Lorem ipsum ...Lorem ipsum ...</p>
<p>Lorem ipsum ...Lorem ipsum ...</p>
<p>Lorem ipsum ...Lorem ipsum ...</p>
</div>
</div>
</div>
</div>
Update: It's not about aligning the 2 alert-boxes, it's about the inside of my left alert-box. I expect the inside row containing the content (abcd1234) to be more centered withing it's own alert-box like this: https://ibb.co/myntK5j
Do this:
.alert-dark {
display: flex; /*add*/
flex-direction: column; /*add*/
align-items: center; /*add*/
color: #1b1e21;
background-color: #d6d8d9;
border-color: #c6c8ca;
}
You need to use flex on .alert-box and remove margin from .row
Js fiddle: https://jsfiddle.net/zbywdacp/
Live Demo:
.row {
background: #f8f9fa;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
.alert-dark {
display: flex;
align-items: center;
justify-content: center;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 d-flex">
<div class="alert alert-dark">
<div class="row m-0">
<div class="col-md-6">
<p class="mb-0">1:</p>
</div>
<div class="col-md-6">
<p class="mb-0">A</p>
</div>
<div class="col-md-6">
<p class="mb-0">2:</p>
</div>
<div class="col-md-6">
<p class="mb-0">B</p>
</div>
<div class="col-md-6">
<p class="mb-0">3:</p>
</div>
<div class="col-md-6">
<p class="mb-0">C</p>
</div>
<div class="col-md-6">
<p class="mb-0">4:</p>
</div>
<div class="col-md-6">
<p class="mb-0">D</p>
</div>
</div>
</div>
</div>
<div class="col-md-6 d-flex">
<div class="alert alert-dark text-center">
<p>Lorem ipsum ...Lorem ipsum ...</p>
<p>Lorem ipsum ...Lorem ipsum ...</p>
<p>Lorem ipsum ...Lorem ipsum ...</p>
</div>
</div>
</div>
</div>
Try adding display: flex; to .alert.alert-dark.

Cannot fit two Jumbotrons Horizontally (Bootstrap)

I'm new to bootstrap and I am having some trouble getting two jumbotrons to sit on one row (without space in between.) No matter how small I make their respective columns, they stay on separate rows.
Here is my HTML:
<div class="col no-gutters">
<div class="col-md-6">
<div class="jumbotron jumbotron-fluid" style="background-color: #e3f2fd;">
<div class="container">
<h1 class="display-4">Title</h1>
<p class="lead">Description. Lorem ipsum dolor sit amet.</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="jumbotron jumbotron-fluid" style="background-color: #e3f2fd;">
<div class="container">
<h1 class="display-4">Active</h1>
<br>
</div>
</div>
</div>
</div>
I have not messed with the default bootstrap CSS. Thank you in advance!!!
The class of the containing div should to be row, not col:
<div class="row no-gutters">
Bootstrap's Grid system has column spacing (padding) by default. There are a few ways to address this issue to adapt to your requirements.
One approach could be to add a new CSS selector, and then modify your HTML accordingly.
CSS:
/* Add this */
.no-padding {
padding-right:0;
padding-left:0;
}
HTML:
<div class="col">
<div class="col-md-6 no-padding"> <!-- add no-padding -->
<div class="jumbotron jumbotron-fluid" style="background-color: #e3f2fd;">
<div class="container">
<h1 class="display-4">Title</h1>
<p class="lead">Description. Lorem ipsum dolor sit amet.</p>
</div>
</div>
</div>
<div class="col-md-6 no-padding"> <!-- add no-padding -->
<div class="jumbotron jumbotron-fluid" style="background-color: #e3f2fd;">
<div class="container">
<h1 class="display-4">Active</h1>
<br>
</div>
</div>
</div>
</div>

How to remove border from last-child?

So i have this demo https://fiddle.jshell.net/nx4s6jsd/ where i have that html structure. I want to remove broder-bottom from last child but i dont know how. I tried with
.product:last-child{
border-bottom:none:
}
but its not working .Any suggestion?
<div class="checkout">
<div class="checkout_title"><span>Vasa narudzba</span></div>
<div class="product custom_form_title order_product_list">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-12 no-padding-right">
<div class="product_image">
<img src="assets/img/product1_small.png" class="img-responsive" />
</div>
</div>
<div class="col-md-8 col-sm-8 col-xs-12">
<div class="product_box">
<div class="product_title">
<span>Product title</span>
</div>
<div class="product_description">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. IntegeLorem ipsum dolor sit amet</span>
</div>
</div>
</div>
</div>
</div>
<div class="product custom_form_title order_product_list">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-12 no-padding-right">
<div class="product_image">
<img src="assets/img/product1_small.png" class="img-responsive" />
</div>
</div>
<div class="col-md-8 col-sm-8 col-xs-12">
<div class="product_box">
<div class="product_title">
<span>Product title</span>
</div>
<div class="product_description">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. IntegeLorem ipsum dolor sit amet</span>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="total custom_form_title order_list">
<span class="left-title">Cijena bez PDV-a</span><span class="right-title">0,000.00 KM</span>
<span class="left-title">PDV(17%)</span><span class="right-title right">0,000.00 KM</span>
<span class="left-title">Postarina</span><span class="right-title right">0,000.00 KM</span>
<span class="left-title">Total cijena</span><span class="right-title right">0,000.00 KM</span>
</div>
</div>
</div>
</div>
you need to wrap .product with in div, the problem is right now in you code .product is not last-child of parent div so check my code snippet
.black_line{
margin-top: 30px;
border-bottom: 1px solid #24282f;
margin-bottom: 20px;
}
.finish_button{
float: left;
margin-bottom: 60px;
}
.finish_button a{
padding: 12px 45px;
}
.right{
float: right;
}
.order_list{
float: left;
margin-top: 20px;
border-top:1px solid black;
border-bottom: 1px solid black;
padding-top: 10px;
padding-bottom: 10px;
}
.order_product_list{
float: left;
margin-top: 10px;
padding-bottom: 10px;
border-bottom: 1px solid #cccccc;
}
.order_product_list:last-child{border: 0;}
<div class="checkout">
<div class="checkout_title"><span>Vasa narudzba</span></div>
<div class="product-holder">
<div class="product custom_form_title order_product_list">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-12 no-padding-right">
<div class="product_image">
<img src="assets/img/product1_small.png" class="img-responsive" />
</div>
</div>
<div class="col-md-8 col-sm-8 col-xs-12">
<div class="product_box">
<div class="product_title">
<span>Product title</span>
</div>
<div class="product_description">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. IntegeLorem ipsum dolor sit amet</span>
</div>
</div>
</div>
</div>
</div>
<div class="product custom_form_title order_product_list">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-12 no-padding-right">
<div class="product_image">
<img src="assets/img/product1_small.png" class="img-responsive" />
</div>
</div>
<div class="col-md-8 col-sm-8 col-xs-12">
<div class="product_box">
<div class="product_title">
<span>Product title</span>
</div>
<div class="product_description">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. IntegeLorem ipsum dolor sit amet</span>
</div>
</div>
</div>
</div>
</div></div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="total custom_form_title order_list">
<span class="left-title">Cijena bez PDV-a</span><span class="right-title">0,000.00 KM</span>
<span class="left-title">PDV(17%)</span><span class="right-title right">0,000.00 KM</span>
<span class="left-title">Postarina</span><span class="right-title right">0,000.00 KM</span>
<span class="left-title">Total cijena</span><span class="right-title right">0,000.00 KM</span>
</div>
</div>
</div>
</div>
Don't worry. Just remove style "border-top: 1px solid #cccccc;" from selector ".order_product_list".
Here is the universal solution for this type of situation. Adjacent sibling selector (+).
CSS
Add this
.order_product_list + .order_product_list{
border-top: 1px solid #cccccc;
}
Try with nth-child(3) and it will remove the border, like this:
.product:nth-child(3){
border-bottom: none;
}
If you inspect your code you will see that after last .product div there is another div, so the :last pseudo selector won't select anything
The last-child selector is used to select the last child element of a
parent. It cannot be used to select the last child element with a
specific class under a given parent element.
Better approach would be to wrap all the .product items in another container and then apply .product:last-child selector

Aligning content (Vertically and Horizontally) in a list group in Bootstrap

I have a row with three divisions:
Image (two divs, text and text) Button
The only thing I'm able to do is pulling the button to right or bottom of the div, but not centering it, how can I achieve this?
My code:
<div class="row">
<div class="col-md-9 ">
<div class="row">
<div class="col-md-12">
<h3>
h3. Lorem ipsum dolor sit amet.
</h3>
</div>
</div>
<div class="row list-group-item ">
<div class="col-md-3 text-center">
<img alt="Bootstrap Image Preview" src="http://lorempixel.com/140/140/" class="img-circle">
</div>
<div class="col-md-5 ">
<div class="row">
<div class="col-md-6 ">
<h3>
h3. Lorem ipsum dolor sit amet.
</h3>
</div>
<div class="col-md-6">
<h3>
h3. Lorem ipsum dolor sit amet.
</h3>
</div>
</div>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-success btn-lg pull-right">
Default
</button>
</div>
</div>
</div>
This is what I have:
This is what I want but I'm not able to achieve:
I want the button centred too
First of all no need to use this much nested rows and cols, you should try to achieve this result by using less html elements. Secondly divide your blocks into equal parts (use col-md-3 class four times).
<div class="row list-group-item ">
<div class="col-md-3 text-center vcenter">
<img alt="Bootstrap Image Preview" src="http://lorempixel.com/140/140/" class="img-circle">
</div>
<div class="col-md-3 vcenter">
<h3>
h3. Lorem ipsum dolor sit amet.
</h3>
</div>
<div class="col-md-3 vcenter">
<h3>
h3. Lorem ipsum dolor sit amet.
</h3>
</div>
<div class="col-md-3 vcenter text-center">
<button type="button" class="btn btn-success btn-lg">
Default
</button>
</div>
</div>
Finally use vertical alignment for your divs:
.vcenter {
display: inline-block;
vertical-align: middle;
float: none;
margin-left: -4px;
}
You can check fiddle here: https://jsfiddle.net/johannesMt/npgsnojf/3/
It achievs the same result by using much less html elements which makes your code more readable. Hope this helps!
First things first, You are already dividing some section which already has a width of 100%. (by using two col-6 inside a row). So that means they've been already expanding as far as possible in that row.
You should increase the col number in
<div class="col-md-5 ">
meanwhile decreasing button column
<div class="col-md-4">
In the end, you can design your structure in the following way:
<div class="row">
<div class="col-md-6 text-center">
<div class="centered-block">
<div>h3. Lorem ipsum dolor sit amet.</h3>
</div>
</div>
<div class="col-md-6 text-center">
<div class="centered-block">
<h3>h3. Lorem ipsum dolor sit amet.</h3>
</div>
</div>
</div>
with the following css rule:
.centered-block {
display: inline-block;
position: relative;
width: 100px; /* you would like to have a fixed width */
}
.centered-block > h3 {
position: absolute;
width: 100%;
top: 50%;
transform: translateY(-50%);
}
Haven't tested it out, but that should work.