Rearranging the order of cells in a table for mobile - html

I am trying to change the order of the cells I have in a table on #mobile screen, but haven't had any luck.
My table on Mac width is a grid with different cell sizes, colors, font sizes etc., but on Mobile I want it to be a simple list separated by horizontal lines, with a link for each item. I managed to do this, but I'd also like to change the order in which the list appears.
Tried to add divs and order it that way but it didn't work. Any advice would be most welcome!
Here's my HTML and mobile CSS:
#mobile screen CSS
.situations {
table.situ {
margin-left: 0%;
}
tr {
display: block;
color: #161616 !important;
line-height: 1 !important;
border: none;
}
#frame {
height: 100px;
width: 100%;
}
td {
/* Behave like a "row" */
display: block;
background-color: #ffffff;
border: none;
border-bottom: 0.5px solid #161616;
position: relative;
padding-left: 2%;
text-align: center;
height: 60px;
width: $fullWidth;
font-size: 14px !important;
color: #161616 !important;
padding-top: 8%;
padding-bottom: 8%;
line-height: 1 !important;
}
td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
color: #161616 !important;
line-height: 1 !important;
border: none;
}
}
<section class="situations responsiveWidth center cinch2">
<div class="table"><table class="situ" id="frame" border="0" cellspacing="0" cellpadding="0">
<tr>
<div id="situ4"><td class="product1" height="33.333%" rowspan="2"><a class="label black" href="product1.html">Text</a></td></div>
<div id="situ6"><td class="product2" height="16.666%"><a class="label black" href="product2.html">Text</a></td></div>
<div id="situ3"><td class="product3" height="50%" rowspan="3"><a class="label black" href="product3.html">Text</a></td></div>
</tr>
<tr>
<div id="situ5"><td class="product4" height="16.666%"><a class="label black" href="product4.html">Text</a></td></div>
</tr>
<tr>
<div id="situ2"><td class="product5" height="33.333%" colspan="2" rowspan="2"><a class="label black big" href="product5.html">Text</a></td></div>
</tr>
<tr>
<div id="situ7"><td class="product6" height="16.666%"><a class="label black" href="product6.html">Text</a></td></div>
</tr>
<tr>
<div id="situ8"><td class="product7" height="16.666%"><a class="label black startout" href="product7.html" id="situ8">Text</a></td></div>
<div id="situ1"><td class="product8" height="33.333%" colspan="2" rowspan="2"><a class="label white big" href="product8.html">Text</a></td></div>
</tr>
<tr>
<div id="situ9"><td class="product9" height="16.66666%"><a class="label black" href="product9.html" id="situ9">Text</a></td></div>
</tr>
</table></div>
<br>
</section>

You could consider using divs instead of a table and have a flexbox for the rows. It's than easy to change the order of the columns.
.table {
display: table;
width: 100%;
}
.row {
display: flex;
justify-content: space-between;
width: 100%;
border-bottom: thin solid lightgray;
}
.cell {
display: table-cell;
padding: 0.5em;
}
.title {
order: 2;
}
.name {
order: 1;
}
.zip {
order: 4;
}
.place {
order: 3;
}
<div class="table">
<div class="row">
<div class="cell title">Title</div>
<div class="cell name">Name</div>
<div class="cell zip">Zip</div>
<div class="cell place">Place</div>
</div>
<div class="row">
<div class="cell title">Title</div>
<div class="cell name">Name</div>
<div class="cell zip">Zip</div>
<div class="cell place">Place</div>
</div>
<div class="row">
<div class="cell title">Title</div>
<div class="cell name">Name</div>
<div class="cell zip">Zip</div>
<div class="cell place">Place</div>
</div>
</div>

Related

Div overflow does not align correct

