I have a td where I declare white-space:nowrap;. This prevents linebreaks in the text, but the cell size does account for the missing linebreaks and the text goes outside the td. Is there anyway to make the cell size account for white-space:nowrap;?
My code looks like this:
<tr><td style="background-color: #0C264C;color: #FFFFFF; padding: 2px; margin: 2px; white-space: nowrap;" >
<div style="float:left; text-align:left; width:50%;">Quarter</div>
<div style="float:right; text-align:right; width:50%;">Thousands of Employees</div>
</td></tr>
The tr does not extend automatically, and some of the Thousands of Employees text streches outside the table. I do not declare widths anywhere for the table.
Update
Without seeing your whole table, its hard to judge, but the combination of nowrap, floated elements, and block elements will be difficult to make it work. Those elements all have a different effect on element positioning, and pushing the bounds of the parent.
Since you are already using a table, you should use its built in cell mechanism which should properly adjust the width of the table accordingly (inline styles omitted for brevity).:
<table>
<tr>
<th>Quarter</th>
<th class="right">Thousands of Employees</th>
</tr>
....
</table>
And then put this in your css:
tr th { width: 50%; white-space: nowrap }
th.right { text-align: right }
Original Answer
If you have a fixed width on the table, and the content cannot fit within the td and not push with width of the table larger, then the contents will go outside the cell.
Try removing the width (width:auto) or using this in your css:
#idOfYourTable {
min-width: 800px; /* or whatever width you originally had set */
}
And then using width: 800px in an IE6 only stylesheet since IE6's width acts like min-width anyway. You might have to play around with some other rules as well to get IE6 to play nice.
EDIT: misunderstood your question at first.
I think you won't be able to achieve what you're looking to do without giving your containers some fixed dimensions. A hack might be to include some additional disguised element on the same line as your text, like a spacer or a white dot, forcing the container to take it into account, but that's a really nasty hack.
Space between html elements is supposed to be ignored. So what you have is a continuous block of nowrap code.
A way to get around this is to use the unicode character for Zero Width Space. This will break apart your code without introducing additional space.
<div style="float:left; text-align:left; width:50%;">Quarter</div>
<div style="float:right; text-align:right; width:50%;">Thousands of Employees</div>
If for some reason you can't use the unicode code, you might want to try the html entity which is a thin space. It will, however, introduce some additional space into your html output.
Related
Problem seems to be 'common', but among plenty of discussions I've seen I did not find nor acceptable solution nor strong reason why this not possible at all according to 'standards'.
Problem statement is
There is block in HTML whose external dimensions I can control - both width and height
Within this block I have first line with content of variable height, and I need this content to be visible completely (i.e. autosize without scrolling or clipping) ...
... and second line - it should completely take the rest of space in parent block and overflow is OK to be scrolled.
I remember it was working some time ago (when setting first TR to 1px it actually gets expanded exactly to height needed to fit the content, second TR takes the rest of height), but trying to test it now in current major browsers I see it does work only in Chrome.
So the question is - is that layout possible to be achieved within HTML5/CSS3/cross-browser standards (with or without TABLEs). As you can see on screenshot both FF and IE do not control 'correctly' (i.e. as I expect) height of the embedded DIV with 'red' background.
Below is screenshot and jsfiddle for the problem.
And sample HTML
<div style="width: 200px; height: 200px;">
<table style="height: 100%; border: 1px solid blue;">
<tr>
<td style="height: 1px; background: green; border: 1px solid magenta;">
Variable Number<br/>
Of Lines<br/>
All should be visible<br/>
</td>
</tr>
<tr>
<td style="border: 1px solid magenta;">
<div id="subject" style="height: 100%; background: red; overflow-x: hidden; overflow-y: auto">
Variable<br/>
Number<br/>
Of Lines<br/>
Overflowing <br/>
lines<br/>
Can be scrolled<br/>
...<br/>
Variable<br/>
Number<br/>
Of Lines<br/>
Overflowing <br/>
lines<br/>
Can be scrolled<br/>
...<br/>
</div>
</td>
</tr>
</table>
</div>
Yet trying to find the way to "make it work" I've got to following question, which seems to be indirectly but closely relevant -
HTML <tr> tag and position:relative. It says that TR and TD elements cannot be relatively-positioned
http://www.w3.org/TR/CSS21/visuren.html#propdef-position
The effect of 'position:relative' on table-row-group, table-header-group, table-footer-group, table-row, table-column-group, table-column, table-cell, and table-caption elements is undefined.
I guess this implies that these elements cannot create own blocks, because otherwise after setting "position: relative" on TD I would be able to absolutely position child DIV via "position: absolute; top: 0; left; 0; right: 0; bottom: 0".
...
Not sure how this co-exists with another part of 'standards' ...
http://www.w3.org/TR/CSS2/visuren.html#block-formatting
block containers (such as inline-blocks, table-cells, and table-captions) ... establish new block formatting contexts for their contents.
... in my understanding, 'block formating context' creates some container where I can set following style on single child DIV "position: absolute; top: 0; left; 0; right: 0; bottom: 0" and it will take whole content of the parent (TD in my case). This does not work too. I can't see reason behind this (most probably because nor TD not TR are relatively-positionable).
...
And the final thing - regarding %-units in height spec says
http://www.w3.org/TR/2002/WD-css3-box-20021024/#the-ltlengthgt
A 'percentage' is relative to the computed value of the width or height of the containing block, but if that value is 'auto' the computed value for the percentage is also 'auto'.
...
http://www.w3.org/TR/2002/WD-css3-box-20021024/#containing
The containing block of a normal-flow element or of a floating element is the content area of the nearest ancestor that is either a flow root or a block-level element.
In my case - after setting some fixed height on TD, 100% on child DIV is still calculated as 100% from whole table height, not TD height. Bug in FF and IE? Or am I misreading the 'standards'? ...
...
Damn ... those dummy standards make developer's life so hard ... PS: I'm now recalling - "some time ago" is back to IE5 and IE6. That case works in current IE the same way like current Chrome when switching to "IE5 quirks" mode. Now, with dummy 'standards' I've to find workaround for artificially introduced problems ...
Summary: after digging and trying to solve the problem during the day I have to admit - this is not possible to implement in a 'standards' way. I'll have to resort to JavaScript (what will cause some amount of lags and flickering :().
I want the width of a div element to be equal to the width of the content inside it, and also (and more importantly) that any content after this div does not start to the right of the div(as though the div was float:left;), but display below the current div.
I know one way is that after this div, I create another empty div and set clear:both;, but in my case that would not be very preferable.
I think that the following may be close to what you need:
The HTML demo code is:
<div>
Some text may be before the element.
<div id="info">This is my bible!</div>And some text may follow. the element.
</div>
And the CSS styles are:
#info {
display:inline;
background-color:#CFFF9F;
color:black;
font-weight:normal;
border:black solid 1px;
}
#info:after {
content:"\A";
white-space: pre;
}
Fiddle reference: http://jsfiddle.net/audetwebdesign/6FNQc/
Explanation of How This Works
Use :after to generate some content (known as a pseudo-element in CSS). The "\A" is interpreted as a line break (linefeed) provided that the white space is preserved, hence you need to set white-space: pre. Finally, the element has to be inline, hence display: inline.
Related References:
CSS to line break before/after a particular `inline-block` item
To learn more about "\A" (linefeed), see:
http://www.w3.org/TR/CSS21/syndata.html#strings
I have a single column table with multiple rows some of which have a-tag links in them, the others just plain text. I can change the height of any cells except the ones that have a-tags in them; they remain unaffected.
#table tr td{
max-height: 20px;
}
This code changes the height of all the cells to 20px except the cells that have a-tags in them. They remain around 30px or so no matter what I do. How can I get the height of those cells to change too?
Define display:block is your <a> tag because <a> an inline element. An inline element did not take width , height ,vertical margin & vertical padding
Try overflow: hidden
If that doesn't work, please post some of your markup or make a jsfiddle :)
I am trying to create a table for a website that is a fixed width, but is fixed width based on fixed width td tags, and not the entire table having a fixed width. The need for this is because I am showing and hiding some of the columns dynamically using jQuery, and using a jQuery scrolling plugin to scroll the table as it gets wider. The problem I'm running into is that when the width of the td tags makes the table wider than its containing div, the td tags start to shrink instead of maintaining their width. So far, nothing I have done has made the td tags stay the right width. You can see a jsfiddle of what I'm dealing with here:
http://jsfiddle.net/MxE9A/1/
How do I make td tags fixed width, even when they make the table wider than its container?
you can use max-width, and min-width in css to define the minimum and maximum width you want to your td's to reach to.
Haha, so I've never done it this way around, but here is a solution for you. Add the following:
tr {
font-size: 0px;
white-space: nowrap;
}
th, td {
display: inline-block;
}
Note that this will only be IE7+ compatible, but you can use tricks to get it to display correctly as inline block in IE 7.
Trick is to set them to display: inline-block so that they run off the end of the element (using white-space: nowrap).
th {
min-width:200px;
max-width:200px
}
use this for fixed width for th
How do I place the link Refresh on the middle in height of the div nav_bar?
<div id="nav_bar">
<a class="nav" id="refresh" href="#">Refresh</a>
</div>
Here is a fiddle for more help
http://jsfiddle.net/axuxT/
The easiest way is to set line-height to be the same height as the container. This will fail if you ever add more text that spans more than one line (dependent on your circumstances, you could avoid this with white-space: nowrap).
You could also add top and bottom padding, e.g. padding: 30px 0.
You could add display: table-cell and then vertical-align: middle. The only problem with this one however is that it is not supported <= IE8.
If you know the height of the parent div (eg: 35px), and you know it won't change, then you can just set line-height: 35px; on the link, and the browser's inline formatting will do the rest. I updated your fiddle to show this approach: http://jsfiddle.net/axuxT/1/.
Update
If you need the container div to be able to change size, it's a bit more complex. Here's an update to your fiddle that shows this approach: http://jsfiddle.net/axuxT/3/. Note that, in this case, the content needs to be display:block, with a known height. It also requires some additional markup - an additional wrapper div, and a floating spacer div.
It sounds like an easy thing to do, right? but there's no way that's correct, you just have to you margin-top or vertical-align or position: absolute; top: 50%; margin-top: -half-the-element-height-px'.
I hate CSS.