Twitter bootstrap grid -simulate rowspan - css

I have a grid using twitter bootstrap that we are converting from a table. Ordinarily we would consider this tabular data and just use a table but we have to (client requirements) be able to reliably print the table and given the bag of hurt printing log tables is, I'm migrating to bootstrap grids.
What I need to be able to simulate is the rowspan that we're currently using in the table.
Note I'm using a custom bootstrap with a grid of 10 cols because of size constraints
JS Fiddle of example http://jsfiddle.net/dstarh/hKjEM/
<div class="container">
<div class="row">
<div class="span1">Date</div>
<div class="span2" style="text-align:center;">Total Time</div>
<div class="span1" style="text-align:right;">Time of activity</div>
<div class="span1" style="text-align:left;">Time of Day</div>
<div class="span1" style="text-align:right;">Distance</div>
<div class="span4" style="text-align:left;">Description</div>
</div>
<div class="row">
<div class="span3">
<div class="row">
<div class="span1" style="height:100%;">01/31/2013</div>
<div class="span2" style="height:100%;">8 hours/12 miles
<hr> <span class="target-calories">
TARGET 15 miles
</span>
</div>
</div>
</div>
<div class="span7">
<div class="row">
<div class="span1" style="text-align:right;">1 hour</div>
<div class="span1" style="text-align:left;">morning</div>
<div class="span1" style="text-align:right;">3 miles</div>
<div class="span4" style="text-align:left;">ran 3 miles</div>
</div>
<div class="row">
<div class="span1" style="text-align:right;">1 hour</div>
<div class="span1" style="text-align:left;">noon</div>
<div class="span1" style="text-align:right;">2 miles</div>
<div class="span4" style="text-align:left;">walked 2 miles</div>
</div>
<div class="row">
<div class="span1 offset2" style="text-align:right;">2 miles</div>
<div class="span4" style="text-align:left;">biked 2 miles</div>
</div>
<div class="row">
<div class="span1 offset2" style="text-align:right;">4 miles</div>
<div class="span4" style="text-align:left;">ran 4 miles</div>
</div>
<div class="row">
<div class="span1" style="text-align:right;">4 miles</div>
<div class="span1" style="text-align:left;">night</div>
<div class="span1" style="text-align:right;">4 miles</div>
<div class="span4" style="text-align:left;">ran 4 miles</div>
</div>
</div>
</div>
</div>
I need the first two columns (inside the span3) to be vertically centered next to the rest of the columns/rows ). The number of rows on the right (in the span 7) is random, anywhere from 1 to likely 10-15 on the high end.

This should get you close. You do have to stretch the frame wide enough to allow responsive to do its thing. Note that vertical alignment is a challenge in itself and may require a nested table or JavaScript solution (see below).
http://jsfiddle.net/WfDUY/4/
.row {
position: relative;
}
.gray {
background-color: #eee;
height: 100%;
vertical-align: middle;
height: 100%;
position: absolute;
}
.grayer {
background-color: #ddd;
}
<div class="row">
<div class="span10">
<div class="row">
<div class="span3">I want to be Vertically Aligned in the middle</div>
<div class="span7 offset3">
...
Here's an example with the nested table solution: http://jsfiddle.net/WfDUY/6/

Related

Scrollable Card bootstrap

I am using bootstrap 4. I have 3 columns in a single row. One of the columns contains a list and the other two do not. I want only the column with the list to be scrollable but not the entire container, which means that the scrollbar muss appear only within that column.
I would appreciate any help.
<div class="row">
<div class="col-sm-4">
<div class="card">...
<div class="col-sm-4">
<div class="card">...
<div class="col-sm-4">
<div class="card">...
</div>
You could do something like this:
<div class="row">
<div class="col-sm-4">
<div class="card">...</div>
</div>
<div class="col-sm-4 scroll">
<div class="card">...</div>
</div>
<div class="col-sm-4">
<div class="card">...</div>
</div>
</div>
then in your css:
.scroll {
max-height: 100px;
overflow-y: auto;
}