How can I make the second line be one line and not broken up as it is now?
And look like this:
I tried to use the display: table and table-cell but it makes no difference.
I never seem to get along with CSS.
css:
<style>
.column1 {
float: left;
width: 10%;
font-size: 350%;
}
.column2 {
float: left;
width: 10%;
font-size: 350%;
}
.column3 {
float: left;
width: 80%;
font-size: 350%;
}
</style>
html:
<div class="row" style="display: table">
<div class="column1" style="background-color:#ccc;" display: table-cell;>
<b>col1</b><br>
<div style="background-color:#FF0000;">32</div>
<div style="background-color:#00FF00;">33</div>
</div>
<div class="column2" style="background-color:#ccc;" display: table-cell;>
<b>col2</b><br>
<div style="background-color:#FF0000;">11:00</div>
<div style="background-color:#00FF00;">12:00</div>
</div>
<div class="column3" style="background-color:#ccc;" display: table-cell;>
<b>col3</b><br>
<div style="background-color:#FF0000;">This is some text That will overflow the div by a few words</div>
<div style="background-color:#00FF00;">Next line</div>
</div>
If you want to use "table CSS" you might aswell adjust the markup. I made an example here
Demo here
table {
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid black;
text-align: left;
padding: 8px;
}
th {
background-color: white;
}
tr:nth-child(odd) {
background-color: #00FF00;
}
tr:nth-child(even) {
background-color: #FF0000;
}
<table>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
<tr>
<td>31</td>
<td>11:00</td>
<td>This is some text That will overflow the div by a few words</td>
</tr>
<tr>
<td>32</td>
<td>12:00</td>
<td>Next line</td>
</tr>
</table>
This is how I was able to achieve it. To achieve word wrap properly, we need to use display:table-row as well
CSS:
.column1 {
float: left;
width: 10%;
font-size: 350%; //100%
}
.column2 {
float: left;
width: 10%;
font-size: 350%; //100%
}
.column3 {
float: left;
width: 80%;
font-size: 350%; //100%
}
.row1 {
background-color:#ccc;
display: table-row;
}
.row2 {
display: table-row;
background-color:#FF0000;
}
.row3 {
display: table-row;
background-color:#00FF00;
}
HTML
<div style= "display: table;">
<div class= "row1">
<div class= "column1" style= "display:table-cell"><b>col1</b></div>
<div class= "column2" style= "display:table-cell"><b>col2</b></div>
<div class= "column3" style= "display:table-cell"><b>col3</b></div>
</div>
<div class= "row2">
<div class= "column1" style="display:table-cell">32</div>
<div class= "column2" style= "display:table-cell">11:00</div>
<div class= "column3" style= "display:table-cell">This is some text That will overflow the div by a few words</div>
</div>
<div class= "row3">
<div class= "column1" style= "display:table-cell">33</div>
<div class= "column2" style= "display:table-cell">12:00</div>
<div class= "column3" style="display:table-cell">Next line</div>
</div>
Demo Link: http://jsfiddle.net/5qc7adf9/1/show/
It will display properly only in full screen result window as font size is 350% here. To view it properly in result window of jsfiddle, we would need to reduce font-size.

How to set a div next to an image and center it vertically?

I want to know how to place an image next to a div and center the div (progress bar) vertically?
What I want to do:
Here is my code for the progress bar:
<div class="progressbar">
<div class="skill"><span>HTML 5</span></div>
</div>
.progressbar {
background-color: black;
border-radius: 25px;
padding: 3px;
width: 200px;
}
.progressbar > div {
background-color: #FDEE18;
width: 175px;
height: 20px;
border-radius: 10px;
}
.skill span {
padding-left: 10px;
}
You can do it with display: table and display:table-cell; like this :
CSS
img { height: 60px; display: table-cell; }
#container { display: table;}
.container-progress { display: table-cell; vertical-align: middle; padding-left: 10px;}
HTML
<div id="container">
<img src="http://lorempicsum.com/futurama/350/200/1" alt="">
<div class="container-progress">
<div class="progressbar">
<div class="skill"><span>HTML 5</span></div>
</div>
</div>
</div>
Live example
Try using a table for both elements:
<table>
<tr align="center">
<td align="center">
<div>
<img src="http://images3.moneysavingexpert.com/images/small-claims-court.png">
<div>
</td>
<td allign="center">
<div>
<img src="http://www.catswhocode.com/blog/wp-content/uploads/2010/10/pure-css3-progress-bar.jpg">
<div>
</td>
</tr>
</table>

Make column height same

