two twitter bootstrap columns, both need to have the same height - html

I need the right column to have the same height as the left column, because the border needs to go all the way down to the end of the page, it is apart of the design.
I thought about setting the border on the row class but there is spacing between the column and row and was unable to override that spacing.
Any help getting the right column to stretch the entire page would be appreciated, thanks.
http://www.bootply.com/117727
css
html, body { min-height: 100%; }
.container { min-height: 100%; }
.left { border: 1px solid red; }
.row { border: 1px solid purple; }
.right { border: 1px solid green; height: 100%; }
html
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-8 left">
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
<p>this is a paragraph</p>
</div>
<div class="col-sm-4 right">
<p>this is a paragraph</p>
</div>
</div>
</div>
</div>

Add a class .equalCol to both of your column. And use this jQuery code to do the magic.
BOOTPLY DEMO
var highestCol = Math.max($('.left').height(),$('.right').height());
$('.equalCol').height(highestCol);
The code here is calculating and comparing the height of both columns and storing the max value in the highestCol variable. Later that highest value is being applied to both the column via same class i.e. .equalCol

Related

Equal distribution of height across multiple Flex Columns [duplicate]

This question already has answers here:
Align child elements of different blocks
(3 answers)
Closed 10 months ago.
We have the following problem:
It is about accommodating three boxes in a row, which should have the same height. In addition, the boxes each contain two parts: an introductory block and a detailed description.
If we now build the whole thing with Bootstrap 4, this is the structure:
/**
* CSS just for visualization
**/
.block-wrap {
background: lightgrey;
height: 50px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-4 block-wrap">
<div>
Intro text
</div>
<div>
Detais text
</div>
</div>
<div class="col-4 block-wrap">
<div>
Intro text
</div>
<div>
Detais text
</div>
</div>
<div class="col-4 block-wrap">
<div>
Intro text
</div>
<div>
Detais text
</div>
</div>
</div>
We want the blocks (cols) to always have the same height - this means that the tallest block (based on the content) dictates the height of the others. We achieve this by setting the height of all blocks to 100 percent. It will look somewhat like this:
Now it gets tricky. While the blocks should always have the same height among themselves, the detail blocks should always start at the same height, like this:
Any idea how we can achieve this - it is important that the responsive behavior is retained and the blocks also make sense on mobile.
Edit:
I found a simple solution while stumbling across another problem - in hindsight I wonder why I didn't think of that right away, after all I've already worked with it. Thats how it works:
Bootstrap comes with a function to sort the columns. So in the end I just created a row with 6 columns. I then gave them a sorting on the different devices during the break.
I have recreated it again for you to illustrate:
Codepen fullscreen
we can use table to do that. not sure if we can do that flex box or grid without using javascript
.container {
border: 1px solid black;
border-collapse: collapse;
}
.intro {
background:lightblue;
}
.intro div{
background:orange;
}
.details div{
background:lightgreen;
}
.details {
height:100px;
background:lightblue;
}
table td {
width: 1%;
border: 1px solid black;
padding:10px;
vertical-align:top;
}
table td.details{
vertical-align:bottom;
}
.ch-50 {
height: 5em;
}
.ch-75 {
height: 7.5rem;
}
.ch-100 {
height: 10rem;
}
.ch-20 {
height: 2rem;
}
table{width:100%;}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<table class="container">
<tr>
<td class="intro ch-50">
<div class="h-75"></div>
</td>
<td class="intro ch-75">
<div class="h-100"></div>
</td>
<td class="intro ch-100">
<div class="h-50"></div>
</td>
</tr>
<td class="details">
<div class="h-50"></div>
</td>
<td class="details">
<div class="h-75"></div>
</td>
<td class="details">
<div class="h-100"></div>
</td>
<tr>
</tr>
</table>
/**
* CSS just for visualization
**/
.row {
display: flex;
}
.block-wrap {
background: lightgrey;
flex: 1;
border: 1px solid;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-4 block-wrap">
<div>
Intro text
Intro text
Intro text
</div>
<div>
Detais text
</div>
</div>
<div class="col-4 block-wrap">
<div>
Intro text
</div>
<div>
Detais text
</div>
</div>
<div class="col-4 block-wrap">
<div>
Intro text
Intro text
Intro text
Intro text
</div>
<div>
<p>Detais text</p>
<p>Detais text</p>
<p>Detais text</p>
<p>Detais text</p>
</div>
</div>
</div>
Please check the properties of flex that I have given to block-wrap. You have to give class to Intro Text as well if you want the height of that column to be same as well

Padding bottom caused due to overflow: auto

I am trying to put MathJax content inside a div with the css 'overflow:auto' so that the div will show a horizontal scroll bar for long mathematical expressions.
But, i am getting a strange behavior. The existing div is like the first one in the following snippet. However when I add overflow:auto, a vertical scroll bar appear (see the second div in the following snippet). By looking into the details, I understand, it is caused due to the alignment caused by MathJax classes.
Note that, changing box-sizing or vertical-align property does not solve this issue. But, if I add a padding-bottom to the div or if i set overflow-y:hidden, this can be solved. But I am not sure if this is the right approach.
Could anyone help me to understand exactly why the overflow-auto is forcing a padding bottom for the div, why it is not included in the height of the div forcing the vertical scrollbar to appear, and what is the best way to resolve it. Thanks
.margin-botom-zero {
margin-bottom: 0;
}
.red {
background: red;
}
.blue {
background: blue;
}
.overflow-auto {
overflow-x: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax:{inlineMath: [['$','$']]} });
</script>
<div class="red">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{2}$</p>
</div>
<br>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{2}$</p>
</div>
As I commented there is a lot of code dynamically added by the plugin and it's difficult to identify the issue. It's clearly an overflow issue created by one among all the nested span and it's somehow random.
For example, if you replace the numbers with letters you won't have the issue:
.margin-botom-zero {
margin-bottom: 0;
}
.red {
background: red;
}
.blue {
background: blue;
}
.overflow-auto {
overflow-x: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax:{inlineMath: [['$','$']]} });
</script>
<div class="red">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{2}$</p>
</div>
<br>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{j}$</p>
</div>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{9}$</p>
</div>
An idea of fix is to increase the line-height of p to avoid the overflow. It remains an approximate solution for this particular case. It will probably not work in other situations:
.margin-botom-zero {
margin-bottom: 0;
line-height: 2.7em;
}
.red {
background: red;
}
.blue {
background: blue;
}
.overflow-auto {
overflow-x: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax:{inlineMath: [['$','$']]} });
</script>
<div class="red">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{2}$</p>
</div>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{j}$</p>
</div>
<div class="red overflow-auto">
<p>this is test</p>
<p class="blue margin-botom-zero">$\dfrac{1}{9}$</p>
</div>

