I am currently coding an accessibility page, but I am visually impaired. I've been advised that the table on this page:
http://www.accessibilityagent.com/legal/
is overlapping the adjacent content. Below is the CSS code being used. Could someone please help adjust this code to not overlap the page in the link above:
<div>
<style type="text/css">
body {
color: purple;
background-color: #d8da3d
}
table.center {
margin-left:auto;
margin-right:auto;
}
body {
text-align:center;
}
table {
width: 50%;
}
table, th, td {
border: 20px solid black;
margin: auto;
padding: 5px;
}
td.wrappable,
table.data_table td.wrappable {
white-space: normal;
}
</style>
Try setting this CSS for the table:
table-layout: fixed;
width: 100%;
word-wrap: break-word;
you need to fit the table, so set table-layout:fixed , now you need to have it fit as large as possible so change width to 100% in table, then you need to fit the links in the cell, so break the words, using word-wrap:break-word in .center a
body {
background-color: #d8da3d;
color: purple;
}
table.center {
margin-left: auto;
margin-right: auto;
table-layout: fixed;
width: 100%;
}
table,
th,
td {
border: 20px solid black;
padding: 5px;
}
.center a {
display: block;
word-wrap: break-word;
}
<table class="center">
<thead>
<tr>
<th scope="col">Year</th>
<th scope="col">Plaintiff</th>
<th scope="col">Defendant</th>
<th scope="col">Link to More Info</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">2015</td>
<td>US DOJ</td>
<td>YAKIMA COUNTY</td>
<td>http://www.ada.gov/yakima…
</td>
</tr>
</tbody>
</table>
Related
Trying to make my website responsive and want to specify #media queries for mobile phones.
I have set a wrapper on my full body on each site to centre the content.
I set a new wrapper in #media but want to move the table a little more to the left. Nothing seems to move the table though. Tried setting margin left/right and different positioning. What else could I try?
Full CSS for my #media query:
body {
background-color: #d5e6b3;
font-family: 'Raleway';
font-weight: 700;
color: #000;
background-image: url(../img/backgroundt.png);
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
}
.wrapper {
margin: 0 auto;
width: 1200px;
}
thead tr {
background-color: #a0d93f;
}
td {
padding: 12px 15px;
}
tbody tr:first-child {
background-color: #707fe0;
}
tbody tr:nth-last-of-type(even) {
background-color: #949feb;
}
tbody tr:last-child {
background-color: #707fe0;
}
#media(max-width: 500px) {
html,
body {
overflow-x: hidden;
}
body {
position: relative
}
.wrapper {
width: 200px;
}
.table {
margin-right: 50px;
}
}
<div class="wrapper">
<h1>About me</h1>
<table>
<thead>
<tr>
<th>Skills</th>
<th>Years of Experience</th>
<th>Levels of Experience</th>
</tr>
</thead>
<tbody>
<tr>
<td>HTML</td>
<td>1</td>
<td>Beginner</td>
</tr>
<tr>
<td>CSS</td>
<td>1</td>
<td>Beginner</td>
</tr>
<tr>
<td>JavaScript</td>
<td>1</td>
<td>Beginner</td>
</tbody>
</table><br>
<br>
I assume your table is 0 margin and there is no spacing on left, try to add in negative margin:
table {
margin: -5px
}
Found the answer to this.
The table did not align correctly with various px of left-margin or right-margin, neither did with margin-left: auto and margin-right: auto or padding on the left or right. However, using flex and flex-wrap to align the table head with the table body worked and centred the table for mobile devices.
The change can be seen when opening it with Web Dev tools on devices with max-width: 500px.
body {
background-color: #d5e6b3;
font-family: 'Raleway';
font-weight: 700;
color: #000;
background-image: url(../img/backgroundt.png);
background-size: cover;
background-repeat:no-repeat;
background-attachment: fixed;
}
.wrapper {
margin: 0 auto;
width: 1200px;
}
thead tr {
background-color: #a0d93f;
}
td {
padding: 12px 15px;
}
tbody tr:first-child {
background-color: #707fe0;
}
tbody tr:nth-last-of-type(even) {
background-color: #949feb;
}
tbody tr:last-child {
background-color: #707fe0;
}
#media(max-width: 500px) {
html, body {
overflow-x: hidden;
}
body {
position: relative
}
.wrapper {
width: 200px;
}
.table {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/styles.css" type="text/css">
</head>
<body>
<div class="wrapper">
<h1>About me</h1>
<table>
<thead>
<tr>
<th>Skills</th>
<th>Years of Experience</th>
<th>Levels of Experience</th>
</tr>
</thead>
<tbody>
<tr>
<td>HTML</td>
<td>1</td>
<td>Beginner</td>
</tr>
<tr>
<td>CSS</td>
<td>1</td>
<td>Beginner</td>
</tr>
<tr>
<td>JavaScript</td>
<td>1</td>
<td>Beginner</td>
</tbody>
</table><br>
<br>
</body>
</html>
I'm trying to make an entire cell of my table clickable and I've tried just about every solution I found here except whenever my table cell is finally a hyperlink, the text just will not center no matter what I do and I could use some help.
Here's my html:
table {
border-collapse: collapse;
width: 100%;
height: 100%;
text-transform: uppercase;
letter-spacing: 1px;
}
td a {
color: #333;
display: flex;
height: 100%;
width: 100%;
justify-content: center;
}
<table align="center" border="1">
<tr>
<td>home</td>
</tr>
</table>
And here's the CSS for it:
And here's a visual of what it looks like:
Sorry if this is something that's been asked and answered, I just personally couldn't find a solution on here after three days of searching. Thanks to anyone that helps!
No need to use flex here. Just set display:block to your anchor tag and add some padding for spacing.
Stack Snippet
table {
border-collapse: collapse;
width: 100%;
height: 100%;
text-transform: uppercase;
letter-spacing: 1px;
}
td a {
color: #333;
display: block;
padding: 20px;
text-align: center;
}
<table align="center" border="1">
<tr>
<td>home</td>
</tr>
</table>
use align-items: center; in anchor tag
table {
border-collapse: collapse;
width: 100%;
height: 100%;
text-transform: uppercase;
letter-spacing: 1px;
}
td a {
color: #333;
display: flex;
height: 100%;
width: 100%;
justify-content: center;
align-items: center;
}
<table align="center" border="1">
<tr>
<td>home</td>
</tr>
</table>
table {
border-collapse: collapse;
width: 100%;
height: 100%;
text-transform: uppercase;
letter-spacing: 1px;
}
td a, td a:link, td a:hover {
display:block;
color: #333;
padding:40px;
text-align:center;
justify-content:center;
}
<table align="center" border="1">
<tr>
<td>home</td>
</tr>
</table>
This should work for you. You don't need to break out the flexbox, and you don't need to make the td a width:100% height:100%. If you just set those properties for the table, the td a will stretch.
use this:
td a{text-align: justify;}
I have this:
and want this (second column using less space):
Is there a way without introducing absolute values or fixed columns? I don't mind any other hacks like wrappers or invisible columns as long as the content sizes dynamically.
HTML
table {
border-collapse: collapse;
height: 100%;
background-color: blue;
white-space: nowrap;
}
.wrapper {
width: 40%;
font-family: avenir;
height: 100vh;
}
td > div {
color: white;
background-color: darkblue;
padding: 5px;
display: inline-block;
}
td {
padding: 0px;
border: 1px dotted white;
}
.w1px {
width: 1px;
}
.h-100 {
height: 100%;
}
<div class="wrapper">
<table>
<tr>
<td class="w1px"><div>Item1</div></td>
<td><div>Item2</div></td>
<td><div>Item3</div></td>
</tr>
<tr>
<td colspan="3"><div>Item Spanning All Three Above</div></td>
</tr>
<tr>
<td colspan="2"><div>Item Spanning Two</div></td>
</tr>
<tr class="h-100">
</tr>
</table>
</div>
To format these 2 tables I have a css sheet. The top table is a filter/sort selection. The second is a scrollable data table.
div#scrollTableContainer {
width: auto;
margin: 20px; /* just for presentation purposes */
border: 1px solid black;
}
#tHeadContainer {
background: #CC3600;
color: black;
font-weight: bold;
}
#tBodyContainer {
height: 750px;
overflow-y: scroll;
}
td:first-child {
min-width: 5%; /* EDIT */
max-width: 5%;
border-left:0;
}
td:first-child + td {
min-width: 4%;
max-width: 4%;
}
td:first-child + td + td {
min-width: 4%;
max-width: 4%;
}
<div id="scrollTableContainer">
<div id="tHeadContainer">
<table border="1" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<th bgcolor="<%=bgc0%>">USED</th>
<th bgcolor="<%=bgc0%>">STATUS</th>
</tr>
</table>
</div>
<div id="tBodyContainer">
<table border="1" align="center" id="tBody" class="TableData">
<td> stuff </td>
<td> More stuff </td>
</table>
</div>
</div>
Neither of the 2 tables are aligning column wise so that the Title/Header columns do not match the tables columns below. It also shows almost the same in chrome/IE, but firefox is a complete shamble.
Im at a loss to get this right guys, any help will be appreciated.
div#scrollTableContainer {
width: auto;
margin: 20px;
/* just for presentation purposes */
}
#tHeadContainer {
background: #CC3600;
color: black;
font-weight: bold;
}
#tBodyContainer {
height: 750px;
}
th:first-child, td:first-child {
min-width: 15%;
max-width: 15%;
width: 15%;
}
td:first-child+td {
min-width: 4%;
max-width: 4%;
}
td:first-child+td+td {
min-width: 4%;
max-width: 4%;
}
<div id="scrollTableContainer">
<div id="tHeadContainer">
<table border="1" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<th bgcolor="<%=bgc0%>">USED</th>
<th bgcolor="<%=bgc0%>">STATUS</th>
</tr>
</table>
</div>
<div id="tBodyContainer">
<table border="1" align="center" width="100%" cellpadding="0" cellspacing="0">
<td> stuff </td>
<td> More stuff </td>
</table>
</div>
</div>
You want to align the columns of both table vertically right?
If that is so, I have a solution for you
I have changed your css and u missed tr in second table.
https://jsfiddle.net/9ccwkoav/
div#scrollTableContainer {
width: auto;
margin: 20px; /* just for presentation purposes */
border: 1px solid black;
}
#tHeadContainer {
background: #CC3600;
color: black;
font-weight: bold;
}
#tHeadContainer th{
width:50%;
}
#tBodyContainer {
height: 750px;
overflow-y: auto;
}
.TableData{
width:100%;
}
.TableData td{
width:50%;
}
This should do the trick. Notice that there will be a little margin because of the scroll bar of the second table, but you can easily change it by adding a tab in the first array with the width of the scrollbar. Hope it will help
#scrollTableContainer {
width : 96%;
margin : auto;
border : 1px solid #ccc;
}
#tHeadContainer {
background-color : green;
width : 100%;
}
#tBodyContainer {
width : 100%;
height : 750px;
overflow-y : scroll;
}
#tHeadContainer table, #tBodyContainer table {
border-collapse : collapse;
width : 100%;
}
td, th {
border : 1px solid black;
}
tr {
width : 100%;
}
th:first-child, td:first-child {
min-width : 15%;
max-width : 15%;
width : 15%; /* Tweak this value to change the first column width */
}
<div id="scrollTableContainer">
<div id="tHeadContainer">
<table>
<tr>
<th>USED</th>
<th>STATUS</th>
</tr>
</table>
</div>
<div id="tBodyContainer">
<table>
<tr>
<td>Stuff</td>
<td>Some other stuff</td>
</tr>
</table>
</div>
</div>
I have a page with a table, which is updated periodically. The table has a heading, followed by a number of rows. Each row has 3 fields: Player position, Player name (also a link to the player's profile), and the player's time. The table takes up the entire page width.
The html looks like this:
<table id="raceTable">
<tbody>
<tr><th colspan="3">3 Players</th></tr>
<tr><td>1st</td><td><a>Link to profile of player A</a></td><td>00:22:12</td></tr>
<tr><td>2st</td><td><a>Link to profile of player B</a></td><td>00:23:12</td></tr>
<tr><td>3st</td><td><a>Link to profile of player C</a></td><td>00:24:15</td></tr>
</tbody>
</table>
Now, I want to make the table scalable. If the user changes the width of the window, the table should be resized, the text in the middle column should be clipped when it doesn't fit.
This is the CSS I've tried:
body{
overflow: hidden;
}
table {
width:100%;
line-height: 50px;
border-collapse: collapse;
}
th {
height: 50px;
width: 100%;
background-color: magenta;
}
td {
height: 50px;
}
#raceTable {
width: 100%;
}
#raceTable > tbody > tr:not(:first-child) > td:nth-child(1) {
padding: 10px;
background-color: red;
float: left;
}
#raceTable > tbody > tr:not(:first-child) > td:nth-child(2) {
width: 100%;
background-color: gray;
}
#raceTable > tbody > tr:not(:first-child) > td:nth-child(2) > a{
display: block;
background-color: white;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
#raceTable > tbody > tr:not(:first-child) > td:nth-child(3) {
padding: 10px;
background: green;
float: right;
}
And I have a JSFiddle of it all here: http://jsfiddle.net/Gikkman/5wpts61p/17/
My question is, how do I make text-overflow: ellipsis; to work for the link text in the middle column of the table? I cannot change how the HTML of the site is structured, I can only apply CSS. Is this possible?
In table, text-overflow: ellipsis; only works with fixed table layout, normally you can just apply:
#raceTable {
table-layout: fixed;
width: 100%;
}
But it looks like you also want to have dynamic width for the columns. In that case you can wrap the <a> with a <div> to create a CSS fixed table layout structure, then apply the text overflow on it.
#raceTable td:nth-child(2) div {
display: table;
table-layout: fixed;
width: 100%;
}
#raceTable td:nth-child(2) a {
display: table-cell;
background-color: white;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
#raceTable {
line-height: 50px;
border-collapse: collapse;
width: 100%;
}
#raceTable th {
height: 50px;
background-color: magenta;
}
#raceTable td {
height: 50px;
}
#raceTable td:nth-child(1) {
padding: 10px;
background-color: red;
/* float: left; */
}
#raceTable td:nth-child(2) {
width: 100%;
background-color: gray;
}
#raceTable td:nth-child(2) div {
display: table;
table-layout: fixed;
width: 100%;
}
#raceTable td:nth-child(2) a {
display: table-cell;
background-color: white;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
#raceTable td:nth-child(3) {
padding: 10px;
background: green;
/* float: right; */
}
<table id="raceTable">
<thead>
<tr>
<th colspan="3">3 Players</th>
</tr>
</thead>
<tbody>
<tr>
<td>1st</td>
<td><div><a>Link to profile of player A, Link to profile of player A, Link to profile of player A</a></div></td>
<td>00:22:12</td>
</tr>
<tr>
<td>2st</td>
<td><div><a>Link to profile of player B</a></div></td>
<td>00:23:12</td>
</tr>
<tr>
<td>3st</td>
<td><div><a>Link to profile of player C</a></div></td>
<td>00:24:15</td>
</tr>
</tbody>
</table>
after reconsidering my comment, I would still advise to style your table with table-layout:fixed; and reset default display on a as you did, but build it with a little more table elements.
https://www.w3.org/wiki/HTML/Elements/colgroup
https://www.w3.org/WAI/UA/TS/html401/cp1001/1001-COL-COLGROUP.html
table {
width:100%;
table-layout:fixed;
line-height:50px;
}
thead {background:green;}
td {width:100%;}
col {background:gray;}
col:first-child, col:last-child {
width:4em;
background:red;
}
col:last-child {
background:cyan;
}
a { display:block;
background-color: white;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
width:100%;}
<table id="raceTable">
<colgroup>
<col/>
<col/>
<col/>
</col>
<thead>
<tr>
<th colspan="3">3 Players</th>
</tr>
</thead>
<tbody>
<tr>
<td>1st</td>
<td><a>Link to profile of player A</a></td>
<td>00:22:12</td>
</tr>
<tr>
<td>2st</td>
<td><a>Link to profile of player B</a></td>
<td>00:23:12</td>
</tr>
<tr>
<td>3st</td>
<td><a>Link to profile of player C Link to profile of player C Link to profile of player C</a></td>
<td>00:24:15</td>
</tr>
</tbody>
</table>
https://jsfiddle.net/bn2trf2o
What happens here is the colspan attribute on th and table-layout:fixed; that shares evenly the columns.
To avoid this confusion, you can use the colgroup and col tags to init each width for each columns. Size first and last , the middle will use all space left.You can use them also to set a background defaut color for each columns. it will be hidden as soon as you set a bg on any other elements(like thead does in the snippet)
edit
from your structure , a display reset on trs could do :
table,
tr {
width: 100%;
table-layout: fixed;
line-height: 50px;
border-spacing: 0;
}
tr {
display: table;
}
th {
background: magenta
}
td {
background: gray;
}
td:first-child,
td:last-child {
width: 30px;
background: red;
}
td:last-child {
background: cyan;
width: 100px;
}
a {
display: block;
background-color: white;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
<table id="raceTable">
<tbody>
<tr>
<th colspan="3">3 Players</th>
</tr>
<tr>
<td>1st</td>
<td><a>Link to profile of player A</a></td>
<td>00:22:12</td>
</tr>
<tr>
<td>2st</td>
<td><a>Link to profile of player B</a></td>
<td>00:23:12</td>
</tr>
<tr>
<td>3st</td>
<td><a>Link to profile of player C Link to profile of player C Link to profile of player C</a></td>
<td>00:24:15</td>
</tr>
</tbody>
</table>
https://jsfiddle.net/bn2trf2o/1/