I need your help on this. I would like to make the filter section the same as the result section. However, I am having a hard time on how to make it the same as in the results. I've also been reading the article on Equal Height Columns with Cross-Browser CSS
Below are the codes which I've done. Note that the height is dependent on the results pane or on the filters pane.
#SearchAll tr td {
vertical-align: top;
}
#SearchAllPane {
background: grey;
}
#container1 {
float: left;
border: 1px solid;
}
#container2 {
float: left;
}
#col1 {
float: left;
width: 160px;
background: white;
padding-left: 10px;
height: calc(100% - 54px);
}
#col2 {
float: left;
width: 20px;
/*background: grey;*/
}
#col2 img {
width: 18px;
height: 18px;
}
.FilterItem {
height: 30px;
line-height: 30px;
}
#ResultTable {
width: 300px;
border: 1px solid;
}
.ResultRow {
height: 30px;
line-height: 30px;
background-color: green;
font-size: 15px;
}
<table id="SearchAll">
<tr>
<td id="SearchAllPane">
<div id="container2">
<div id="container1">
<div id="col1">
<div class="FilterItem">
Filter 1
</div>
<div class="FilterItem">
Filter 1
</div>
<div class="FilterItem">
Filter 1
</div>
</div>
<div id="col2">
<img src="http://uxrepo.com/static/icon-sets/font-awesome/svg/angle-left.svg" />
</div>
</div>
</div>
</td>
<td>
<table id="ResultTable">
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
</table>
</td>
</tr>
</table>
Here's the link of what I've done: http://jsfiddle.net/arw5n4qb/
Your markup is pretty complicated, which is going to make styling it harder; here's a simple version. (Run the snippet below, or see this jsfiddle.) The important part is: one div contains the left side content, one contains the right side, and both of those are set to display: table-cell. Their parent container is set to display: table;. Sibling elements set to display: table-cell will automatically sit next to each other without wrapping. They'll also match their heights, so both will be as tall as the tallest content.
If you want the filters and rows to be vertically centered with each other, you can add vertical-align: middle to those sibling divs or to their parent. Otherwise, as you can see, they default to aligning their content along the top.
.container {
display: table; /* important */
border: 1px solid gray;
}
.filters,
.results {
display: table-cell; /* also important */
width: 200px;
}
.filters {
background: white;
}
/* the rest is cosmetic -
* change these styles if needed */
.filter, .result {
line-height: 2;
padding: 0 10px;
}
.result {
background: green;
color: white;
border: 1px solid white;
}
<div class="container">
<div class="filters">
<div class="filter">Filter 1</div>
<div class="filter">Filter 2</div>
<div class="filter">Filter 3</div>
</div>
<div class="results">
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
</div>
</div>

How to create a table with divs and different column width?

