Truncated text in a variable-width container - html

I want to have a two-column list of items where the right column has a fixed width, and the left column is determined by the window size, with its text truncated:
+----------------------+-----------+
|Variable width text...|Fixed width|
+----------------------+-----------+
All of the examples I've found on how to do truncated text in HTML/CSS use a fixed width for the truncated text, so they don't work for my variable-width case. I usually end up with the left text not being truncated, causing the element to be wider than it should be.
I'd include sample code, but I've tried so many different things I don't know which wrong approach to post :)
This is for a WebView in a desktop application, so I only need it to work with the latest WebKit.

If you really want to text to be truncated you could do something like: http://jsfiddle.net/fju9q/2/
Which uses 2 divs. The right div is floated and the left div uses overflow: hidden and white-space: nowrap; to make sure the text is truncated.

Related

Table column header width not the same as the table body and scrollbar too big

I am working on a table that looks like this:
There are 2 issues here:
the column header IPV6 Address is taking small width than the body's column width. And Model and Type are not in place. How to fix this?
I want the scrollbar only when the table columns are not fitting the screen.
I see you're using white-space: nowrap. This might be the cause of your column width issues. Try removing this to see what it looks like multi-line, this will allow the table contents to at least attempt to use the available space properly without being forced over the space provided causing the effect with the "IPv6 Address" that you see.
Most of the time if I have fixed widths for columns (especially with nowrap) in any table I look to truncate the contents of the text within if I want everything to display on one line neatly and not wrap.
https://material.angularjs.org/1.1.2/api/directive/mdTruncate

Align divs vertically but keep order consistent

The problem is that my divs are being ordered so that the first column collapses first and is read first on mobiles (intended).
But on word-wrapping at very specific screen dimensions, the divs get out of balance and now look a little funky on their vertical balance with each other.
An image can be found here (red shows divs):
What I want is to add some space on the text that wasn't word wrapped so that
Personally, Id say the current design works well, as it can fit and change to different screen sizes, the fact that it doesnt line up is understandable as the word is just to long.
However if you wanted to you could set a min-width on the container which represents that box. This means the word wouldnt be wrapped when the screen gets smaller. But it could come with side effects as it will push over the other two divs depending on how the css works.

Why is the img tag screwing up the vertical alignment from line-height?

I'm trying to vertically align some text in a div by setting the line height equal to the div height. This works just fine when there's just text in the div, and also when there's a small image in the div. But for some reason, when there's an image beyond a certain size in the div, it starts pushing the text downward. Check out this fiddle I made to demonstrate it.
In the fiddle are 4 divs that all have height: 40px and line-height:40px. The only difference is the the 2nd, 3rd & 4th divs also have images of size small, medium and large:
.small{height:20px;}
.medium{height:30px;}
.large{height:40px;}
So why are the third fourth images messing up the vertical alignment?
You need to add vertical-align: middle to your img tag, because it's not inline element, its inline-block element.
See updated Fiddle
Note that your vertical alignment method will not work when your text will be more than 1 row. Use for alignments flexbox, there are really good things :)
There a small space below every image. By default, an image is rendered inline (actually it's inline-block), like a letter. It sits on the same line that other letters sit on. There is space below that line for the descenders you find on letters like j, p and q.
You can adjust the vertical-align of the image to position it elsewhere. In this case vertical-align: middle; would be fine.
This answer describes the issue in details: Mystery white space underneath image tag
Vertical align is one of those things they never got quite right - try googling some articles around it.
My instant reaction here is to try vertical-align:middle on each of your images - but no guarantees - I've always had to experiment and you may get varying results from different browsers.
The only all-browser answer I've found is to create a 2-column table (maybe within the div box, but not necessarily) and put text in one cell (text is automatically vertically centred in table cells) then put the matching image in the next cell (which will automatically expand to the height of the image).
Aren't tables brilliant? (some people don't think so...)

Some doubts about how to set the height of a div to prevent its contents come out from it

I have some little problem setting the right height of some informative boxes.
If you go in this example page you can simply understand what my problem is: http://onofri.org/example/example3/test2.html
As you can see under the Main Report area I have 3 boxes.
The problem occurs in the boxes titled as Links and in Work Supported by Japanese Trust Found
As you can see these boxes contain some informative text. The problem is that if I enlarge the character (in the browser, using CTRL+) this informative text goes out of the box (it goes out of the bottom of the box)
Is there a way to solve this problem? I want that box always contains its content.
Thanks in advance.
Use the min-height property to set the height. This allows the boxes to "grow" when needed.
Here's an example: http://jsfiddle.net/43MjD/4/
Don't give the div a height so the box will expand as the text does.

Text 'listens' to float element below it, not the one on the same line

In Coda, my text float divs work perfectly. The text and the divs are both 1 em:
However, once I go to look at this same site in Chrome, the text now listens to the div below it, and as you can see the text is all on one line:
What's wrong here? HTML/CSS: http://jsfiddle.net/u773M/2/
The size of your font is currently too big. Set a smaller font size on the anchor (not the list item, as that will change the size of your steps) and add set the anchor to display: block.
Without the proper space for the letters to spread out, they are just getting cut off and not rendering correctly.
Giving widths to the text area or max-width (newer browsers) and either floating or displaying these will help with cross browser implementation - I have had similar issues before and you will find ie7 likes widths on text to be set dependant on the mark-up that surrounds.