How to strech the grid items in a Cartesian plane made with Bootstrap4 and Flex?

I need to implement a cartesian plane with Bootstrap 4 and Flex. The desired output is something like the following image:
The plane is composed by a 10x10 matrix. Moreover I need a row containing the x labels and a column showing the y labels.
Here you are my code:
<div class="d-flex p-2" style="border: 1px solid black; width: 40%; margin-bottom: 50px;">
<div class="d-flex flex-row">
<div class="p-2 align-items-stretch">1</div>
</div>
<div class="d-flex flex-column">
<div class="p-2">1</div>
<div class="p-2">2</div>
<div class="p-2">3</div>
<div class="p-2">4</div>
<div class="p-2">5</div>
<div class="p-2">6</div>
<div class="p-2">7</div>
<div class="p-2">8</div>
<div class="p-2">9</div>
<div class="p-2">10</div>
<div class="p-2 align-items-stretch">11</div>
</div>
<div class="d-flex flex-column">
<div class="p-2">1</div>
<div class="p-2">2</div>
<div class="p-2">3</div>
<div class="p-2">4</div>
<div class="p-2">5</div>
<div class="p-2">6</div>
<div class="p-2">7</div>
<div class="p-2">8</div>
<div class="p-2">9</div>
<div class="p-2">10</div>
</div>
<!-- the same for the other 8 rows -->
</div>
And the associated css:
.p-2 {
border: 1px solid lightgray;
}
.p-2:before {
content:'';
float:left;
padding-top:100%;
}
The actual result is:
I have two problems:
the row number 11 should be stretched until the last column;
the grid items should adapt their size according to the available space
of the container.
How I can reach these goals? Thank you
You can use the Bootstrap grid like this...
Demo: https://www.codeply.com/go/sQA6tvHiZh
<div class="container text-center">
<div class="row">
<div class="col-md-8 mx-auto">
<div class="row">
<div class="col-1">y</div>
<div class="col-11">
<div class="row">
<div class="col">1
</div>
<div class="col">2
</div>
<div class="col">3
</div>
<div class="col">4
</div>
<div class="col">5
</div>
<div class="col">6
</div>
<div class="col">7
</div>
<div class="col">8
</div>
<div class="col">9
</div>
<div class="col">10
</div>
</div>
<!--/row-->
9 more row ...
<div class="row">
<div class="col">x
</div>
</div>
</div>
</div>
</div>
</div>
<!--container-->
</div>

Bootstrap 3 two responsive rows next to each other?