I have a table created only with divs with fixed width columns. But I need to change width of columns with bootstrap or any other way.
Html:
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="rTable">
<div class="rTableHeading">
<div class="rTableRow">
<div class="rTableHead">Title1 </div>
<div class="rTableHead">Title2 </div>
<div class="rTableHead">Title3 </div>
<div class="rTableHead">Title4 </div>
</div>
</div>
<div class="rTableBody">
<div class="rTableRow">
<div class="rTableCell">row1</div>
<div class="rTableCell">row1</div>
<div class="rTableCell">row1</div>
<div class="rTableCell">row1</div>
</div>
<div class="rTableRow">
<div class="rTableCell">row2</div>
<div class="rTableCell">row2</div>
<div class="rTableCell">row2</div>
<div class="rTableCell">row2</div>
</div>
</div>
</div>
</div>
</div>
Styles:
.rTable {
display: block;
width: 100%;
border: 1px solid #ddd;
}
.rTableHeading, .rTableBody, .rTableFoot, .rTableRow {
clear: both;
}
.rTableHead, .rTableFoot {
background-color: #FBFBFB;
font-weight: bold;
width: 100%;
padding: 0 !important;
}
.rTableCell, .rTableHead {
padding: 5px !important;
border-bottom: 1px solid #ddd;
float: left;
height: 17px;
overflow: hidden;
padding: 3px 1.8%;
width: 24%;
}
.rTableCell {
height: 46px;
}
.rTable:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
When I need 4 columns I should use width=24% for all columns. But how can I create columns with different width? Is there a way to use bootstrap column classes to do this?
You need to put your table in correctly first. Then you can resize columns as you want. I have recreated your table in html, and applied the css style to it to change the width of each column.
You should look at nth-child and nth-of-type in W3Schools sometime. Thery're very helpful.
thead th:nth-child(1) {
background: red;
width: 10%;
}
thead th:nth-child(2) {
background: pink;
width: 20%;
}
thead th:nth-child(3) {
background: purple;
width: 5%;
}
thead th:nth-child(4) {
background: green;
width: 50%;
}
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<table class="table table-striped table-hover table-condensed table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Title1</th>
<th>Title2</th>
<th>Title3</th>
<th>Title4</th>
</tr>
</thead>
<tbody>
<tr>
<td>row1</td>
<td>row1</td>
<td>row1</td>
<td>row1</td>
</tr>
<tr>
<td>row2</td>
<td>row2</td>
<td>row2</td>
<td>row2</td>
</tr>
</tbody>
</table>
</div>
</div>
Yes there is, try this. If I understand the question correctly that is. I'm not 100% sure where you want to actually add the width, but I would assume this would do what you are asking for.
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="rTable">
<div class="rTableHeading">
<div class="rTableRow">
<div class="rTableHead col-sm-3">Title1 </div>
<div class="rTableHead col-sm-3">Title2 </div>
<div class="rTableHead col-sm-3">Title3 </div>
<div class="rTableHead col-sm-3">Title4 </div>
</div>
</div>
<div class="rTableBody">
<div class="rTableRow">
<div class="rTableCell col-sm-3">row1</div>
<div class="rTableCell col-sm-3">row1</div>
<div class="rTableCell col-sm-3">row1</div>
<div class="rTableCell col-sm-3">row1</div>
</div>
<div class="rTableRow">
<div class="rTableCell col-sm-3">row2</div>
<div class="rTableCell col-sm-3">row2</div>
<div class="rTableCell col-sm-3">row2</div>
<div class="rTableCell col-sm-3">row2</div>
</div>
</div>
</div>
</div>
</div>
Also, I would take out the width% in your CSS for rTableCell if you are utilizing the bootstrap column sizing. You can still add sizing here if you would like to see how it impacts your columns. It isn't right or wrong, but first see what it looks like without the width% and then come back to add width to your liking.
.rTableCell, .rTableHead {
padding: 5px !important;
border-bottom: 1px solid #ddd;
float: left;
height: 17px;
overflow: hidden;
padding: 3px 1.8%;
/* width: 24%; */
}
Maybe there is a better solution with bootstrap but I used this approach for now.
.rTableHeading .rTableHead:nth-child(1) ,
.rTableBody .rTableCell:nth-child(1) {
width: 30%;
}
.rTableHeading .rTableHead:nth-child(2) ,
.rTableBody .rTableCell:nth-child(2) {
width: 30%;
}
.rTableHeading .rTableHead:nth-child(3) ,
.rTableBody .rTableCell:nth-child(3) {
width: 15%;
}
.rTableHeading .rTableHead:nth-child(4) ,
.rTableBody .rTableCell:nth-child(4) {
width: 20%;
}
I also cleared width=24% from rTableCell and rTableHead.

Alignment issues inside table

I have two divs which I put inside a table in order to get horizontally alignment.
<table>
<tr>
<td>
<div>
data
</div>
<div>
data
</div>
</td>
</tr>
</table>
Which looks like the following:
I now want to align these 2 in the centre, as opposed to the left.
I have tried <td style="margin-left:auto; margin-right:auto;">
but no joy.
Any idea?`
Apply the margins to the <table/>:
table {
margin: 0 auto;
}
Here is a demo fiddle.
Created a fiddle example
use align="center" for td and for div use display: inline-block;
<table style="border: 1px solid green; width: 100%; ">
<tbody><tr>
<td align="center">
<div style="border: 1px solid red;width: 30px;display: inline-block;">
data
</div>
<div style="border: 1px solid red;width: 30px;display: inline-block;">
data
</div>
</td>
<div id="containerdiv">
<div id="coveringdiv">
<div id="firstdiv">
<div id="yourdata">
Your Data Here
</div>
<div id="yourvalue">
Value
</div>
</div>
<div id="seconddiv">
<div id="yourdata">
Your Data Second
</div>
<div id="yourvalue">
values2
</div>
</div>
</div>
</div>
and CSS:
body
{
background-color: #123456;
}
#coveringdiv
{
border: solid 1px #FFFFFF;
height: 200px;
margin: 0 auto;
width: 100%;
text-align: center;
}
#firstdiv
{
display: inline-block;
}
#yourdata
{
color: #FFFFFF;
font-size: 10px;
}
#yourvalue
{
color: #FFFFFF;
font-size: 24px;
}
#seconddiv
{
display: inline-block;
}