How to expand column height automatically and vertically align its contents? - html

I am trying to expand the height of first three col-md-1 divs to the rows maximum height which is expanded by two col-md-5, and also vertically align its contents. I am using grid system from bootstrap.
<div class="row load-container">
<div class="col-md-1">{{Id}}</div>
<div class="col-md-1"><img src="images/{{statusIcon Status}}" /></div>
<div class="col-md-1"><div class="info-bubble info-bubble-small middle-align {{statusClass}}">{{Class}}</div></div>
<div class="col-md-5 container">
<div class="row">{{From.Name}}</div>
<div class="row">{{From.City}} {{From.State}}, {{From.Zip}}</div>
<div class="row">{{pickupFormatted}}</div>
</div>
<div class="col-md-5 container">
<div class="row">{{To.Name}}</div>
<div class="row">{{To.City}} {{To.State}}, {{To.Zip}}</div>
<div class="row">{{deliveryFormatted}}</div>
<div class="row">{{expectedFormatted}}</div>
</div>
<div class="col-md-1">
{{Weight}}
</div>
<div class="col-md-2">
{{Distance.text}}
</div>
<div class="col-md-2">
{{Duration.text}}
</div>
<div class="col-md-4">
</div>
</div>
Edit:
Here is the method the sort-of works, except that the column widths are no longer affecting actual width.
.load-container {
padding: 5px;
display: table;
width: 100%;
}
.load-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: middle;
text-align: left;
}
Ninja-edit:
This seems to work now
.load-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: middle;
}

Related

Vertical Align Center not working for div text alignment

I am trying to vertically align and I can not find the solution. I have read so many stack overflow questions and I am not sure what I am doing wrong. Here is my HTML:
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<form class="order-form">
<div class="row first-row">
<div class="col-xs-12 col-sm-2 v-middle">
<span>Order 123456789</span>
</div>
<div class="col-xs-12 col-sm-2 v-middle">
<span>Order Date: 8/28/18</span>
</div>
<div class="col-xs-12 col-sm-2 v-middle">
<span>Order Status: OP</span>
</div>
<div class="col-xs-12 col-sm-2 v-middle">
<span>Ready Status: RD</span>
</div>
<div class="col-xs-12 col-sm-4 v-middle">
<span>Facility 123 Dudley Chip-N-Saw</span>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
and here is my SCSS:
$font-family: "roboto", "open-sans";
body {
font-family: $font-family;
padding-top: 5%;
.order-form {
text-align: center;
position: relative;
display: block;
label {
display: block;
}
.first-row {
font-size: 16px;
.v-middle {
display: inline-block;
vertical-align: middle;
}
}
}
}
I a using Bootstrap v3 so I can not use the alignment classes Bootstrap 4 provides. I am not sure what else is required for vertical align besides display being inline. I know vertical alignments do not work on block level items. Please help Thanks!
Here is my codepen: https://codepen.io/sazad/pen/BOZWOV
but Please shrink screen to make sure when the line breaks the text is vertically aligned middle. Thanks!
Your .v-middle elements inherit float from the col-.. elements, thats why you can't vertically align them. Simply add float: none to that class to fix it.
You will also have a problem with whitespaces in-between display: inline-block elements. A lot of ways to fix those, my favourite fix for those is adding font-size: 0 to parent.
Final code:
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<form class="order-form">
<div class="row first-row">
<div class="col-xs-12 col-sm-2 v-middle">
<span>Order 123456789</span>
</div>
<div class="col-xs-12 col-sm-2 v-middle">
<span>Order Date: 8/28/18</span>
</div>
<div class="col-xs-12 col-sm-2 v-middle">
<span>Order Status: OP</span>
</div>
<div class="col-xs-12 col-sm-2 v-middle">
<span>Ready Status: RD</span>
</div>
<div class="col-xs-12 col-sm-4 v-middle">
<span>Facility 123 Dudley Chip-N-Saw</span>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
$font-family: "roboto", "open-sans";
body {
font-family: $font-family;
padding-top: 5%;
.order-form {
text-align: center;
position: relative;
display: block;
label {
display: block;
}
.first-row {
font-size: 0;
.v-middle {
display: inline-block;
vertical-align: middle;
float: none;
font-size: 16px;
}
}
}
}
Also a small suggestion. Don't nest selectors that heavily (for ex. order-form doesn't need to be nested inside body).

Align vertically boxes with different height in Flexbox in a row

