Alignment issues inside table - html

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;
}

Related

Table height 100% difference between Firefox and Chrome

I've a table inside another table in HTML/CSS - and I want the inside table be at height 100% of the surrounding table cell.
Something like that (the pink table has 100% of the height):
That works fine in Firefox - but in Chrome I get this:
The code for both is:
.largeNumber {
font-size: 10.5em;
line-height: 1;
}
.table-base {
display: table;
border-collapse: collapse;
width: auto !important;
margin: 0 auto;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
}
<div class="table-base" style="border: 1px solid black;">
<div class="table-row">
<div class="table-cell">
<span class="largeNumber">cell1 in t1</span>
</div>
<div class="table-cell" style="vertical-align: middle;height: 100%; border: 2px dashed green;">
<div class="table-base" style="border: 3px solid pink; height: 100%;">
<div class="table-row">
<div class="table-cell"><span style="color:red">cell1 in t2</span>
</div>
</div>
<div class="table-row">
<div class="table-cell"><span style="color:blue">cell2 in t2</span>
</div>
</div>
</div>
</div>
</div>
</div>
I tried to keep it simple.
But who gets it wrong? FF or Chrome? And how can I talk Chrome into drawing the inside table 100% in height?
So, you want the table with class table-base to have 100% the height of the other table, that's right?
If so, I defined the height to 100% on that class.
.largeNumber {
font-size: 10.5em;
line-height: 1;
}
.table-base {
display: table;
border-collapse: collapse;
width: auto !important;
margin: 0 auto;
height: 100%;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
}
<div class="table-base" style="border: 1px solid black;">
<div class="table-row">
<div class="table-cell">
<span class="largeNumber">cell1 in t1</span>
</div>
<div class="table-cell" style="vertical-align: middle;height: 100%; border: 2px dashed green;">
<div class="table-base" style="border: 3px solid pink; height: 100%;">
<div class="table-row">
<div class="table-cell"><span style="color:red">cell1 in t2</span>
</div>
</div>
<div class="table-row">
<div class="table-cell"><span style="color:blue">cell2 in t2</span>
</div>
</div>
</div>
</div>
</div>
</div>
Hope this helps.
Regards

Rearranging the order of cells in a table for mobile

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>

stretch a div to match it to the sum of width of 2 divs below it

I'm trying to make 3 divs align in such a way that the top div stretches to make the sum of the width of the bottom 2 divs.
Attached Image of the expected div positioning
I tried using display : table-row for the divs.
<div id="main_div" style="display: table-row">
<div id='col1' style="width: 300px; display: table-cell;">
<div style="display: table-row">
<div style="width: 300px; display: table-cell;text-align :right;border-style: groove;">
<h1>This is heading 1</h1>
</div>
</div>
<div style="display: table-row">
<div style="width: 150px; display: table-cell;white-space: nowrap;border-style: groove; border-color: green;">
abc: <input type="text" name="def">
</div>
<div style="width: 150px; display: table-cell;white-space: nowrap;border-style: groove; border-color: red">
def: <input type="text" name="ghi">
</div>
</div>
</div>
</div>
Thanks
Updated
You can also achieve this by div elements by using the float: left and display: inline-block property of css.
.row:before,.row:after{
content:"";
display:table;
}
.row:after{
clear:both;
}
.row{
border: 1px solid #000;
text-align:center;
}
.full{
width:100%;
float:left;
display:inline-block;
padding: 20px;
box-sizing:border-box;
}
.half{
width:50%;
float:left;
display:inline-block;
padding: 20px;
box-sizing:border-box;
border-top:1px solid #000;
border-right: 1px solid #000;
}
.half:last-of-type{
border-right:0;
}
<div class="row">
<div class="full">
DIV 1
</div>
<div class="half">
DIV2
</div>
<div class="half">
DIV3
</div>
</div>
The best way to achieve this layout is to use table. Please check the code below:
table{
border-spacing: 0;
border-collapse: collapse;
text-align: center;
}
td{
border: 1px solid #000;
padding:30px;
}
<table>
<tbody>
<tr>
<td colspan="2">DIV 1</td>
</tr>
<tr>
<td>DIV 2</td>
<td>DIV 3</td>
</tr>
</tbody>
</table>
Using flex from css3:
<div style="width: 300px;">
<div style="width: 100%; border: 1px solid black;">Hello</div>
<div style="width: 302px; display: flex;">
<div style="width: 50%; border: 1px solid black;">1</div>
<div style="width: 50%; border: 1px solid black;">2</div>
</div>
</div>
The 302px width is the left and right 1px borders

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>