extend scrollable div to match bottom of another div

Basically, I have two columns, each with row divs of different height (dynamic content). on the right column, the bottom div has a scrollable set of content. What I want to do is to be able to make the scrollable div have a max-height such that its bottom lines up with the end of the divs in the first column.
The biggest difference I see between my question and How do I keep two divs that are side by side the same height? is that my 2 divs do not start at the same point (and I don't want to use flexbox due to compatibility issues with IE)
VERY simple plunkr: http://plnkr.co/edit/P1yvJon24xOeb3B9as3P?p=preview
HTML
<div class="row">
<div class="col-md-8">
<div class="row row1">randomly heighted content</div>
<div class="row row2">
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
</div>
</div>
<div class="col-md-4">
<div class="row row3">
<p>random content</p>
</div>
<div class="row row4">
<div class="scroll-container">
<div class="scroll">
<p>item1</p>
<p>item2</p>
<p>item3</p>
<p>item4</p>
<p>item5</p>
<p>item6</p>
</div>
</div>
</div>
</div>
</div>
(in the plunkr I want the item1....item6 to line up with the bottom of the red div)
CSS
.row1 {
background-color: yellow;
}
.row2 {
background-color: red;
}
.row3 {
background-color: blue;
}
.row4 {
background-color: green;
}
.scroll {
overflow-y: scroll;
max-height: 100px;
}
Things I've tried:
1) Setting fixed heights for each div. This doesn't work because I need the height to change with the content for the other divs. In addition, the inner content isn't responding to fixed heights.
2) I don't think I want to use tables because a) I have heard it is very bad style b) It doesn't matter/really shouldn't be the case that row1 and row3 are the same height
3) Flexbox is a problem because it works very poorly in tandem with percentages padding. And the top left div is a video with the 0 height padding-bottom trick to make it preload the space properly. So one option would be to find a way around the padding-bottom trick and then use flex box.
4) The weird padding: 100000px; margin: -1000000px; trick didn't work when I tried it, however I could simply be missing an additional step
I don't think this is possible using only HTML/CSS, because the height of a particular div needs to be dynamically determined that relies on another div that isn't its parent or child.
Therefore I was able to solve it using JavaScript:
http://liveweave.com/3014aD
Here are the files should Liveweave ever go down.
index.html
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css"> <!-- Put your style.css below bootstrap, so that your custom css overrides it -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <!-- jQuery -->
<script src="script.js"></script>
</head>
<body>
<div class="row">
<div class="col-left col-md-8"> <!-- Added col-left class here -->
<div class="row1">
<p>randomly heighted content</p>
</div>
<div class="row2">
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
<p>randomly heighted content</p>
</div>
</div>
<div class="col-right col-md-4"> <!-- Added col-right class here -->
<div class="row3">
<p>random content</p>
</div>
<div class="row4">
<div class="scroll-container">
<div class="scroll">
<p>item1</p>
<p>item2</p>
<p>item3</p>
<p>item4</p>
<p>item5</p>
<p>item6</p>
<p>item7</p>
<p>item8</p>
<p>item9</p>
<p>item10</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
style.css
.row1 {
overflow: auto;
background-color: yellow;
}
.row2 {
overflow: auto;
background-color: red;
}
.row3 {
overflow: auto;
background-color: blue;
}
.row4 {
overflow: auto;
background-color: green;
}
.scroll {
overflow-y: scroll;
}
.col-left {
padding-right: 0px !important;
}
.col-right {
padding-left: 0px !important;
}
script.js
function SetHeight() {
var left = $(".col-left").css("height");
var right = $(".row3").css("height");
var result = parseInt(left) - parseInt(right);
$(".scroll").css("height", result);
}
$(window).resize(function() {
SetHeight();
});
SetHeight(); // Call once to start off with

