I'm struggling with TABLE HTML.
I have no idea why this table tag doesn't work properly in browser
<table border="1">
<tbody>
<tr>
<td rowspan="2">1-1</td>
<td rowspan="3">2-1</td>
</tr>
<tr>
<td rowspan="2">1-2</td>
</tr>
<tr>
<td rowspan="3">2-2</td>
</tr>
<tr>
<td rowspan="2">1-3</td>
</tr>
</tbody>
</table>
The html above would be rendered like this
However the view I expected to see is like this
As I figured out, If I want to see what I want in browser, I should fix rowspans like this
<table border="1">
<tbody>
<tr>
<td rowspan="1">1-1</td>
<td rowspan="2">2-1</td>
</tr>
<tr>
<td rowspan="2">1-2</td>
</tr>
<tr>
<td rowspan="2">2-2</td>
</tr>
<tr>
<td rowspan="1">1-3</td>
</tr>
</tbody>
</table>
But I'm really wondering what's different and why The browser (Chrome) doesn't render the first one properly and does the second one.
According to W3C there is no way to specify float value like 1.5 for rowspan but some tweaks like below may help.
<table border="1">
<tbody>
<tr>
<td rowspan="2">1-1</td>
</tr>
<tr>
<td rowspan="2">1-2</td>
</tr>
<tr>
<td rowspan="2">2-1</td>
</tr>
<tr>
<td rowspan="3">2-2</td>
</tr>
<tr>
<td rowspan="2">3-1</td>
</tr>
</tbody>
</table>
Have you tried flexbox yet? It is little bit different approach to solve this.
#main {
width: 100px;
height: 150px;
border: 1px solid #c3c3c3;
align-items: stretch;
display: flex;
flex-flow: column wrap;
}
#main div {
width: 50px;
height: 50px;
line-height: 45px;
text-align: center;
}
#right {
width: 50px;
height: 150px;
}
#right div {
width: 50px;
height: 75px;
line-height: 70px;
text-align: center;
}
<div id="main">
<div style="background-color:lightgrey;" >1-1</div>
<div style="background-color:grey;">1-2</div>
<div style="background-color:lightgrey;">1-3</div>
<div id="right">
<div id="right" style="background-color:lightblue;">2-1</div>
<div id="right" style="background-color:lightgreen;">2-2</div>
</div>
</div>
Related
this the image I'm trying to recreate
I'm trying to place the two(2) stacked images right next to each other and also make the whole three(3) images to also align right next to the sidebar tables like in the above image, but each time I try it always goes below the sidebar table. I have tried using flexbox but it doesn't work maybe I don't know it very much. please if anyone can help. Thank you
<div class="table">
<table>
<tr>
<th class="cat">Categories</th>
</tr>
<tr>
<th>Electronics</th>
</tr>
<tr>
<th>Clothing</th>
</tr>
<tr>
<th>Music & Equipment</th>
</tr>
<tr>
<th>Footwear</th>
</tr>
<tr>
<th>Software Products</th>
</tr>
<tr>
<th>Computer Hardware</th>
</tr>
<tr>
<th>Mobile Phones</th>
</tr>
<tr>
<th>Laptops</th>
</tr>
<tr>
<th>Furniture</th>
</tr>
<tr>
<th>Beauty Products</th>
</tr>
<tr>
<th>Computer Accessories</th>
</tr>
</table>
</div>
<div class="holder">
<div class="lone-image"> </div>
<div class="stacked-image">
<div class="canon"></div>
<div class="dell"></div>
</div>
</div>
CSS Code
.table {
display: flex;
flex - flow: column;
border: 1px solid #999696;
width: 25%;
height: 60%;
box-sizing: border-box;
}
table, th, td{
border-bottom:1px solid black;
text-align: left;
padding: 10px;
}
.cat{
background-color:rgb(0, 0, 107);
color: white;
border-radius: 4px;
}
.holder{
display: flex;
justify-content: center;
align-items: center;
}
.lone-image{
background-image: url(xii.jpg);
background-size: cover;
width: 35%;
height: 410px;
}
.stacked-image{
display: flex;
flex-direction: column;
height: 400px;
width: 40%;
margin: 4px;
}
.canon{
background-size: cover;
background-image: url(canon.jpg);
width: 65%;
height: 400px;
margin-bottom: 4px;
}
.dell{
background-size: cover;
background-image: url(dell.jpg);
width: 65%;
height: 400px;
}
I came up with this.
You can play around with width's and other styling but this should give you the basic idea.
Also, using tables is a bad practice as they offer no responsiveness.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
</style>
</head>
<body>
<table>
<tr>
<td>
<div id="1table">
<table border="1">
<tr>
<th class="cat">Categories</th>
</tr>
<tr>
<th>Electronics</th>
</tr>
<tr>
<th>Clothing</th>
</tr>
<tr>
<th>Music & Equipment</th>
</tr>
<tr>
<th>Footwear</th>
</tr>
<tr>
<th>Software Products</th>
</tr>
<tr>
<th>Computer Hardware</th>
</tr>
<tr>
<th>Mobile Phones</th>
</tr>
<tr>
<th>Laptops</th>
</tr>
<tr>
<th>Furniture</th>
</tr>
<tr>
<th>Beauty Products</th>
</tr>
<tr>
<th>Computer Accessories</th>
</tr>
</table>
</div>
</td>
<td>
<table>
<tr>
<td rowspan="2"><img src="https://i.imgur.com/JeXUv8x.png" style="height:290px"></td>
<td colspan="2"><img src="https://i.imgur.com/4girMKd.png" style="height:140px"></td>
</tr>
<tr>
<td><img src="https://i.imgur.com/4girMKd.png" style="height:140px"></td>
</tr>
<tr>
</tr>
</table>
</td>
</tr>
</table>
<div class="holder">
<div class="lone-image"> </div>
<div class="stacked-image">
<div class="canon"></div>
<div class="dell"></div>
</div>
</div>
</body>
</html>
Have a great day!
I think their was some error in your width & height selection for each div. I changed that and removed a little bit of extra flex properties and thats it Just tell me you want something like this.
Proposed code
.container{
display:flex;
width:100%;
height:60%;
}
.table{
display: flex;
flex-flow: column;
border: 1px solid #999696;
width: 25%;
height: 100%;
box-sizing: border-box;
}
table, th, td{
border-bottom:1px solid black;
text-align: left;
padding: 10px;
}
.cat{
background-color:rgb(0, 0, 107);
color: white;
border-radius: 4px;
}
.holder{
width:100%;
display: flex;
flex-direction:row;
}
.lone-image{
background:blue;
width:60%;
height: 100%;
}
.stacked-image{
display: flex;
flex-direction: column;
height: 100%;
width: 40%;
}
.canon{
width: 100%;
background:green;
height:50%;
}
.dell{
background:red;
width: 100%;
height: 50%;
}
<div class="container">
<div class="table">
<table>
<tr>
<th class="cat"> Categories</th>
</tr>
<tr>
<th> Electronics</th>
</tr>
<tr>
<th>Clothing</th>
</tr>
<tr>
<th> Music & Equipment</th>
</tr>
<tr>
<th> Footwear</th>
</tr>
<tr>
<th> Software Products</th>
</tr>
<tr>
<th> Computer Hardware</th>
</tr>
<tr>
<th> Mobile Phones</th>
</tr>
<tr>
<th> Laptops</th>
</tr>
<tr>
<th> Furniture</th>
</tr>
<tr>
<th> Beauty Products</th>
</tr>
<tr>
<th> Computer Accessories</th>
</tr>
</table>
</div>
<div class="holder">
<div class="lone-image">
</div>
<div class="stacked-image">
<div class="canon"></div>
<div class="dell"></div>
</div>
</div>
</div>
You were heading in the right direction I know flexboxes are really cool but they do take a little while to hang on.
Do tell me whether I was of any Help :)
I want to create a table with stuff in it like this:
What I have right now:
<table class="table">
<td>
<tr>
<div style="width: 100px;height:100px; background-color: blue;"></div>
</tr>
<tr>
<div style="width: 100px;height:100px; background-color: red;"></div>
</tr>
</td>
<td>
<div style="width: 100px;height:200px; background-color: yellow;"></div>
</td>
</table>
Use rowspan, and td cannot be direct child of a table.
table {
border-collapse: collapse;
}
td {
width: 100px;
text-align: center;
vertical-align: middle;
}
.blue {
background-color: royalblue;
height: 100px;
}
.yellow {
background-color: yellow;
height: 200px;
}
.red {
background-color: red;
height: 100px;
}
<table>
<tr>
<td class="blue">1</td>
<td class="yellow" rowspan="2">3</td>
</tr>
<tr>
<td class="red">2</td>
</tr>
</table>
Well, firstly, your table syntax is off. It should look like this.
<table>
<tr>
<td> </td>
</tr>
</table>
Next, what you want is the first row to have two columns, with the second column taking up the space of two rows. The next row will have one column. This can be done using rowspan.
Here's your refactored code.
<table class="table">
<tr>
<td rowspan="1">
<div style="width: 100px;height:100px; background-color: blue;"></div>
</td>
<td rowspan="2">
<div style="width: 100px;height:200px; background-color: yellow;"></div>
</td>
</tr>
<tr>
<td rowspan="1">
<div style="width: 100px;height:100px; background-color: red;"></div>
</td>
</tr>
</table>
Your code must like this: use rowspan for second td
<table cellpadding="0" cellspacing="0">
<tr>
<td style="width: 100px;height:100px; background-color: blue;"></td>
<td rowspan="2" style="width: 100px;height:200px; background-color: yellow;"></td>
</tr>
<tr>
<td style="width: 100px;height:100px; background-color: red;"></td>
</tr>
</table>
</tr>
</table>
I am starting to learn HTML. In a table I created I use rowspan, but when I insert an image in a column that is expanded the image seems to not expand in the whole cell. So the rows of the table start to have different heights.
This happens in EDGE and IE but not in OPERA,Firefox etc as is shown in the images below. Column heights are not consistent there too.
Ideally, I would like to have the following heights (assuming fixed row height) for the cells identified by their content:
Headers 1 and 2: 1 column
Headers 3 and 4: 2 columns
Left image height: 4 columns
Right image height: 6 columns
body{
background-color:#FFFF99
}
img {
height: 70px;
display:block;
}
h1{
font-style: italic;
color:#3300CC;
}
table, th, td {
border: 1px solid black;
border-spacing:3px;
}
table {
width: 75%;
}
th {
padding:4px;
text-align:right;
}
td{
padding:4px;
}
.Tablestyle1{
background-color: #00CC66;
text-align: center
}
<h1>TITLE </h1>
<table>
<tr class="Tablestyle1" > <!--First Row-->
<td>A</td>
<td colspan="4">B</td>
</tr>
<tr>
<td class="Tablestyle1"rowspan="2">C</td>
<th>Header1</th>
<td> D</td>
<td rowspan="6"> <img src="https://www.w3schools.com/images/w3schools_green.jpg" alt="alt1" >
<td rowspan="6">
<ol type="I">
<li>List1</li>
<li>List2</li>
<li>List3</li>
</ol>
</tr>
<tr>
<th>Header2</th>
<td>F</td>
</tr>
<tr>
<td rowspan="4">
<img src="https://www.w3schools.com/images/w3schools_green.jpg" alt="alt2" >
</td>
<th rowspan="2">Header3</th>
<td rowspan="2">H</td>
</tr>
<tr></tr>
<tr>
<th rowspan="2">Header4</th>
<td rowspan="2">L</td>
</tr>
<tr></tr>
<tr>
<td colspan="5">
Link1
</td>
</tr>
</table>
Here is a stripped down example with inline css to explain how to style each element. The colspans and rowspans is also simplified.
This is a fixed height solution. If you want the height to be adjusted to the content, you might need some jQuery magic. Flexbox and tables won't work cross browser I think.
<table style="border-collapse: collapse; width: 75%; height: 216px;" border="1">
<tbody>
<tr style="height: 36px;">
<td style="width: 30%; height: 36px;">A</td>
<td style="width: 70%; height: 36px;" colspan="4">B</td>
</tr>
<tr style="height: 36px;">
<td style="width: 30%; height: 72px;" rowspan="2">C</td>
<td style="width: 15%; height: 36px;">1</td>
<td style="width: 10%; height: 36px;">D</td>
<td style="width: 20%; height: 144px;" rowspan="4">Image</td>
<td style="width: 25%; height: 144px;" rowspan="4">List</td>
</tr>
<tr style="height: 36px;">
<td style="width: 15%; height: 36px;">2</td>
<td style="width: 10%; height: 36px;">F</td>
</tr>
<tr style="height: 36px;">
<td style="width: 30%; height: 72px;" rowspan="2">Image</td>
<td style="width: 15%; height: 36px;">3</td>
<td style="width: 10%; height: 36px;">H</td>
</tr>
<tr style="height: 36px;">
<td style="width: 15%; height: 36px;">4</td>
<td style="width: 10%; height: 36px;">L</td>
</tr>
<tr style="height: 36px;">
<td style="width: 100%; height: 36px;" colspan="5">Link</td>
</tr>
</tbody>
</table>
If the content is too big the table could still be distorted – unless you use overflow:hidden https://stackoverflow.com/a/509825/762640
For the height, you can set height to all td's
Another option (also for the width) you can set class for every cell you want, and define the css rules for it.
You can see the example here.
https://jsfiddle.net/5upeywrd/2/
I did the rule for the header cell "A".
I would greatly appreciate help figuring this out. I'm working on a HTML table puzzle trying to match this image here:
I have everything good, make the red pillars on both sides using the rowspan tag, have the 1st, 2nd, 4th, and 5th row good, but the third row, with the three purple rectangles I just can't get to center themselves and resize to the smaller size without breaking the table.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
body { background-color:black;}
table { background-color:white;
margin: 0px auto;
width:1000px;
height:500px;}
td { width:200px;
height:100px;
}
</style>
</head>
<body>
<table border="2px solid white">
<tr>
<td bgcolor="red" rowspan="5" align="left"></td>
<td bgcolor="white"></td>
<td bgcolor="green" colspan="2" align="center" colspan="2"></td>
<td bgcolor="white"></td>
<td bgcolor="red" rowspan="5" align="right"></td>
</tr>
<tr>
<td bgcolor="blue" colspan="4"></td>
</tr>
<tr>
<td bgcolor="purple"></td>
<td bgcolor="purple"></td>
<td bgcolor="purple"></td>
</tr>
<tr>
<td bgcolor="green" colspan="4"></td>
</tr>
<tr>
<td bgcolor="purple" colspan="4"></td>
</tr>
</table>
</body>
</html>
You need more columns:
body {
background-color: black;
}
table {
background-color: white;
margin: 0px auto;
width: 1000px;
height: 500px;
border: 2px solid white;
}
td {
width: 200px;
height: 100px;
}
.red { background-color: red }
.white { background-color: white }
.green { background-color: green }
.blue { background-color: blue }
.purple { background-color: purple }
<table>
<tr>
<td class="red" rowspan="5"></td>
<td class="white" colspan="2" ></td>
<td class="green" colspan="3" ></td>
<td class="white" colspan="2" ></td>
<td class="red" rowspan="5"></td>
</tr>
<tr>
<td class="blue" colspan="7" ></td>
</tr>
<tr>
<td class="white" ></td>
<td class="purple" ></td>
<td class="white" ></td>
<td class="purple" ></td>
<td class="white" ></td>
<td class="purple" ></td>
<td class="white" ></td>
</tr>
<tr>
<td class="green" colspan="7" ></td>
</tr>
<tr>
<td class="purple" colspan="7" ></td>
</tr>
</table>
Is this some kind of homework exercise? Anyways, instead of centering your table cells, try to add white table cells. You need more columns. And you have to recalculate your colspan attributes. Good luck!
It really doesn't seem too complex.
Just draw the wanted result on squared paper and you should be able to immediately detect the correct rowspan/colspan values to use.
Just note that when writing down the HTML you need to completely skip the <td>...</td> for cells that end up in the "extension" of cells considered before in the sequence.
For example consider a simple 4 rows x 3 cols table:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
td { width:30px; height: 30px; text-align:center; }
</style>
</head>
<body>
<table border=1>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</table>
</body>
</html>
If you want to merge 1 and 2 you need to declare colspan=2 on the cell 1 and then omit cell 2. Similarily if you want to merge 5/6/8/9 you need to declare colspan=2 rowspan=2 on cell 5 and omit the merged ones:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
td { width:30px; height: 30px; text-align: center; }
</style>
</head>
<body>
<table border=1>
<tr>
<td colspan=2>12</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td colspan=2 rowspan=2>56<br/>89</td>
</tr>
<tr>
<td>7</td>
</tr>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</table>
</body>
</html>
One alternative could be flexbox. I'm not saying it's better than a table, but this could be done as follows:
See: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
While I am very fond of flexbox, a table works at least as well for this issue (though if what you wanted were to change the right ways flexbox may become a better solution).
style:
#parent {
margin: 0px;
padding: 0px;
padding-left: 20vw;
padding-right: 20vw;
background-color: red;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
-webkit-align-items: stretch;
align-items: stretch;
height: 100vh;
}
.row, .row-sm {
padding: 2px;
padding-bottom: 0px;
flex: 1;
background-color: white;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-align-items: stretch;
align-items: stretch;
}
.row:last-child {
padding-bottom: 2px;
}
.row > div {
flex: 1;
}
#centered {
-webkit-justify-content: center;
justify-content: center;
}
#centered > div {
flex: initial;
width: 40%;
background-color: #655900;
}
#sm3 {
flex: .5;
/* This would not require the spacing divs; however, the start and end gap would be half the size it should be
-webkit-justify-content: space-around;
justify-content: space-around;
*/
}
#sm3 > div {
width: 16.6666%;
background-color: white;
}
#sm3 > div:nth-child(even) {
background-color: #111155;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
.purple {
background-color: purple;
}
<div id="parent">
<div class="row" id="centered">
<div></div>
</div>
<div class="row">
<div class="blue"></div>
</div>
<div class="row" id="sm3">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="row">
<div class="green"></div>
</div>
<div class="row">
<div class="purple"></div>
</div>
</div>
NOTE: While this version scales, it could also be adjusted to have fixed content sizes; however, fixed content sizes could be done easily without flex anyway (just divs width widths/heights padding, ect).
<!DOCTYPE html>
<html>
<head>
<style>
td{
width: 75px;
height: 100px;
}
.r{
background-color: red;
}
.w{
background-color: white;
}
.g{
background-color: green;
}
.b{
background-color: blue;
}
.p{
background-color: purple;
}
</style>
</head>
<body>
<table border="0">
<tr>
<td class="r" rowspan="9" colspan="2" style="width:150px;"></td class="r">
<td class="w" rowspan="2" colspan="2"></td class="w">
<td class="g" rowspan="2" colspan="3"></td class="g">
<td class="w" rowspan="2" colspan="2"></td class="w">
<td class="r" rowspan="9" colspan="2" style="width:150px;"></td class="r">
</tr>
<tr>
</tr>
<tr>
<td class="b" rowspan="2" colspan="7"></td class="b">
</tr>
<tr>
</tr>
<tr>
<td class="w" style="height: 50px;"></td class="r">
<td class="p" style="height: 50px;"></td class="r">
<td class="w" style="height: 50px;"></td class="r">
<td class="p" style="height: 50px;"></td class="r">
<td class="w" style="height: 50px;"></td class="r">
<td class="p" style="height: 50px;"></td class="r">
<td class="w" style="height: 50px;"></td class="r">
</tr>
<tr>
<td class="g" rowspan="2" colspan="7"></td class="r">
</tr>
<tr>
</tr>
<tr>
<td class="p" rowspan="2" colspan="7"></td class="r">
</tr>
</table>
</body>
</html>
clickhere
I'm new to web development. I'm building a simple site using HTML and CSS. I have a page with 2 price lists made from tables. I have them both in one div and I want them on top of each other. There is a picture to the right of them. In firefox all is ok when I use absolute position, but in IE7 the picture pops up in between the two tables. I've tried floating right and left, positioning absolute and relative. Is it something to do with Quirks? I also changed the doctype to:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
This a bit of my code.
HTML:
<div id="price">
<table>
<tr>
<th>Cutting</th>
<th>Stylist</th>
<th>Senior Stylist</th>
</tr>
<tr>
<td>Men</td>
<td>£32</td>
<td>£35</td>
</tr>
<tr>
<td>Women</td>
<td>£36</td>
<td>£40</td>
</tr>
<tr>
<td>Restyle</td>
<td>£40</td>
<td>£45</td>
</tr>
<td colspan="3">student discount 10% Mon-Fri only</td>
</tr>
<tr>
<table>
<td>Half Head foils</td>
<td>From £55</td>
</tr>
<tr>
<td>Full Head foils</td>
<td>From £75</td>
</tr>
<tr>
<td>Colour between foils</td>
<td>From £15</td>
</tr>
</tr>
<tr>
<td>Organic Permanent colour</td>
<td>From £45</td>
</tr>
<tr>
<td>Semi-Permanent colour</td>
<td>From £40</td>
</tr>
<tr>
<td>Colour correction</td>
<td>By Quotation</td>
</tr>
</div>
<div id="pricepicture">
<img src="images/head.jpg" width="310" height="365" alt="picture of salon"/>
</div>
And CSS: (My last attempt using float)
#pricepicture {
float: right;
margin-right: 40px;
margin-top: 100px;
border: 1px solid #2c2e32;
height: 365px;
width: 310px;
}
#table {
float: left;
margin-left: 40px;
margin-top: 50px;
border-collapse: collapse;
}
#price {
float: left;
margin-left: -5px;
margin-top: 40px;
}
td {
text-align: left;
padding: 0.2em;
font-size: 1.3em;
}
th {
text-align: left;
padding: 0.2em;
font-size: 1.1em;
}
tr {
height: 20px;
}
I've been searching the Stack overflow Questions for days. Please help before I throw my laptop out of the window!
Thanks....
There are some HTML syntax errors. You must ensure that all tags are properly closed, and in the correct order. See the following.
<div id="price">
<table>
<tr>
<th>Cutting</th>
<th>Stylist</th>
<th>Senior Stylist</th>
</tr>
<tr>
<td>Men</td>
<td>£32</td>
<td>£35</td>
</tr>
<tr>
<td>Women</td>
<td>£36</td>
<td>£40</td>
</tr>
<tr>
<td>Restyle</td>
<td>£40</td>
<td>£45</td>
</tr>
<tr>
<td colspan="3">student discount 10% Mon-Fri only</td>
</tr>
</table>
<table>
<tr>
<td>Half Head foils</td>
<td>From £55</td>
</tr>
<tr>
<td>Full Head foils</td>
<td>From £75</td>
</tr>
<tr>
<td>Colour between foils</td>
<td>From £15</td>
</tr>
<tr>
<td>Organic Permanent colour</td>
<td>From £45</td>
</tr>
<tr>
<td>Semi-Permanent colour</td>
<td>From £40</td>
</tr>
<tr>
<td>Colour correction</td>
<td>By Quotation</td>
</tr>
</table>
</div>
<div id="pricepicture">
<img src="images/head.jpg" width="310" height="365" alt="picture of salon"/>
</div>