For example I have some kind of table:
<table>
<tr>
<th><div>Title1</div></th>
<th><div>Title2</div></th>
</tr>
<tr>
<td><div>Body1</div></td>
<td><div>Body2</div></td>
<tr>
</table>
I want every th column be resizeable, so I add some CSS:
th > div {
resize: horizontal;
overflow: hidden;
}
Everything working fine, every column can be resized horizontally.
Problem is that in every <th> I have an icon for resizing. I want it to be hidden. Is there anyway to do this?
Here are three possible solutions:
Use the ::webkit-resizer psuedo selector to style the resizer
Use a :after psuedo element to 'hide' the resizer (and add a custom cursor)
Use the :hover psuedo class to add the resize only on :hover
1. It's not cross-browser compliant, but might work for you - the ::-webkit-resizer selector. This allows some basic control over the styling of the resizer icon. We can make it transparent with the following:
(this will only work in Safari)
th > div,
td > div {
resize: horizontal;
overflow: hidden;
text-align: left;
}
td > div::-webkit-resizer {
background-color: transparent;
}
<strong>The `::-webkit-resizer` selector only works in Safari</strong>
<br/><br/>
<table>
<tr>
<th><div>Title1</div></th>
<th><div>Title2</div></th>
</tr>
<tr>
<td><div>Body1</div></td>
<td><div>Body2</div></td>
<tr>
</table>
2. As a more cross-browser solution, we can 'hide' the resizer icon behind a :after psuedo element. The idea here is to create an :after element that sits in the bottom-right corner of the td > div elements (on top of the resizer icon) with a background color that matches the table cell background color. The only remaining change is to add a small amount of padding to the right-side of the cells so the :after psuedo element doesn't also cover the cell contents.
The main advantage of this option is we can add the custom cursor you mentioned you wanted. Using the td > div:hover:after selector we can apply a cursor when the right-side of the resizable table cells is on :hover. Like this:
Like this:
th > div,
td > div {
resize: horizontal;
overflow: hidden;
text-align: left;
position: relative;
padding: 0 8px 0 0;
min-width: 45px;
}
td > div:after {
content: "";
display: block;
position: absolute;
bottom: 0px;
right: 0px;
background-color: white;
width: 8px;
height: 100%;
}
td > div:hover:after {
cursor: col-resize;
}
<table>
<tr>
<th>
<div>Title1</div>
</th>
<th>
<div>Title2</div>
</th>
</tr>
<tr>
<td>
<div>Body1</div>
</td>
<td>
<div>Body2</div>
</td>
<tr>
</table>
3. If we want the cells to be resizable, hide the resize element, and make it obvious the elements are resizable, we can use the :hover psuedo class.
Through some experimenting I found this solution works best if you use both :hover and :active pseudo classes, or the handle on the resize is lost if the cursor is dragged too quickly.
th > div {
resize: horizontal;
overflow: hidden;
text-align: left;
}
td > div {
padding-right: 10px;
min-width: 40px;
}
td > div:hover,
td > div:active {
resize: horizontal;
overflow: hidden;
}
<strong>The `::-webkit-resizer` selector only works in Safari</strong>
<br/><br/>
<table>
<tr>
<th><div>Title1</div></th>
<th><div>Title2</div></th>
</tr>
<tr>
<td><div>Body1</div></td>
<td><div>Body2</div></td>
<tr>
</table>
If you want to remove the icon from each and every td just use th > div selector.
See the example below:
If you want to play with that resize icon: Here
th > div{
resize: horizontal;
overflow: hidden;
}
<table>
<tr>
<th><div>Title1</div></th>
<th><div>Title2</div></th>
</tr>
<tr>
<td><div>Body1</div></td>
<td><div>Body2</div></td>
<tr>
</table>
Related
I have a TD with contents often wider than the TD, a text-align of right, and an overflow-x of hidden. It is displaying the leftmost portion of its contents.
Let us say for the sake of argument that the cell content is "ABCDEFGHIJKLMNOPQRSTUVWXYZ", and the TD will show exactly six characters with a hidden overflow-x.
It is now showing "ABCDEF".
How can I show "UVWXYZ"?
You can use direction: rtl.
td {
border: 1px solid black;
max-width: 70px;
overflow-x: hidden;
direction: rtl;
/*text-align: right;*/
}
<table>
<tr>
<td>ABC</td>
<td>ABCDEFGHIJKLMNOPQRSTUVWXYZ</td>
</tr>
</table>
I have a table, which is put inside a div. And this table has 4 td elements and inside each td element, there are 3 div stacked from top to bottom. My goal is to make the third div positioned at the bottom of the table. CSS below:
tr {
height: 220px;
}
td {
position: relative;
}
third-div {
text-align: center;
position: absolute:
left: 0;
right: 0;
bottom: 0;
}
html image
it works fine in firefox and chrome but bottom:0 in IE11 does not work correctly, I got a text overlay issue:(the number in the third div, which is 2000, is not set at the bottom of the table)
html rendered in IE
what is expected is:
html rendered in Chrome
I tried to set the height to auto/100%, did not work. I manually clicked bottom:0 in developer tool, it worked, 2000 went to the bottom. (not sure why).
The class name of the div in html is third-div, but you use 3rd-div in CSS and lack of a selector for the style rule. I made a demo like below and it can work well in both IE 11 and Chrome:
tr {
height: 220px;
}
td {
position: relative;
}
.third-div {
text-align: center;
position: absolute;
left: 0;
right: 0;
bottom: 0;
}
<table class="table">
<tbody>
<tr>
<td class="col-xs-3"></td>
<td class="col-xs-3"></td>
<td class="col-xs-3">
<div>Amount Financed</div>
<div>The amount of credit provided to you.</div>
<div class="third-div">
<span id="amount">$10,000</span>
</div>
</td>
<td class="col-xs-3"></td>
</tr>
</tbody>
</table>
If am working on a scheduling page that has a row for each hour of the day, and a column for each day of the week. Some cells can span multiple rows (using rowspan) if the occur for multiple hours - a typical calendar situation. Each TD contains a DIV with the event information I would like to control. Additionally, each column must have a width of 12.5% (a col for the time, and 7 for each day)
In short, I would like the div contents to use whatever space is available in the cell. If the td spans 4 rows, it should use all that space and allow wrapping to include as much of the text as will fit, but if the rowspan is only 1, then it should only display 1 line and hide anything beyond that.
I've tried most of the solutions I've found on SE and other sites, but they all interfere with the consistent column width, or with the row height.
Try this using run the code Snippet or find the JSFiddle
.demo {
table-layout: fixed;
width: 100%;
white-space: nowrap;
}
.demo td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.ID {
width: 10%;
}
.email {
width: 20%;
}
<table class="demo">
<thead>
<tr>
<th class="ID">ID</th>
<th class="email">Email<th>
</tr>
</thead>
<tbody>
<tr>
<td>0001</td>
<td>pradyumnaswain76#gmail.com</td>
</tr>
</tbody>
</table>
I think the best way here is to style the <div> you don't want to resize, because the height of the row is determined according to the content size (http://www.w3.org/TR/CSS21/tables.html#height-layout).
Try this: http://jsfiddle.net/vz3muoq8/2/
HTML
<table>
<tr><td>aaa</td><td rowspan="3">aaaaaaaaaaaaaaaaaaaaaaaaa</td></tr>
<tr><td>aaa</td></tr>
<tr><td>aaa</td></tr>
<tr><td>aaa</td><td>aaa</td></tr>
<tr><td>aaa</td><td><div>aaaaaaaaaaaaaaaaaaaaaaaaa</div></td></tr>
<tr><td>aaa</td><td>aaa</td></tr>
</table>
CSS
table {
border: 1px solid black;
table-layout: fixed;
width: 200px;
overflow: hidden;
}
th, td {
border: 1px solid black;
width: 50px;
word-wrap: break-word;
height:15px;
text-wrap: ellipsis;
}
div {
height: 15px;
overflow: hidden;
background-color: yellow;
}
Please see the following example:
http://jsfiddle.net/6t6hq/7/
when I use td with position relative to move it,
it only move the content but not the border.
How can I move the border with the content?
<table>
<tr>
<td id="relativeTD">1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
<div id="expected">expected</div>
<style>
td{
border:1px solid #000;
min-width:100px;
}
#relativeTD{
position:relative;
left:60px;
}
#expected{
border:1px solid #000;
position:relative;
left:60px;
}
</style>
TD is of display: table-cell;!
So you can't move it using relative positioning. Instead, create another <div> inside the <td> and give border and stuff.
Instead, give position: absolute for the td. It works! Also, you need to give position: relative to the table.
Fiddle: http://jsfiddle.net/6t6hq/9/
Else, you can use margin-left too to the td.
You cannot move a single td border you need to move the whole table
Demo
table {
margin-left: 60px;
}
Either what you can do is give your table border: 0;, place a div inside your td
give it some width, border and position: relative with left: 60px; and you are good to go
I have a UL with several LI's.
In these li's there are tables (1 in every li).
I use mootools to make my li's draggable / sortable.
I'll leave the JavaScript out of here though, since it's not part of the problem.
All is well, except I don't want my entire li (and thus child table) to be draggable. Just a small portion so to speak.
I then tried to 'relative and absolute' my way out of this one, but the 'hover' effect of the li remains... So when I hover my (child) table, the (parent) li always shows its: hover effect. Which it shouldn't!
<ul>
<li>
<table cellpadding="0" cellspacing="0">
<tr>
<td>...</td>
<td>foobar</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</table>
</li>
</ul>
<style>
ul {
list-style: none;
margin: 0;
padding: 0;
float: left;
}
li {
background-color: red;
width: 25px;
height: 25px;
float: left;
clear: both;
}
li:hover {
background-color: green;
cursor: move;
}
li table {
border: 1px solid #eee;
width: 850px;
position: absolute;
}
</style>
If you apply this, you'll see that the actual li is 25x25. But when you hover the table, the li turns green (just that 25x25 part)...
Only that 25x25 part should respond to the hover!
The problem is with your markup.
You have the table within (sibling of) the List item (li) therefore whatever effect/styling you apply to the li will apply to all that within it; hence why when you hover over the table the li is turning green.
When you hover over the table, which is a child of li, you trigger the :hover pseudo-class also for the li.
A solution could be to apply a class to all the li with a table inside:
<li class="withTable">
<table cellpadding="0" cellspacing="0">
<tr>
<td>...</td>
<td>foobar</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</table>
</li>
and add this rule to your CSS:
li.withTable:hover {
background-color:transparent;
cursor:default;
}
Obviously you can set another color if you want
li.withTable:hover {
background-color:blue;
cursor:default;
}