display into fixed html area

In my html I get 'response' from controller. Number of lines in the response varies (max is 3).
What is the best way to 'reserve' 3 lines on my html page so the next div with 'SOMETHING' paragraph is not scrolled down by 'response' ?
<div class="row">
<p ng-bind-html="response"></p>
</div>
<div class="row">
<p>SOMETHING</p>
</div>
Using CSS, fix the height occupied by your 3 rows and use overflow to scroll within that fixed height div.
CSS Overflow might help you.
.row-fixed-height {
height: 150px;
overflow: scroll;
}
and in HTML:
<div class="row-fixed-height">
<p ng-bind-html="response"></p></div>
Since the height of the lines varies based on font and font size, I would use line breaks to "reserve" the three lines. If you were to use for instance a fixed height on the div or p, it might jump around on a different browser that uses a different font.
Live Demo:
#response {
background: red;
}
<div class="row">
<p id="response" ng-bind-html="response">
<br />
<br />
<br />
</p>
</div>
<div class="row">
<p>SOMETHING</p>
</div>
JSFiddle Version: https://jsfiddle.net/rspyho74/
As oori pointed you, this is is about CSS, not Angular. The easiest way to fix the height to 3 lines is using the em unit:
.row{
margin: 10px;
padding: 5px;
border: 1px solid #000;
border-radius: 5px;
}
p{
float: left;
margin: 0 5px;
padding: 5px;
border: 1px solid #000;
height: 3em;
}
<div class="row">
<p ng-bind-html="response"></p>
<p ng-bind-html="response">Line 1</p>
<p ng-bind-html="response">Line 1<br>Line 2</p>
<p ng-bind-html="response">Line 1<br>Line 2<br>Line 3</p>
<div style='clear: both;'></div>
</div>
<div class="row">
<p>SOMETHING</p>
<div style='clear: both;'></div>
</div>
As you can see, the paragraph keeps its height no matter how many lines there are. If you remove the height property you can see the difference.

Bootstrap inside row div 100% height

actually how to make the div inside a row equal to 100% height, i mean the left sidebar will following height, depending on the right content,
just try give a height: 100%; but it doesn't work, some advice will be appreciated
<body>
<div class="content">
<div class="container main">
<div class="row 2-col">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 left">
<p>Sidebar</p>
<p>Sidebar</p>
<p>Sidebar</p>
</div>
<div class="col-xs-9 col-sm-9 col-md-9 col-lg-9 right">
<p>Content </p>
<p>Content </p>
<p>Content </p>
<p>Content </p>
<p>Content </p>
<p>Content </p>
<p>Content </p>
<p>Content </p>
<p>Content </p>
<p>Content </p>
</div>
</div>
</div>
</div>
</body>
html, body, .content, .main, .2-col {
width: 100%;
height: 100%;
}
.content {
background: #a1a1a1;
}
.main {
background: #666;
}
.left {
height: 100%;
background: #333;
box-sizing: border-box;
}
.right {
height: 100%;
background: #ccc;
box-sizing: border-box;
}
p {
color: #fff;
}
https://jsfiddle.net/x63qtvsh/4/
Thanks
One solution is calculate the height of two columns left sidebar and your right content after DOM ready.
And then dynamically set the the height of both the columns to maximum height.
Thanks,
You can try this:
function sidebarHeight(){
var tallest = $('.right').height();
$('.left').height(tallest);
}
sidebarHeight();
$(window).on("resize", function(){
sidebarHeight();
});
Example: https://jsfiddle.net/x63qtvsh/9/
Note: You will need the jQuery library for this.