I am using Flexbox and I am trying to create something like this:
I want the three "parent" boxes to be vertically aligned within the row. Each box have different height.
In the snippet (Codepen is better in this case as there was a character limit in Stack) I am trying to replicate the first box as a start, the boxes float to the top. They are not vertically aligned:
.box, .box-first, .box-large, .box-nested, .box-row {
position: relative;
box-sizing: border-box;
min-height: 1rem;
margin-bottom: 0;
background: #007FFF;
border: 1px solid #FFF;
border-radius: 2px;
overflow: hidden;
text-align: center;
color: #fff;
}
.box-nested {
background: #036;
border-color: #007FFF;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.css" rel="stylesheet"/>
<div class="row"> <div class="col-xs-12"> <div class="box box-container"> <div class="row"> <div class="col-xs-12"> <div class="box-first box-container"> <div class="row"> <div class="col-xs-2"> <div class="box-nested"> <img style="width:30px; height:auto;" src="https://cdn0.iconfinder.com/data/icons/simplicity/512/dollar-256.png"/> </div></div><div class="col-xs-5"> <div class="box-nested"> <div class="col-xs-12"> <div class="box-nested">111 222</div><div class="box-nested">105,306</div></div></div></div><div class="col-xs-5"> <div class="box-nested"> <div class="col-xs-12"> <div class="box-nested"> <div class="col-xs-12"> <div class="box-nested">111</div><div class="box-nested">222</div></div></div><div class="box-nested"> <div class="col-xs-12"> <div class="box-nested">105,306</div></div></div></div></div></div></div></div></div></div></div></div></div>
When I tried adding the for the display: flex; align-items: center; in the CSS it messes up with the nested divs:
I am not that familiar with Flexbox and I have seen many different versions online that don't help.

Centering a multi-line block while keeping text aligned left

I tried various different methods to no avail, including using text-align: center; on the <div> and display: inline-block; on the <p> and <h4>. Since the I have 3 different text tags inside the div I'm trying to align this only makes the text look centered and not aligned to the left.
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
.media-body {text-align: center;}
p {display: inline-block}
h4 {display: inline-block;}
<div id="j2" class="jumbotron">
<div class="container">
<div class="row">
<div id="block" class="col-sm-8 col-sm-offset-2">
<div class="media-body">
<p id="time">10:00 A.M.</p>
<h4 class="media-heading"><b>Meet & Greet</b></h4>
<p>Nametags, Swag, Refreshments</p>
</div>
</div>
</div>
</div>
</div>
This is the usual solution:
#block {
text-align: center;
}
.media-body {
display: inline-block;
text-align: left;
}
<div id="block">
<div class="media-body">
<p id="time">10:00 A.M.</p>
<h4 class="media-heading"><b>Meet & Greet</b></h4>
<p>Nametags, Swag, Refreshments</p>
</div>
</div>
But Bootstrap sets the property width: 10000px; to the .media-body class. Therefore, you need to redefine this property as width: auto;:
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
#block {
text-align: center;
}
.media-body {
display: inline-block;
text-align: left;
width: auto;
}
<div id="j2" class="jumbotron">
<div class="container">
<div class="row">
<div id="block" class="col-sm-8 col-sm-offset-2">
<div class="media-body">
<p id="time">10:00 A.M.</p>
<h4 class="media-heading"><b>Meet & Greet</b></h4>
<p>Nametags, Swag, Refreshments</p>
</div>
</div>
</div>
</div>
</div>

How to make contents vertical align inside div

