Bootstrap float column up to eliminate whitespace - html

I am trying to create a layout that resembles the following:
Sketch mockup
The "1/3" and "2/3" labels refer to how much of the screen I want those sections to take up (on web).
I've created 2 rows (with one column and two columns, respectively) to try to produce this layout. However, since the rows stack, I end up with a bunch of whitespace, so my layout looks like this:
Current layout
How can I move up the blue area so that there is not whitespace, but it is still responsive and moves below the other areas on smaller screens?
Here is my HTML:
<div class="container-fluid">
<div class="row onethird">
<div class="col-sm-8 red">
<h1>Title:</h1>
<h1>Description of site</h1>
</div>
</div>
<div class="row twothirds">
<div class="col-sm-8 green">
<h2>pictures go here</h2>
</div>
<div class="col-sm-4 blue">
<h1>Signup form</h1>
<h6>Signup field</h6>
<h6>Signup field</h6>
<h6>Signup field</h6>
<h6>Signup field</h6>
</div>
</div>
Here is my CSS:
.red {
background-color: red;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
html, body {
height: 100%;
width: 100%;
}
.container-fluid {
height: 100%;
}
.row {
height: 100%;
}
.full {
height: 100%;
}
.onethird {
height: 33.333%;
}
.twothirds {
height: 66.6666%;
}
I have tried to use CSS and height percentages to set the heights of the different sections in a responsive way. My main issue is floating that blue column up.
I have considered dividing the blue section into two different rows, but this would end up dividing the sections of the signup form on smaller screens, which I'd like to avoid.
Any help would be greatly appreciated! Thanks in advance.

I think the correct way of doing this is putting everything you have on the left into .col-sm-8 and everything you have on the right into .col-sm-4.
Check out the example below.
.red {
background-color: red;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
html, body {
height: 100%;
width: 100%;
}
.container-fluid {
height: 100%;
}
.row {
height: 100%;
}
.full {
height: 100%;
}
.onethird {
height: 33.333%;
}
.twothirds {
height: 66.6666%;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row onethird">
<div class="col-sm-8">
<div class="red">
<h1>Title:</h1>
<h1>Description of site</h1>
</div>
<div class="green">
<h2>pictures go here</h2>
</div>
</div>
<div class="col-sm-4">
<div class="blue">
<h1>Signup form</h1>
<h6>Signup field</h6>
<h6>Signup field</h6>
<h6>Signup field</h6>
<h6>Signup field</h6>
</div>
</div>
</div>

You can use a different setup for your divs, stacking the lefthand elements in one div, and the blue one on the right in it's own div.
Check out this fiddle: https://jsfiddle.net/3budaekb/ (I've used different classes in lieu of bootstrap)
<div class="row">
<div class="col-sm-8>
// Lefthand side containers:
// div.red
// div.green
</div>
<div class="col-sm-4>
// right hand side element:
// div.blue
</div>
</div>

Related

Responsive table with fixed header

I want to make a responsive table that will show 2 sections a time, the labels and the values.
The labels would be fixed and the data would be a slider.
So far I have this:
[class^=col] {
float: left;
}
.row {
width: 100%;
overflow: hidden;
}
.frame {
overflow: scroll;
}
.col-6 {
width: 50%;
}
.col-12 {
width: 100%;
}
.sub-row {
border: 1px solid;
height: 30px;
}
.sub-row:first-child {
font-weight: bold;
}
<div class="row">
<div class="col-6">
<div class="sub-row"></div>
<div class="sub-row">Test1</div>
<div class="sub-row">Test2</div>
</div>
<div class="col-6">
<div class="col-12">
<div class="sub-row">Col1</div>
<div class="sub-row">bla</div>
<div class="sub-row">bla</div>
</div>
<div class="col-12">
<div class="sub-row">Col2</div>
<div class="sub-row">bla</div>
<div class="sub-row">bla</div>
</div>
</div>
</div>
But notice that the data is being displayed one below each other. I want it to be displayed side by side, hidden in the panel so I can slide it. How can I do this?
Here you can see a working example:
This is acheived using flexbox
thead, th{
display:flex;
}
http://codepen.io/dbushell/pen/wGaamR

row height is not displaying correctly

I have created an html stuff using bootstrap 2.3.2 css. The html will be having four rows with different height such as for the first row it will 10%, second row - 20%, third row - 40% and the fourth row - 40% respetively. The html is rendering but the problem is that the height of each row is not displaying correctly.
Can anyone please tell me some solution for this
My code is as given below
JSFiddle
html
<div id="content">
<div class="row1">
<div class="row-fluid">
<div class="span6">content1</div>
<div class="span6">content1</div>
</div>
</div>
<div class="row2">
<div class="row-fluid">
<div class="span6">content2</div>
<div class="span6">content2</div>
</div>
</div>
<div class="row3">
<div class="row-fluid">
<div class="span4">content3</div>
<div class="span4">content3</div>
<div class="span4">content3</div>
</div>
</div>
<div class="row4">
<div class="row-fluid">
<div class="span3">content4</div>
<div class="span3">content4</div>
<div class="span3">content4</div>
<div class="span3">content4</div>
</div>
</div>
</div>
css
.row1 {
height: 10%;
background: red;
}
.row2 {
height: 20%;
background: yellow;
}
.row3 {
height: 40%;
background: orange;
}
.row4 {
height: 40%;
background: violet;
}
#content {
height: 100%;
}
In order to use a percentage based height, all ancestors must have a defined height.
Add this to your example:
html, body {
height: 100%;
}
JSFiddle
If your elements are heavily nested, a better solution may be to use the following instead:
#content {
height: 100vh;
}
JSFiddle

Table Element Not Taking 100% Of Parent Element

I created a sample of the situation in JSFiddle
I updated JSFiddle Here: http://jsfiddle.net/x11joex11/r5spu85z/8/ (this shows in more detail how the sticky footer works so well, just height issue).
I want the table to take up the remaining height, for some reason the height: 100% is not working?
From my tests it appears to be related to min-height: 100%. I need that to make the sticky footer work.
So a solution for me is another way to do the sticky footer, or a way to still give 100% height to the elements within.
HTML
<div class="wrapper">
<div class="wrapper_content">
<!--Header-->
<div class="header">Header</div>
<div class="content table">
<div class="row">
<div class="l_cell">left</div>
<div class="r_cell">right</div>
</div>
</div>
<div class="push"></div>
</div>
</div>
<!--Footer-->
<div class="footer">Footer</div>
CSS
body, html {
margin: 0;
padding: 0;
height: 100%;
}
.wrapper {
min-height: 100%;
margin: 0 auto -50px;
background-color: black;
}
.container {
}
.table {
display: table;
height: 100%;
width: 100%;
background-color: yellow;
}
.row {
display: table-row;
}
.l_cell {
display: table-cell;
width: 265px;
background-color: orange;
}
.r_cell {
display: table-cell;
background-color: purple;
}
.header {
background-color: red;
width: 100%;
}
.footer {
height: 50px;
background-color: green;
}
.push {
height: 50px;
}
Here is one solution, http://jsfiddle.net/7t4RT/
This question has been asked many times before. I recommend viewing some of the answers already provided here at StackOverflow.
The reason that we're unable to use height: 100% in your example is because no height has defined. The CSS is wondering... well how high is 100%? There are many ways to get our elements to fill their containers in either HTML or CSS. Simply choose one you feel works better for you.
The following is one of many ways to solve this problem.
HTML:
<div class="fill-height">
<p>Filled</p>
</div>
<div class="cant-fill-height">
<p>Not Filled</p>
</div>
CSS:
body {
background-color: #ccc;
}
.fill-height {
background-color: #0ff;
width: 200px;
position: absolute;
top: 0;
bottom: 0;
}
.cant-fill-height {
background-color: #ff0;
width: 200px;
height: 100%;
margin-left: 200px;
}
I found an answer to my problem for now, but it requires the use of display:table which I recall causes other errors down the road, but it does appear to work right now to create the layout I had in mind.
http://jsfiddle.net/x11joex11/r5spu85z/10/
CSS
body,html{margin:0;padding:0;height:100%;}
.wrapper{}
.table{
height:100%;
width:100%;
display:table;
background-color:yellow;
}
.row{display:table-row;}
.cell{display:table-cell;}
.footer{background-color:green;height:50px;}
.header{background-color:red;height:30px;}
.left{background-color:purple;}
.right{background-color:orange;}
HTML
<div class="wrapper table">
<div class="header row">
Header<br/>
Header2
</div>
<div class="content table">
<div class="row">
<div class="cell left">leftt<br/>left2</div>
<div class="cell right">right<br/>right2</div>
</div>
</div>
<div class="footer row">
Footer
<br/>
Footer2
</div>
</div>
An answer not requiring the use of display:table or table tags is preferred.
Notice the sticky footer effect remains.

A better way to float text on top of an image with varying container widths

I'm redesigning a site and the different sections (header, banner image, main, etc.) have a background that stretches all the way across, however the content is contained to a certain width and that box is centered.
However, in the design the "banner image" (which is a image below the header but above the main content) will extend beyond the width of the rest of the content. At first this was easy until a need arose to have text on top of the banner image, and that text would need to line up with the rest of the text.
I cannot use CSS background image because on some pages the banner image area will be a slider, which requires tags.
I have a working solution, but it seems clunky and I was hoping to find a better method: http://jsfiddle.net/PkStg/10/
HTML:
<div class="header">
<div class="content-wrapper">
header text
</div>
</div>
<div class="banner">
<div class="content-wrapper">
<div class="banner-text-outer">
<div class="banner-text-inner">
<h2>banner text header</h2>
<p>banner text paragraph</p>
</div>
</div>
</div>
<div class="banner-image-wrapper">
<img src="http://www.brokenbowlakeguide.com/rainbow-trout-1.jpg" />
</div>
</div>
<div class="main-content">
<div class="content-wrapper">
main content text
</div>
</div>
CSS:
.header, .banner, .main-content { width: 100%; }
.header { background: red;}
.banner { background: green; }
.main-content { background: yellow; }
.content-wrapper {
margin: 0 auto;
max-width: 300px;
}
.banner-text-outer {
position: relative;
}
.banner-text-inner {
position: absolute;
top: 10px;
}
.banner-image-wrapper {
margin: 0 auto;
max-width: 400px;
min-width: 300px;
font-size: 0;
}
.banner-image-wrapper img {
width: 100%;
}
I know that you wanted to not use background-image, but here is a solution which uses that for anyone else who sees the page.
Perhaps your slider could make use of the background-image?
This should do it:
jsFiddle
HTML
<body>
<div class="header">
<div class="content-wrapper">
header text
</div>
</div>
<div class="banner">
<div class="content-wrapper">
<div class="banner-text-outer">
<div class="banner-text-inner">
<h2>banner text header</h2>
<p>banner text paragraph</p>
</div>
</div>
</div>
</div>
<div class="main-content">
<div class="content-wrapper">
main content text
</div>
</div>
</body>
CSS
.header, .banner, .main-content { width: 100%; }
.header { background: red;}
.banner { background: green; }
.main-content { background: yellow; }
.content-wrapper {
margin: 0 auto;
max-width: 300px;
}
.banner {
background: green url("http://www.brokenbowlakeguide.com/rainbow-trout-1.jpg") no-repeat;
background-size: contain;
background-position: center;
min-height: 150px;
}

What is the best way to achieve a multi-column layout in CSS and HTML?

I have a problem in HTML. I have divided the HTML page into two columns:
My code:
<div id="outer">
<div id="inner1">
<div id="data1">
</div>
<div id="response">
</div>
</div>
<div id="inner2">
<div id="data2">
</div>
</div>
</div>
My CSS:
#outer {
background-color:#FFFF99;
}
#inner1 {
float: left;
width: 62%;
}
#inner2 {
float: right;
width: 38%;
}
I need to insert another column #inner1_2 in between inner1 and inner2 which is the optional one.
There is also a third column:
<div id="#inner1_2">
</div>
The problem here is the variable division. Either I have three columns or two columns depending on the data:
inner2 is fixed
If there are three columns of data, .inner1 needs to be split into two halves, otherwise .inner1 remains as it is.
This is more complex logic than I am comfortable with in CSS.
What is the best way to handle this?
Add a class to the outer div that controls how the inner divs are displayed. Setting the class to "twoColumn" hides the middle column and setting the class to "threeColumn" shows the middle column:
<div id="outer" class="twoColumn">
<div id="inner1">
<div id="data1">
</div>
<div id="response">
</div>
</div>
<div id="inner1_2">
</div>
<div id="inner2">
<div id="data2">
</div>
</div>
</div>
css:
#outer { background-color: #FF9; }
#inner1 { float: left; }
#inner1_2 { float: left; }
#inner2 { float: left; width: 38%; }
.twoColumn #inner1 { width: 62% }
.twoColumn #inner1_2 { display: none; }
.threeColumn #inner1 { width: 31%; }
.threeColumn #inner1_2 { width: 31%; }