This is a variation of James Donnelly's answer to a clickable link in a TD question. I found a case where his answer doesn't completely work.
Here is the example in JSFiddle
I added vertical-align to td and lots of text to Parent1.
table.coolTable td {
vertical-align:top;
...
The problem is that the empty space under Parent2 is not clickable. How do I get that part clickable too? Specifying fixed unit heights works but I don't want to constrain my table with fixed heights.
Thanks!
The easiest solution would be to add onclick event listeners and a cursor: pointer; style to the tds.
HTML
<td onClick="document.location.href='#child'">
...
</td>
CSS
table.coolTable td {
...
cursor: pointer;
}
Updated JSFiddle
Related
I'm trying to create a table of empty cells on which I'm attaching Javascript to toggle a class, so I just need to give them a height and width. The problem is when I create the table, while it has padding, I can't get it to maintain it's height. I'm trying to avoid using as when I do, it creates the mouseover of highlighting text, and multiple clicks on the box can select the text.
Looking online, empty-cells: show; comes up as the constant answer, but it doesn't seem to keep the height. I've considered doing it as a series of inline-block divs, but then borders become messy, as the borders don't collapse.
I literally just have an empty table
<table style="border-collapse: collapse; empty-cells: show;">
<tr>
<td style="height: 1.3em; padding: 4px 6px;"></td>
<td style="height: 1.3em; padding: 4px 6px;"></td>
</tr>
</table>
I feel like this is an old HTML problem, and I'm missing some simple answer.
I had seen the question that was suggested as the duplicate, but as the answer there is 5 years old, I thought there must be something more modern for addressing this problem. If there isn't, I guess the visibility trick is the way to go.
Is there a specific minimum height that you want? If so, you can do something like this:
table tr td:first-child::after {
content: "";
display: inline-block;
vertical-align: top;
min-height: 60px;
}
Source code from omelniz originally posted here: Can I use a min-height for table, tr or td?
Try this
For <th> and <td> :
th:empty::before,td:empty::before{content:'\00a0';visibility:hidden}
For <td> only :
td:empty::before{content:'\00a0';visibility:hidden}
Description:
'\00a0' is code for single space
visibility:hidden to hide that single space
Yes, this is table-based layout. It's legacy so I may or may not be able to rip out the table, nonetheless I want to understand how table alignment works anyway, hence this arguably abhorrent question.
Say I have a 3x3 table with the values 1, 2, 3, ..., 8. It ends at 8, so the last row only has 2 elements in it. I want those centered.
HTML:
<table>
<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></tr>
</table>
I would like the CSS rule tr { text-align: center } to work, but I think there's some sort of table structure rule trumping what text align would do in this case, so some other style property maybe I have to cancel.
Fiddle, including a bunch of CSS that doesn't do what I want: http://jsfiddle.net/sdqtg7kr/
If you want those bottom td elements to respect text-align: center, you could change the display of the elements from table-cell to inline-block.
Updated Example
td {
border-color: red;
border-style: solid;
border-width: thin;
display: inline-block;
}
I have the following html
<table>
<tr>
<td>
<div class="container">
<img src="http://.../baking-potato.jpg" />
</div>
</td>
</tr>
</table>
The td cell is not wrapping "perfectly" the div+img content: as you can see from this fiddle, there's a margin in the bottom of the cell, highlighted by the black background.
How can I get rid of that unwanted margin? I tried the following css properties
table{
border-spacing: 0 px;
border-collapse: collapse;
}
but nothing changed..
Thank you in advance
Add the following CSS
.container img { display:block; }
JSFiddle Updated
Reason:
This happens because an <img> is an inline element, and therefore leaves space for text characters like p and y for example, because it is inheriting the line-height
Not sure why this occours here. I have tried several things. The following CSS seems to work for me:
.container img {
margin-bottom: -5px;
}
However it's a hack and therefor not a really good practise in my opinion. But sometimes you just don't get around using hacks...
Not really related to this case, but for someone having issue with <pre> wrapperd in <td>, you may need to set margin: 0 to remove the space. This is the case I met with when using codeblock in hugo.
How to make foo invisible using CSS (CSS3 if needed) while keeping bar and fizz visible?
<table>
<tr>
<td>
<textarea>bar</textarea>
<input type='button' title='fizz' />
foo
</td>
</tr>
</tbody>
Making foo in the same color as background is acceptable, but the trick is - background is an image, hence - foo must be transparent instead of solid color.
JavaScript isn't an option either.
Changing HTML is not an option either.
Any ideas?
This worked fine in IE8 and Firefox (IE7 left little dots for words, which I guess if you set the font-color to something that blends with the background image, it might do fine. Note that this does not affect either the text-area or the input for any text in them.
td {font-size: 0;}
ADDED ON EDIT
WOW I mean, really! This worked on IE7-8, Firefox, and Safari
td {visibility: hidden}
td textarea,
td input {visibility: visible;}
As a side note, I tested this with elements wrapped in div rather than a table, I even did a div in a div and the inner div shows while other content is hidden.
Apparently, the visibility property acts on the element, and (unlike opacity) propagates to the child elements by inheritance, so that if one explicitly sets a child element visibility it no longer inherits the hidden but uses its own setting of visible and the fact that the wrapper is hidden does not matter.
EDIT: Scott's is better. Use his.
I don't think a proper solution is going to be pretty.
td {
position: relative;
left: 9001px;
}
textarea {
position: relative;
right: 9001px;
}
If you don't have to support IE then setting the text to transparent is easy:
table {
background-color: cyan;
}
td {
color: rgba(255,255,255,0);
}
td textarea, td input {
color: #000;
}
You need to put it inside a container like a div then hide the container ..
Set the size of the td to be the same as the size of the textarea (via CSS width and height), then set overflow: hidden on the TD so that the text you want to hide is outside the bounding box?
whoops... should've read the OP a bit more closely. Guess the following won't work after all, since changing the html isn't an option.
Set a css class on the container you want to hide (the textarea?):
...
<textarea class="hideme">bar</textarea>
...
and the following css:
.hideme {
display: hidden;
}
'hidden' makes the element disappear (it's literally not displayed), but still is still accounted for in the document flow and takes up the space it normally would. If you want it to literally be gone and not have any effect on the document, then use display: none.
How about the reverse of Amber's suggestion -
Set overflow to overflow: hidden on the TD, fix the size where it is right now and add a huge padding-bottom on the textarea or button.
I am creating a form in HTML that will be printed, with fields that need to be written in by the recipient. Basically what I want is a single line that stretches from the end of the field label to the side of the page. Here's how I'm doing it right now:
<table width="100%">
<tr>
<td width="1%">
Label:
</td>
<td style="border-bottom-style:solid; border-bottom-width:1px;">
</td>
</tr>
</table>
This works, but there must be an easier way to do this without needing a whole table element. Any ideas?
Here's my CSS:
span.print_underline
{
display: inline-block;
height: 1em;
border-bottom: 1px solid #000;
}
So your HTML will look like:
<span class="print_underline" style="width: 200px"> </span>
I left the width out, so I could reuse it as much as I want, but you can specify the width.
As a sidenote, I tested the same concept with a div tag instead of span tag, and it did not work in some situations. This is probably because it is semantically incorrect to put a div within a paragraph tag (which is why I used a span), and I generally use paragraph tags instead of using table rows like you've used.
I think your solution is better than the responses thus far. The only thing I'd change about your solution is that I'd use a css class instead of inline.
Your solution will have better alignment than using spans. Your code will look cleaner with table elements than with spans as well.
Also, you might want to consider putting in a textbox in your cell so that your users can input the information directly on the page before printing out.
How about using the span tag?
<span style="border-bottom....">Text</span>
just have a div with appropriate margin to the left. Block-elements by default always expand to the full width.
Meaning:
label {
float: left;
}
div {
margin-left: 10em;
border-bottom: 1px solid black;
height: 1em;
}
<label>label:</label>
<div></div>
it won't stretch the full width between the label and the right side, but you can have the label hide the bottom-border (using background-color or something) and have the div expand all the way to the right aswell (without the margin).
If you want correct semantics, you can even use an input instead of a div, set it's display to "block" and fix the borders and background.