I have tried different ways to align contents inside div :
1) table and table cell but it acts weirdly with width
2) I have padding which wont align properly with for every content because data differ.
Note : My actual code is inside ng-repeat
HTMl :
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12">
<div class="offer-horizontal col-sm-6 col-md-6">
<div class="col-sm-6 col-md-6 offer-logo-div-horizontal" >
<img src="https://icon.uiowa.edu/help/wp-content/uploads/2014/07/ICON_logo_only.png" alt="nothing" style="height:20px;width:50px;" class="offer-logo-horizontal">
</div>
<div class="col-sm-6 col-md-6">
<span class="offer-description-horizontal" ng-bind-html="offer.description | words:15"></span>
<p>Some really large label that will wrap to multiple lines in small screens</p>
<div>
<button>
shop now
</button>
</div>
</div>
</div>
<div class="offer-horizontal col-sm-6 col-md-6 ">
<div class="col-sm-6 col-md-6 offer-logo-div-horizontal" style="text-align:center;">
<img src="http://www.iconplc.com/icon-files/images/image-bank-component/other/icon-logo.jpg" style="height:20px;width:50px;" class="offer-logo-horizontal">
</div>
<div class="col-sm-6 col-md-6">
<span class="offer-description-horizontal" ng-bind-html="offer.description | words:15"></span>
<p>Some really large label that wil</p>
<div>
<button>
shop now
</button>
</div>
</div>
</div>
<div class="offer-horizontal col-sm-6 col-md-6">
<div class="col-sm-6 col-md-6 offer-logo-div-horizontal" style="text-align:center;">
<img src="https://upload.wikimedia.org/wikipedia/commons/9/9e/Icons_logo_normal.jpg" alt="nothing" style="height:20px;width:50px;" class="offer-logo-horizontal">
</div>
<div class="col-sm-6 col-md-6">
<span class="offer-description-horizontal" ng-bind-html="offer.description | words:15"></span>
<p>Some really large </p>
<div>
<button>
shop now
</button>
</div>
</div>
</div>
</div>
</div>
</div>
CSS :
.offer-horizontal {
min-height: 194px;
background-color: #EEF0F1;
border: 5px solid #fff;
text-align:center;
}
.offer-logo-div-horizontal {
min-height: 194px;
text-align: center;
}
.offer-logo-horizontal {
max-height: 100%;
max-width: 100%;
width: auto;
height: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
JSFiddle
My Question : How content I make data inside div vertically align.
Any help is appreciated.
Depending on your browser support, flexbox will achieve this:
Browser support: http://caniuse.com/#feat=flexbox
JSFiddle:
http://jsfiddle.net/22xvnjd5/4/
I've added the following rules to your code:
.offer-horizontal {
padding-bottom:20px; /* Tidy up the spacing on smaller screens */
display: flex;
align-items: center;
justify-content: center;
flex-flow: row wrap;
}
Not necessary for alignment, but I also adjusted the image min-height as it caused a massive gap on smaller screens!
.offer-logo-div-horizontal {
min-height: 90px;
}
#media (min-width: 768px) {
.offer-horizontal {
min-height:194px;
}
}

div table column width doesn't match rows

Spending way too much time on (what should be) a simple div table. PROBLEM: the column headers will not resize to the width of the table, or the rows. The rows appear okay, but the column headers don't.
Trying to avoid having fixed widths as the next table I post may have a different number of columns. With the following code the column headers are all scrunched to the left, next to each other, but they don't match the rows...
<style type="text/css">
.table-container {
display: table;
width: 50%;
table-layout: fixed;
border-collapse: collapse;
}
.table-heading {
font-weight: bold;
display: table-caption;
background-color: #e9e9e9;
text-align: center;
padding: 8px;
line-height: 21px;
font-size: 18px;
color: #CA8327;
}
.table-row {
display: table-row;
text-align: center;
}
.table-row-shade {
display: table-row;
text-align: center;
background-color: #e9e9e9;
}
.table-col {
display: table-cell;
text-align: center;
border: 1px solid #ca8327;
}
</style>
<div class="table-container">
<div class="table-heading">Approximate Dimensions (inches)</div>
<div class="table-col">
<div class="table-col">size</div>
<div class="table-col">head strap (inc. frame)</div>
<div class="table-col">chin strap</div>
<div class="table-col">lbs.*</div>
</div>
<div class="table-row-shade">
<div class="table-col">XXS</div>
<div class="table-col">3-9 inches</div>
<div class="table-col">2-3 inches</div>
<div class="table-col">< 5 lbs*</div>
</div>
<div class="table-row">
<div class="table-col">XS</div>
<div class="table-col">5-13 inches</div>
<div class="table-col">3-7 inches</div>
<div class="table-col">5 - 10lbs*</div>
</div>
</div>
http://jsfiddle.net/Speedy1/t3e3ken6/
You only put table-col rather than table-row
<div class="table-container">
<div class="table-heading">Approximate Dimensions (inches)</div>
<div class="table-row"> <!-- must be a table-row -->
<div class="table-col">size</div>
<div class="table-col">head strap (inc. frame)</div>
<div class="table-col">chin strap</div>
<div class="table-col">lbs.*</div>
</div>
<div class="table-row-shade">
<div class="table-col">XXS</div>
<div class="table-col">3-9 inches</div>
<div class="table-col">2-3 inches</div>
<div class="table-col">< 5 lbs*</div>
</div>
<div class="table-row">
<div class="table-col">XS</div>
<div class="table-col">5-13 inches</div>
<div class="table-col">3-7 inches</div>
<div class="table-col">5 - 10lbs*</div>
</div>
</div>
http://jsfiddle.net/vgjb578s/
Try this http://jsfiddle.net/t3e3ken6/1/
It's because you have put the class "table-col" next to your heading. Change it to "table-row" and the problem is solved.
<div class="table-row">
<div class="table-col">size</div>
<div class="table-col">head strap (inc. frame)</div>
<div class="table-col">chin strap</div>
<div class="table-col">lbs.*</div>
</div>