I have this table:
<table id="tabla">
<tbody>
<tr><th>row1</th><td>aaaa</td></tr>
<tr><th>row2</th><td>bbbb</td></tr>
<tr><th>row3</th><td>cccc</td></tr>
<figure><img src="image.png"/></figure></td></tr>
</tbody>
</table>
This organizes the information in rows... But I want to rotate it and display it in columns... I hope this is enough explanation for what I want:
How I have it now:
row1: aaaa
row2: bbbb
row3: cccc imag
How I want it:
row1 | row2 | row3
aaaa | bbbb | cccc
| imag
How can I do this with CSS?
If you are forced only to use CSS you can play with rotate :)
#table {
transform:rotate(90deg);
}
#table th, #table td{
transform:rotate(-90deg);
}
td {
height: 50px;
}
<table id="table">
<tbody>
<tr><th>row1</th><td>aaaa</td></tr>
<tr><th>row2</th><td>bbbb</td><td>bbbb</td><td>bbbb</td></tr>
<tr><th>row3</th><td>bbbb</td><td>bbbb</td><td>bbbb</td></tr>
</tbody>
</table>
Use display: flex on your tbody and set an evenly divided flex-basis on your table rows.
body {
font-size: 20px;
font-family: monospace;
}
table {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
tbody {
display: flex;
width: 800px;
position: relative;
align-items: stretch;
border: 1px solid black;
}
tr {
flex-basis: 33.33333333%;
display: flex;
flex-wrap: wrap;
align-content: flex-start;
padding: 5px 10px;
}
tr + tr {
border-left: 1px solid black;
}
th, td {
flex-basis: 100%;
text-align: left;
display: flex;
padding: 2px;
}
th {
font-weight: bold;
}
<table id="tabla">
<tbody>
<tr>
<th>row1</th>
<td>aaaa</td>
</tr>
<tr>
<th>row2</th>
<td>bbbb</td>
</tr>
<tr>
<th>row3</th>
<td>cccc</td>
<td>
<figure>
<img src="https://via.placeholder.com/150"/>
</figure>
</td>
</tr>
</tbody>
</table>
CodePen: https://codepen.io/jeffdaley/pen/WmgNRb?editors=1100
Borders might give you some trouble, but this should put you on the right track.
This probably isn't the solution you're expecting, I would really encourage you to look at the new CSS Flexible Box Model instead of using HTML tables as it'll make your life much easier in these sort of scenarios.
If you're interested, take a look at my answer for a very similar question at Vertical Menu (+ Sub-Menu) stacks unnaturally.
<table id="tabla">
<tbody>
<tr><th>row1</th><th>row2</th><th>row3</th></tr>
<tr><td>aaaa</td><td>bbbb</td><td>cccc</td></tr>
</tbody>
</table>
use this
I wonder why everybody is complicating this question. The answer is simple and clear, If you follow the right format of html table you probably wouldn`t face that problem.
<table id="tabla">
<thead>
<th class="rb">row1</th>
<th class="rb">row2</th>
<th>row3</th>
</thead>
<tbody>
<tr><td class="rb">aaaa</td><td class="rb">bbbb</td><td>cccc</td></tr>
<tr><td colspan="2" class="rb"></td><td><figure><img src="image.png"/>
</figure></td></tr>
</tbody>
</table>
.rb{
border-right: 1px solid #ccc;
}
Just simple and basic like that...
Related
I am trying to create a profile box where the user would be able to see his own profile picture, and other account specific information and utilities, like their username, settings button, profile page button, etc. The way I went about doing this was with a table element centered using flex. Then, I colored the backgrounds of my divs to see what they are doing. I noticed white lines between the cells of my table, tried some things, did some research, found the border-collapse attribute, and used it. Problem is, only some of my lines went away, as shown in the picture below. Weirder enough, it seems to disappear when I zoom in and out using ctrl + scroll. My guess is that it's some sort of rounding error.
What to do?
.Leftside2 {
flex: 20%;
background-color: red;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
}
.profile {
width: 90%;
border: 2px solid black;
display: flex;
justify-content: center;
border-collapse: collapse;
}
#profile_picture {
height: 100%;
padding: 5px;
background-color: orange;
display: flex;
justify-content: center;
}
#profile_picture img {
width: 80%;
height: 80%;
}
.friend_list {
width: 90%;
}
<div class="Leftside2">
<table class="profile">
<tr>
<td style="height: 30vh;border-width: 0px">
<div id="profile_picture"><img src="https://via.placeholder.com/450x400"></div>
</td>
</tr>
<tr>
<td style="border: 0 solid black; background-color: orange">Jill</td>
</tr>
<tr>
<td style="border-width: 0px">Eve</td>
</tr>
<tr>
<td style="border-width: 0px">John</td>
</tr>
</table>
<table class="friend_list">
<tr>
<td>Friends List</td>
</tr>
<tr>
<td>content</td>
</tr>
</table>
</div>
Edit: I tried putting cellpadding="0" and cellspacing="0" inside my and it didn't work. I also tried to explicitly state that margin = 0, padding = 0 in all table elements. I do not think that it's a margin/padding issue, as many have suggested below.
Edited code:
.profile {
width: 90%;
border: 2px solid black;
display: flex;
justify-content: center;
border-collapse: collapse;
padding: 0;
margin: 0;
}
.profile td {
padding: 0;
margin: 0;
}
Second edit:
<html lang = "en">
<head>
<link rel="stylesheet" href="../css/style.css">
<title>Find a Friend</title>
</head>
<body>
<div class="HeaderMenu">
<div style="margin-left:40px;margin-right:100px;background-color: #008aed;">
<button class="logout_button">Logout</button>
</div>
</div>
<div class="row">
<div class = "left_space"></div>
<div class="Leftside2">
<table class="profile" cellpadding="0" cellspacing="0">
<tr>
<td style="height: 30vh;border-width: 0px">
<div id="profile_picture"><img src="../img/placeholder.png"></div>
</td>
</tr>
<tr>
<td style="border: 0 solid black; background-color: orange">Jill</td>
</tr>
<tr>
<td style="border-width: 0px">Eve</td>
</tr>
<tr>
<td style="border-width: 0px">John</td>
</tr>
</table>
<table class="friend_list">
<tr>
<td>Friends List</td>
</tr>
<tr>
<td>content</td>
</tr>
</table>
</div>
<div class="Centerside2">
</div>
<div class="Rightside2">
</div>
<div class = "right_space"></div>
</div>
</body>
.profile td {
padding: 0;
}
adding this to your css should solve the problem. or you can add cellpadding="0" in your html table tag.
just adding attribute cellpadding="0" in your table tag will fix your issue.
Try adding this to your table tag:
cellspacing=“0”
Padding refers to the space inside the cell. Cell spacing is about how much space there is outside it.
I want to design table in html that would have different heights of td using only one table. Is it possible? If possible how can I get it done?
<table>
<tbody>
<td>height:30px</td>
<td>height:90px</td>
<td>height:60px</td>
<td>height:80px</td>
</tbody>
</table>
Something like this table :
<style>
tr {
height: auto;
}
td {
overflow: hidden;
display: inline-block;
white-space: nowrap;
vertical-align: top;
background-color: #3399ff;
height: 100%;
width: 75px;
border: 1px solid black;
}
td:nth-child(odd) {
background-color: #1177dd;
}
#b {
height: 200px;
}
#j {
height: 90px;
}
#k {
height: 180px;
}
</style>
<table>
<tbody>
<tr>
<td id="b">b</td>
<td id="j">j</td>
<td id="k">k</td>
</tr>
</tbody>
</table>
I suggest you take a look at rowspan. In my opinion, this is the best solution to your problem. It would take a slightly different HTML setup but should do the trick.
http://www.w3schools.com/tags/att_td_rowspan.asp
Use div inside the table td tag Or Convert all code to div instead of table
<table>
<tbody>
<td><div "height:30"></div> <div "height:40"></div> <div "height:60"> </div></td>
</tbody>
</table>
Somthing like this should do the Trick:
<td style="height: 30px"></td>
For styling anything in html you have to use the style Tag and then what you want to style,
or link to a seperate css file
I have a table using jQuery datatables with some rows in it.
Per this example, the table could look something like this:
https://jsfiddle.net/ef42942g/
I want to use CSS to change the way the table rows are shown so the final result will look something like this: https://jsfiddle.net/hamx5tas/ (please ignore the actual code)
It's very important to keep the basic table structure. I want that the change will be made entirely using CSS (if at all possible).
I have tried various changes to the tr's and td's css but with not much luck.
<table cellspacing="0" cellpadding="0" border="0">
<thead>
<tr>
<th>Thumbnail</th>
<th>Title</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img src="http://www.cmacgm-marcopolo.com/wp-content/uploads/2013/01/vignette-cargo-carnet-pratique-zeebrugge.jpg" width="100">
</td>
<td>Title 1</td>
<td>100$</td>
<td>
<button>Edit</button>
<button>Delete</button>
</td>
</tr>
<tr>
<td>
<img src="http://www.cmacgm-marcopolo.com/wp-content/uploads/2013/01/vignette-cargo-carnet-pratique-zeebrugge.jpg" width="100">
</td>
<td>Title 1</td>
<td>100$</td>
<td>
<button>Edit</button>
<button>Delete</button>
</td>
</tr>
<tr>
<td>
<img src="http://www.cmacgm-marcopolo.com/wp-content/uploads/2013/01/vignette-cargo-carnet-pratique-zeebrugge.jpg" width="100">
</td>
<td>Title 1</td>
<td>100$</td>
<td>
<button>Edit</button>
<button>Delete</button>
</td>
</tr>
</tbody>
</table>
I will appreciate any help that can be handed.
Thanks in advance.
You can adjust the layout using CSS flexbox. No changes necessary to the HTML.
CSS
thead > tr { display: none; }
tbody { display: flex; }
tbody > tr {
display: flex;
flex-direction: column;
align-items: center;
margin: 5px;
border: 1px solid black;
}
tbody > tr > td {
display: flex;
justify-content: center;
align-items: flex-start;
padding: 5px;
}
tbody > tr > td img {
width: 100px;
height: 65px;
}
tbody > tr > td:last-child {
flex-direction: row;
}
tbody > tr > td:last-child button {
margin: 5px;
}
Revised Demo
Note that flexbox is supported by all major browsers, except IE 8 & 9. Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes. For a quick way to add all the prefixes you need, use Autoprefixer. More browser compatibility details in this answer.
You can achieve what you want with pure CSS, changing the display property.
In this way, let's say that the table will not behave like a table anymore.
After that, you just have to adjust minor details to achieve your goal.
CSS:
tr {
width: 120px;
display: inline-block;
padding: 5px;
border: 1px solid black;
margin-right: 20px;
}
td {
padding: 5px;
display: block;
text-align: center;
}
Check it here: JSFiddle.
Hope it helps!
Setting the display on the td elements to block, and the display on the tr elements to inline-block gets you most of the way there.
td { padding: 5px;
border-bottom: none;
border-right:1px solid black;
display:block;}
tr{
display:inline-block;
}
thead{
display: none;
}
It sounds like you have some specific requirements for the format, so I won't go into further detail on assumptions, but from here you should be able to get what you want by turning borders on and off where needed.
https://jsfiddle.net/ef42942g/3/
I saw that Op wanted the structure unaltered so I had to go back to the drawing board. The following are the CSS changes:
Assigned display: none; to <thead>
Made the 3 tr into display: inline-table
Made all of the td to tr
Made the .main table 90vw which...
...made it easy for me to get the 3 tables symmetrical...
...some margins and padding...
...compared to the model we were provided, my table are 2px further apart, 10px wider, and 20px taller.
Fiddle
Snippet
thead {
display: none;
}
table {
width: 90vw;
}
tr {
display: inline-table;
outline: 1px solid black;
margin: 10px 5px;
}
td {
padding: 10px 15px;
display: table-row;
height: 30px;
text-align: center;
}
img {
width: 120px;
margin: 10px 15px;
}
<table cellspacing="0" cellpadding="0" border="0">
<thead>
<tr>
<th>Thumbnail</th>
<th>Title</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img src="http://www.cmacgm-marcopolo.com/wp-content/uploads/2013/01/vignette-cargo-carnet-pratique-zeebrugge.jpg" width="100">
</td>
<td>Title 1</td>
<td>100$</td>
<td>
<button>Edit</button>
<button>Delete</button>
</td>
</tr>
<tr>
<td>
<img src="http://www.cmacgm-marcopolo.com/wp-content/uploads/2013/01/vignette-cargo-carnet-pratique-zeebrugge.jpg" width="100">
</td>
<td>Title 1</td>
<td>100$</td>
<td>
<button>Edit</button>
<button>Delete</button>
</td>
</tr>
<tr>
<td>
<img src="http://www.cmacgm-marcopolo.com/wp-content/uploads/2013/01/vignette-cargo-carnet-pratique-zeebrugge.jpg" width="100">
</td>
<td>Title 1</td>
<td>100$</td>
<td>
<button>Edit</button>
<button>Delete</button>
</td>
</tr>
</tbody>
</table>
I'm a newbie regarding CSS and HTML, so apologies if this seems like a stupid question. But for the love of god, I can't seem to figure it out. I only get a horizontal scrollbar and not a vertical one.
In the code below I try to achieve that the last column, that contains the string 'aaaaaabbb...' becomes scrollable. So that when it's overfilled it starts a new line and shows a scrollbar. So I would like to see this for the last row:
Desired result:
aaaaaaaa
bbbbbbbc
cccccccc
HTML-code:
<!DOCTYPE html><html>
<head></head>
<body><head><style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
th {
text-align: left;
background-color: #eee;
}
.td_size {
width:100px;
height:200px;
max-width:100px;
min-width:100px;
max-height:200px;
min-height:2000px;
overflow:scroll;
}
</style></head><body>
<h2>Ticket details</h2>
<table>
<tr><th>Requester</th><td>^User^</td></tr>
<tr><th>Submitted by</th><td>®User®</td></tr>
<tr><th>Service</th><td>#GLOBAL END USER WORKPLACE#</td></tr>
<tr><th>CI</th><td>+N/A+</td></tr>
<tr><th>Source</th><td>#Event#</td></tr>
<tr><th>Category</th><td>&Request Fulfillment&</td></tr>
<tr><th>Impact</th><td>!None - No Degradation of Service!</td></tr>
<tr><th colspan="2" style="text-align:Center">Assignment</th></tr>
<tr><th>Group</th><td>]Team]</td></tr>
<tr><th>Staff</th><td>[User[</td></tr>
<tr><th colspan="2" style="text-align:Center">Description</th></tr>
<tr><td class="td_size">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddd</td</tr>
</table>
</body></html>
Thank you for your help.
Two things:
You have a missing ">" at the end of your closing </td>.
You only have one column in that <tr> - is that intentional? (if not you should have colspan=2 in that <td>
The solution you are looking for is word-wrap: break-word; This will allow the content to wrap.
I have modified your snippet:
<!DOCTYPE html><html>
<head></head>
<body><head><style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
th {
text-align: left;
background-color: #eee;
}
.td_size {
width:100px;
height:200px;
max-width:100px;
min-width:100px;
max-height:200px;
min-height:2000px;
overflow: auto; /* changed this */
word-wrap: break-word; /* added this */
}
</style></head><body>
<h2>Ticket details</h2>
<table>
<tr><th>Requester</th><td>^User^</td></tr>
<tr><th>Submitted by</th><td>®User®</td></tr>
<tr><th>Service</th><td>#GLOBAL END USER WORKPLACE#</td></tr>
<tr><th>CI</th><td>+N/A+</td></tr>
<tr><th>Source</th><td>#Event#</td></tr>
<tr><th>Category</th><td>&Request Fulfillment&</td></tr>
<tr><th>Impact</th><td>!None - No Degradation of Service!</td></tr>
<tr><th colspan="2" style="text-align:Center">Assignment</th></tr>
<tr><th>Group</th><td>]Team]</td></tr>
<tr><th>Staff</th><td>[User[</td></tr>
<tr><th colspan="2" style="text-align:Center">Description</th></tr>
<tr><td class="td_size" colspan=2>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddd</td></tr>
</table>
</body></html>
Like others have mentioned, in order to get the long-one-word text to wrap - you need to add: word-wrap: break-word; to the td
However, achieving a vertical scroll on a table cell is problematic because by definition table cells expand to fit all the content.
You could work around this by setting display:block on that table cell. (like this)
But it's probably better to wrap the text within a span tag so as not to mess with the display of table elements:
Like so:
FIDDLE
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
th,
td {
padding: 5px;
}
th {
text-align: left;
background-color: #eee;
}
.td_size {
width: 100px;
height: 200px;
max-width: 100px;
min-width: 100px;
}
.td_size span {
overflow: auto;
display: block;
max-height: 200px;
word-wrap: break-word;
}
<h2>Ticket details</h2>
<table>
<tr>
<th>Requester</th>
<td>^User^</td>
</tr>
<tr>
<th>Submitted by</th>
<td>®User®</td>
</tr>
<tr>
<th>Service</th>
<td>#GLOBAL END USER WORKPLACE#</td>
</tr>
<tr>
<th>CI</th>
<td>+N/A+</td>
</tr>
<tr>
<th>Source</th>
<td>#Event#</td>
</tr>
<tr>
<th>Category</th>
<td>&Request Fulfillment&</td>
</tr>
<tr>
<th>Impact</th>
<td>!None - No Degradation of Service!</td>
</tr>
<tr>
<th colspan="2" style="text-align:Center">Assignment</th>
</tr>
<tr>
<th>Group</th>
<td>]Team]</td>
</tr>
<tr>
<th>Staff</th>
<td>[User[</td>
</tr>
<tr>
<th colspan="2" style="text-align:Center">Description</th>
</tr>
<tr>
<td class="td_size"><span>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddd</span>
</td>
</tr>
</table>
First, make that last column span over 2, ie colspan=2 but as for the css part you can use overflow-x and overflow-y to determine the scrolling parts
Try it
you may use word-wrap: break-word; or <br> tag where you want to break the word
The fiddle for my code is here:
http://jsfiddle.net/wasingej/k2GPw/
I think the problem has something to do with how I specify right/left aligned divs but I'm not sure:
div.right
{
float:right;
margin-right: 2%;
border-style:solid;
}
As you can see, the fiddle produces a jumbled mess of garbage. My goal was to have the page look similar to this:
https://i.imgur.com/DVyk7s6.png
I'm fairly new to css so I'm guessing that my problem is caused by something fairly obvious. Any ideas?
Okay here's a very simple example of doing this with a table. This data appears to be tabular in nature, so while there are wonks who insist a table is NEVER okay, using a table for tabular data is appropriate.
HTML:
<table>
<thead>
<tr>
<th colspan=2>List 1 Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Owner 1 Name:</td>
<td>Owner 1 Status</td>
</tr>
<tr>
<td>Owner 2 Name:</td>
<td>Owner 2 Status</td>
</tr>
<tr>
<td>Owner 3 Name:</td>
<td>Owner 3 Status</td>
</tr>
</tbody>
</table>
CSS:
table {
border: 1px solid;
width: 50%;
padding: 2%;
border-radius: 6px;
}
td {
border: 1px solid;
padding: 1% 2%;
}
td:first-child {
text-align: right;
}
thead th {
text-align: center;
}
The fiddle: http://jsfiddle.net/BUp82/
Your issues are stemming from two things... proper handling of floats and overflows
This forked fiddle should show you your expected results: JSFIDDLE
The main bit of css that you need to add is this:
div.outer
{
//... your existing css ...
overflow: hidden;
}
I also added a 100% wide DIV around the title areas like this:
div.title { width: 100%; overflow: hidden; text-align: center; }
*my fiddle has min-height and min-width set for demonstration purposes