Laying out DIVs in a table-like manor in HTML - html

I'm trying to figure out how to CSS-style my DIV's in order to make a calendar view of some data.
Here is a screenshot of what I've got so far.
I'm using a table, with tr and five TD's. Inside the TD's I've added a DIV that has display: inline-block. Somewhat like this structure:
<table>
<tr>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
</tr>
<tr>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
</tr>
</table>
It looks alright as long as there is no text inside the DIV, but when I add some text the grid is skewed, as seen in the picture.
I've tried different variants of TABLE vs DIV, but I just can get it do display correctly.
Do you have any suggestions as to how I can create this calendar view?
I don't want to use a calendar-plugin, since this is a part of a more complex resource-view I'm building.

Use CSS to align the divs in a table-like way using text-align and vertical-align, making sure you give each div a separate id.
HTML
<div class="table" id="one"></div>
<div class="table" id="two"></div>
<div class="table" id="three"></div>
<div class="table" id="four"></div>
CSS
.table{
width: 45%;
height: 45%;
background-color: #efefef;
}
#one{
text-align: left;
vertical-align: top;
}
#two{
text-align: right;
vertical-align: top;
}
#three{
text-align: left;
vertical-align: bottom;
}
#four{
text-align: right;
vertical-align: bottom;
}
try that and tell me if it is insufficient.
if you have more than 9 divs, use pixels for the alignment

Related

aligning text to top in a table cell

I'm trying to get my text to align with the top of the image in the cell beside it. Vertical-align top doesn't seem to be working? I think currently it's trying to center itself relative to the other cell. Maybe there's a better way to do this with floats or something?
Here's the CSS:
table#body1 {
padding: 0px;
vertical-align: top;
margin-bottom: 10px;
margin-top: 5px;
}
td#images {
width: 30%;
}
td#text {
width: 70%;
padding-left: 15px;
text-align: justify;
vertical-align: top;
}
And the HTML: (all the divs are inline-block elements if that makes a difference)
<table id="body1">
<tr>
<td id="images"><img class="halfimg1" src="titania2.jpg" alt="Queen Titania"><br></td>
<td id="text">
<div id="header">Wander in these woods.</div><br>
This is some Text.<br>
<div id="caption"><br>This is my caption.</div>
</td>
</tr>
</table>
Thanks in advance for helping!
Add vertical-align: top; to td#images as well.
Keeping in mind the comment I made above, you probably want to move the vertical-align: top; rule from td#text to td#images
jsFiddle example

Two tables side by side, fill remaining width

I have two tables. The left table should have an auto width so that its flexible based on its contents. The right table I need to fill the remaining width of the containing div.
I understand that I can do this by setting table.b to display: block, but the problem with this is that it has no effect in IE9 and below. I need a solution that works down to IE6 (or as close as possible).
table.a {
background-color: blue;
float: left;
}
table.b {
background-color: red;
/* display: block; Can't do display block because setting table as block on <= IE 9 doesn't work */
}
<table class="a">
<tr>
<td>Hello1</td><td>Test1</td>
</tr>
</table>
<table class="b">
<tr>
<td>Hello2</td><td>This table should fill remaining width</td>
</tr>
</table>
This solution would help you,
Wrap each''s with separate ''s. Make the left table wrapper '.table1' as float left and right table wrapper '.table2' as overflow hidden. Tada!!
https://jsfiddle.net/raaj_obuli/jt71ywwm/1/
body {
margin: 0;
padding: 0;
}
.table1 {
float: left;
background: #bbb;
}
.table2 {
overflow:hidden;
background: #afa;
}
<div class="table1">
<table class="a" >
<tr>
<td>Hello1</td><td>Test1</td>
</tr>
</table>
</div>
<div class="table2">
<table class="b" width="100%">
<tr>
<td>Hello2</td><td>This table should fill remaining width</td>
</tr>
</table>
</div>
Don't put display block directly to the table just add div around the table and float the div
Try this Sample it may works for you
herehttp://codepen.io/anon/pen/jPBbrW

HTML & CSS: Can't center my tables