I'm using Bootstrap 3 and trying to solve this what's mocked on the image. I used one row with two cols, and they are next to each other like in the image, but when I resize to mobile I want the right side to fall beneath the left. Any help is appreciated, thank you.
Code sample:
<div className="container">
<div className="row">
<div className="col-xs-4 col-offset-xs-1">
<h1>1</h1>
</div>
<div className="col-xs-4">
<div className="row">
<h1>2</h1>
</div>
</div>
.black{background-color:#000; height:320px;}
.red{background-color:#F00; height:100px;margin-bottom:10px;}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12 black">
black
</div>
</div>
</div>
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12 red">
one
</div>
</div>
<div class="row">
<div class="col-xs-12 red">
two
</div>
</div>
<div class="row">
<div class="col-xs-12 red">
three
</div>
</div>
</div>
</div>
</div>
Bootstrap allows nesting your elements easily, here you go: https://jsfiddle.net/denea/DTcHh/25594/
<div className="container">
<div class="row">
<div class="col-sm-6 col-xs-12" id="first">
<h1>1</h1>
</div>
<div class="col-sm-6 col-xs-12" id="second">
<div class="row">
<h1>2</h1>
</div>
<div class="row">
<h1>3</h1>
</div>
<div class="row">
<h1>4</h1>
</div>
</div>
</div>
and read this: http://getbootstrap.com/css/#grid-nesting
Bootstrap allows for nesting which will provide what you need:
<div class="row">
<div class="col-sm-6">
Left column
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12">
Right column, row 1
</div>
</div>
<div class="row">
<div class="col-sm-12">
Right column, row 2
</div>
</div>
<div class="row">
<div class="col-sm-12">
Right column, row 3
</div>
</div>
</div>
</div>
More info here.
You can achieve this by using flexbox and media query
#media (max-width: 360px) {
.container > .row {
display:flex;
flex-flow: row-reverse wrap;
}
}
Demo: https://jsfiddle.net/xs3joev8/1/

Bootstrap - I cannot center my five two columns inside of a ten column inside of a twelve column

I cannot center my five two columns inside of a ten column inside of a twelve column. http://jsfiddle.net/p8znkgv2/. I have tried the following "solutions" without any luck:
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-1"> </div>
<div class="col-sm-10 col-centered">
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
</div>
</div>
<div class="col-sm-1"> </div>
</div>
.col-centered{ margin: auto; float: none; }
Make the container a table and each column a table cell item ( failed )
Make the container (10 column) float none with an auto margin. ( failed on large displays )
So how can I center each two column inside the ten column with the ten column centered inside the twelve column?
So how can I center each two column inside the ten column with the ten column centered inside the twelve column?
By using .col-sm-offset-* class. Examples can be found here. http://getbootstrap.com/css/#grid-offsetting. Here's a fiddle as well. http://jsfiddle.net/yongchuc/m12cysv1/
Something like this? http://jsfiddle.net/p8znkgv2/2/
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-10 col-sm-offset-1">
<div class="col-sm-2 col-sm-offset-1">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
</div>
</div>
<div class="col-sm-1"> </div>
</div>
</div>
A lot of problems with your structure.
One is you create child div elements with those grid classes e.g. col-sm-* without adding and element with .row class first.
Html should be:
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-1"> </div>
<div class="col-sm-10 col-centered">
<div class="row">
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
</div>
</div>
<div class="col-sm-1"> </div>
</div>
</div>
</div>
</div>
And regarding to center those 5 cols, since there's no specific class for 5 cols since it's a 12 grid system, add a custom style for those elements.
e.g.
.col-centered .row .col-sm-2 {
width: 20%;
}
Fiddle

Responsive design issue in small screens - Bootstrap

I am having cards which show horizontally. Please see the image to get an idea. When I have a big header, in sm screens the cards inside the columns wrap unevenly.
<div class="col-sm-4" data-ng-repeat="card in cards">
<div class="card">
<div class="cardHeader">Big Header issue</div>
.....
</div>
</div>
How to solve this issue?
Option 1
You could use CSS ellipsis like this to append '..' to the heading when it's too long:
.cardHeader {
text-overflow:ellipsis;
white-space:nowrap;
overflow: hidden;
}
Demo: http://www.bootply.com/115420 (uses panel-heading instead)
Option 2
Another option is to use a clearfix div after every 3 'col-sm-4' div..
Demo: http://www.bootply.com/115421
Related
Bootstrap row with columns of different height
do you use the row class? something like this:
<div class ='row'>
<div class="col-sm-4">
<div class="card">
<div class="cardHeader">Big Header issue</div>
.....
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="cardHeader">Big Header issue</div>
.....
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="cardHeader">Big Header issue</div>
.....
</div>
</div>
</div>
Another option, which is slightly more HTML heavy but keeps the boxes/cards responsive:
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-4">
<div class="card biggercard">
<div class="cardHeader">Biggest Header</div>
1
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="cardHeader">Second Header</div>
2
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="cardHeader">Third</div>
3
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="cardHeader">Fourth</div>
4
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="cardHeader">5th</div>
5
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="cardHeader">6th</div>
6
</div>
</div>
</div>
</div>
</div>
</div>
Demo FIddle: http://jsfiddle.net/La3H2/

Resources