I'm struggling to get my 3 tables to be centered in the page.
Here's a picture of what it looks like currently:
Basically (from look at the image), I want the second/middle table ("Work" table) to be the only table in center, and the other 2 tables ("About" and "Collaborate" tables; left and right from the middle, respectively) to have spread out a bit (using margin, I would assume).
Here's my HTML:
.fixedWidth2 {
margin: 0 auto;
width: 1000px;
height: 350px;
background-color: green;
border: 2px solid yellow;
}
.tableProp1 {
width: 200px;
float: left;
margin-left: ;
}
.tableProp1 tr td {
height: 200px;
color: red;
}
.tableProp2 {
margin-left: 40px;
width: 200px;
float: left;
}
.tableProp2 tr td {
height: 200px;
color: pink;
}
.tableProp3 {
margin-left: 40px;
width: 200px;
float: left;
}
.tableProp3 tr td {
height: 200px;
color: blue;
}
<div id="mainContent">
<div class="fixedWidth2">
<table class="tableProp1" border="1">
<tr>
<th>About</th>
</tr>
<tr>
<td>Learn more about me and my accomplishments.</td>
</table>
<table class="tableProp2" border="1">
<tr>
<th>Work</th>
</tr>
<tr>
<td>I tend to get involved with a lot of different projects. Ranging from a simple photoshop gig to having a small role in a television/pilot</td>
</tr>
</table>
<table class="tableProp3" border="1">
<tr>
<th>Collaborate</th>
</tr>
<tr>
<td>Have a brand new or idea of a project? Whatever help you may need, I may be of some assistance to</td>
</tr>
</table>
</div>
<!-- Fixed Width 2 DIV for Main Content DIV -->
</div>
<!-- mainContent DIV -->
Since you are using fixed widths for your tables and you're floating them, I would wrap them in a container, set the width on that to match all three tables+margin and set margin: auto on the container
.table-wrapper{
width: 680px;
margin: auto;
}
JSFIDDLE
Alternatively you can just use display: inline-block instead of float:left and add text-align: center to .fixedWidth2
ALT FIDDLE
I would not use <table> at all... table are good for tabular content, not for templating....
I would use DIV or even HTML5's <article> and <section>.
Think also about SEO, <h2> is a better mirror to your website semantic toward search engines than table's TH ...
To center three elements you can simply set them display: inline-block; with some vertical-align, than just setting the <div class="centered"> to text-align: center; will center-align your inner elements. You can also use float:left; but I've not covered that example.
http://jsbin.com/roruqo/1/
<div id="container">
<div id="slider"></div>
<div id="mainContent">
<div class="centered">
<div class="fixedWidth2">
<h2>About</h2>
<p>Learn more about me and my accomplishm...</p>
</div>
<div class="fixedWidth2">
<h2>Work</h2>
<p>I tend to get involved with a lot of d...</p>
</div>
<div class="fixedWidth2">
<h2>Collaborate</h2>
<p>Have a brand new or idea of a project?...</p>
</div>
</div>
</div><!-- mainContent DIV -->
</div>
h2, p{
padding:15px;
margin:0;
}
#container{
width:960px;
margin:0 auto;
background:#eee;
}
#slider{
background:blue;
height:400px;
}
.centered{
text-align:center;
}
.centered > div{
text-align:left;
}
.fixedWidth2{
min-height:170px;
background:#ddd;
display:inline-block;
vertical-align:top;
width: 250px;
margin: 15px;
}
.fixedWidth2 h2{
text-align:center;
background:#aaa;
}
<div id="mainContent">
<div class="fixedWidth2">
<div class="row">
<table class="tableProp1" border="1">
<tr>
<th>About</th>
</tr>
<tr>
<td>Learn more about me and my accomplishments.</td>
</table>
<table class="tableProp2" border="1">
<tr>
<th>Work</th>
</tr>
<tr>
<td>I tend to get involved with a lot of different projects. Ranging from a simple photoshop gig to having a small role in a television/pilot</td>
</tr>
</table>
<table class="tableProp3" border="1">
<tr>
<th>Collaborate</th>
</tr>
<tr>
<td>Have a brand new or idea of a project? Whatever help you may need, I may be of some assistance to</td>
</tr>
</table>
</div>
</div>
</div>
add this style in style sheet
.row {
margin: 0 auto;
width: 680px;
}
add "row " division and apply this style then check it's working properly.

vertical-align of a TD works in HTML not CSS

Well, this worked as expected:
<td style="vertical-align: middle; text-align: center">some text</td>
(the text comes out vertically and horizontally centered), so being a nice guy I moved over the style part into a CSS like so:
HTML:
<td class="allcenter">some text</td>
CSS:
.allcenter {
vertical-align: middle;
text-align: center;
}
and you know what, it only gets horizontally centered.
What gives?
HTML
<table>
<tr>
<td class="allcenter">some text</td>
</tr>
</table>
CSS
td {
border:1px solid black;
padding : 10px;
height:100px;
width:100px;
}
.allcenter {
vertical-align: middle;
text-align: center;
}
Working Fiddle

Center image in table td in CSS

I've been trying to align an image to the center of the table td. It worked with setting margin-left to a specific value but it also increased the size of td too and that isn't exactly what I wanted
Is there any efficient ways of doing this? I used percentages for the height and witdh of the table.
<td align="center">
or via css, which is the preferred method any more...
<td style="text-align: center;">
Simple way to do it for html5 in css:
td img{
display: block;
margin-left: auto;
margin-right: auto;
}
Worked for me perfectly.
Center a div inside td using margin, the trick is to make the div width the same as the image width.
<td>
<div style="margin: 0 auto; width: 130px">
<img src="me.jpg" alt="me" style="width: 130px" />
</div>
</td>
This fixed issues for me:
<style>
.super-centered {
position:absolute;
width:100%;
height:100%;
text-align:center;
vertical-align:middle;
z-index: 9999;
}
</style>
<table class="super-centered"><tr><td style="width:100%;height:100%;" align="center" valign="middle" >
<img alt="Loading ..." src="/ALHTheme/themes/html/ALHTheme/images/loading.gif">
</td></tr></table>
Set a fixed with of your image in your css and add an auto-margin/padding on the image to...
div.image img {
width: 100px;
margin: auto;
}
Or set the text-align to center...
td {
text-align: center;
}
<table style="width:100%;">
<tbody ><tr><td align="center">
<img src="axe.JPG" />
</td>
</tr>
</tbody>
</table>
or
td
{
text-align:center;
}
in the CSS file
td image
{
display: block;
margin-left: auto;
margin-right: auto;
}
Another option is the use <th> instead of <td>. <th> defaults to center; <td> defaults to left.
As per my analysis and search on the internet also, I could not found a way to centre the image vertically centred using <div> it was possible only using <table> because table provides the following property:
valign="middle"