I'm currently trying to make a text box with hiding overflowing text. It works fine, but for some part. I'm using
text-overflow: ellipsis;
This should put three dots ("...") at the place where my text is cut off, but it doesn't place three dots, instead it places the character which looks like three dots (called 'ellipsis').
The font I'm currently using doesn't have this character, so it shows some other random character instead of three dots.
Does anyone have a simple workaround (no javascript involved please, only CSS), while keeping my font for the text ?
To completely imitate the functionality of text-overflow: ellipsis without using JavaScript while still having complete browser support (text-overflow: "..." only works in Firefox 9 in the time of this post, and is completely unavailable on any other browser) is extremely difficult (if not impossible).
The only solution I can think of without any "hacks" is to edit your font file, creating a unicode character for the ... ellipsis character. I have next to no experience in this area, but here's a link that seems pretty good: http://sourceforge.net/projects/ttfedit/
Here's some HTML code I've got:
<div id="wrapoff">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vehicula, augue id pretium euismod, nisi dolor sodales orci, non porttitor ligula velit ac lorem.
</div>
And some CSS:
#wrapoff {
width: 200px;
border: 2px solid blue;
white-space: nowrap;
overflow: hidden;
position: relative;
}
#wrapoff:after {
content: "...";
position: absolute;
right: 0;
top: 0;
background-color: white;
padding: 0 5px;
}
This adds a pseudo-element on top of the #wrapoff div, at the top right hand corner, allowing the content to work like text-overflow: ellipsis. The downside to this is that the "ellipsis" always shows there, regardless of whether the content actually extends off and overflows. This cannot be fixed, as there is no way using CSS to figure out whether the text overflows off the page.
Here's a JSFiddle:
http://jsfiddle.net/ysoxyuje/
The border is to show you the size of the element itself.
Make sure you have
white-space: nowrap;
overflow: hidden;
with your
text-overflow: ellipsis;
http://jsfiddle.net/cbppL/707/
HTML
<header>
<h1>Long text is so long oh my is long indeed</h1>
</header>
CSS
header {
border:1px solid red;
width:150px;
position:relative;
}
h1 {
overflow:hidden;
white-space:nowrap;
/* -ms-text-overflow:ellipsis; */
/* text-overflow:ellipsis; */
width:150px;
height:1.2em;
}
header:after{
content:"...";
position:absolute;
top:0;
right:0;
background:#fff;
}
h1:hover {
overflow:visible;
}
Not a very good solution. It will depend on what kind of background you have. Hope Helps!
Instead of "ellipsis", you can actually specify your own set of characters to signify text overflowing.
If your custom font has the period defined, you should be able to just use three periods like this:
text-overflow: '...';
Here's a JSFiddle of it in action: http://jsfiddle.net/x5e6yv21/
From what I understand you're problem is that, in the font you're using, you're missing the ellipsis character.
To quickly fix this you could select this last-letter with the ::last-letter pseudo-element selectorand change the font-family property to another font that supports ellipsis _
So, I know this isn't ideal but it is a work-around. The CSS3 specification says that the ellipsis must take their style from the container that they're in. This works correctly in all browsers except IE8/9 which takes it's ellipsis style from the first letter of the container. The work-around I propose is to wrap the text inside of your "overflowed" elements with an inline element, give the outer container a font where the ellipsis character is defined and give the inline element inside your custom font. It would look something like this fiddle: http://jsfiddle.net/u9dudost/2/
If you need to add IE8/9 support, add the following:
div {
white-space: nowrap;
}
div::before {
font-family: 'Helvetica', sans-serif; /* Your custom font here. */
content: ''; /* IE9 fix */
}
You need to use the following together:
white-space: nowrap;
text-overflow: ellipsis;
Related
This is the example:
<style>
div {
background-color: skyblue;
height: 100px;
}
.posttext {
word-wrap: break-word;
-ms-hyphenate-limit-lines: 10;
text-overflow: ellipsis;
}
</style>
<div>
<p class="posttext">---------0---------1---------2---------3---------4---------5---------6---------7---------8---------9---------0---------1---------2---------3---------4---------5---------6---------7---------8---------9---------0---------1---------2---------3---------4---------5---------6---------7---------8---------9---------0---------1---------2---------3---------4---------5---------6---------7---------8---------9---------0---------1---------2---------3---------4---------5---------6---------7---------8---------9---------0---------1---------2---------3---------4---------5---------6---------7---------8---------9---------0---------1---------2---------3---------4---------5---------6---------7---------8---------9---------0---------1---------2---------3---------4---------5---------6---------7---------8--------</p>
</div>
When you decrease the width of your browser enough the text will continue to show under the blue colored div. I found a way to stop it using 'text-overflow: ellipsis' but it stops at the first line.
Is it possible to make it continue until it reaches the height of the div and then show three dots at the end rather than continuing under it?
Below properties are useful when you want to show ellipsis at the end of single line.
div {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Since you are looking for multi line ellipsis (which is not directly available in CSS), I think below link might help you :
https://codepen.io/martinwolf/pen/qlFdp
There is also one Jquery plugin available which can be used :
https://tpgblog.com/threedots/
Recently I have been having a few issues with using a content editable div as a text box for a project I have been working on. The project is built with Angular2 on the front-end.
The issue I have been having is when I go to tab/space all the way to the end of the content editable div, rather than moving to the next line, it instead keeps adding tabs that appear to accumulate in the text content of the div. By that I mean, if I hit the tab/space key 4 times once it reaches the end, I will then have to backspace 4 times to clear them out.
<div class="text-box" contenteditable="true"></div>
body
{
background-color: black;
}
.text-box
{
background-color: white;
color: black;
height: 200px;
width: 200px;
margin: auto;
white-space: pre-wrap;
}
https://codepen.io/anon/pen/YxYNYW
The code pen I included demonstrates the issue. If you just click inside the box and then hold space bar, once the cursor gets to the end, it will not move to a newline. I realize it has something to do with the white-space: pre-wrap property I use with the content editable div. Is there anyway to get this to work while still being able to use that property?
I would like to keep the pre-wrap property because it preserves all the white-space that is brought in from objects with text in the database. I tried it with the pre-line property over pre-wrap but that caused the text to jump when clicking into the editable div. I also tried using word-break: break-all which seemed to work but then the text gets a little messed up.
Also on a side note, has anyone ever experienced an issue where they were unable to click between characters once the text was highlighted? This is kind of a weird issue to describe, and a tough one to track down apparently. What happens is I will type some text into the div, highlight it with my cursor, and then if I try to deselect the text by clicking in between characters, it will not work. I will have to click a line that is currently not highlighted or outside of the element entirely to deselect any highlighted text.
I originally thought maybe it was a content editable issue, but it seems to be working fine in the code pen I linked, so now I am not sure what it is.
Thanks in advance for the help!
You have to use word-break for solving your issue.Modify your css like following
body
{
background-color: black;
}
.text-box
{
background-color: white;
color: black;
height: 200px;
width:150px;
margin: auto;
white-space: pre-wrap;
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: pre-wrap; /* css-3 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
word-break: break-word;
white-space: normal;
}
This solves your problem.Here is the working pen pen
Please reffer this ans for more info
I have a simple two-word header, from which I would like to remove or hide the last word, instead of wrapping it to the next line, when there is not enough room in the window for both words.
<h1>First Last</h1>
I know that there are no first-word selectors for css, so that's not an option. I could hide the overflow, but I want the last word to disappear all at once, not letter by letter. And of course, white-space:nowrap; comes to mind, but that doesn't remove the word.
Is there a way to do this with css? Preferably without fixed heights or widths?
http://jsfiddle.net/pnaL4/2/
There is no possibility to select a last word from a tag. The only possibility I could think of was to use a media query that loads this custom CSS when the line size is too small:
h1 {
visibility: hidden;
}
h1:before {
visibility: visible;
content: "First";
}
Of course, this would require you to specify the showed content.
Simple. Use a white-space:nowrap; CSS Property.
h1 {
white-space: nowrap;
}
This will ensure that even if the window resizes, the text will not wrap down and get hidden as the window shrinks.
Here is the WORKING DEMO to illustrate the issue.
I ususally do something like
h1 {
font-size: 250px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 745px;
}
ellipsis outputs ... to show there is more text to come, if you don't want anything at all I would do
text-overflow: inherit;
another good tip if you are cutting of text is to add a title attribute to the h1 so that the user can see the full word on hover.
eg
<h1 title="First Last">First Last</h1>
If you let the overflowing word(s) break to the next line, you can use an overflow with a height instead of width to create that effect:
h1 {
height: 30px;
overflow: hidden;
}
Example
I was trying to make a link restricted to a width using the ellipsis.
The html is something like this:
<a class="blueLink2 destination-url-space" style="top:0;" href="http://google.com/uyv245">http://google.com/iuh345345345gthrthrthrth</a>
and the CSS is
.blueLink2 {
color: #0051A1;
display: inline;
font-size: 14px;
margin-left: 5px;
overflow: hidden;
position: relative;
text-overflow: ellipsis;
top: 0;
}
.destination-url-space {
display: inline-block;
max-width: 200px;
overflow-x: hidden;
}
But it's working only in Chrome. Not working in Firefox.
Demo: http://jsfiddle.net/xE6HG/
you need to add white-space: nowrap; there
DEMO
p{
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-ms-text-overflow: ellipsis;
-moz-binding: url('ellipsis.xml#ellipsis');
}
<p>
Lorem ipsum is a pseudo-Latin text used in web design, typography, layout, and printing in place of English to emphasise design elements over content. It's also called placeholder (or filler) text. It's a convenient tool for mock-ups. It helps to outline the visual elements of a document or presentation, eg typography, font, or layout.
</p>
<p>
Lorem ipsum is a pseudo-Latin text used in web design, typography, layout, and printing in place of English to emphasise design elements over content. It's also called placeholder (or filler) text. It's a convenient tool for mock-ups. It helps to outline the visual elements of a document or presentation, eg typography, font, or layout.
</p>
I have html elements for which i want to show more information in a tooltip on hover than actually fits nicely into one short row.
How can i create tooltips bigger than one row?
(something that looks like a right click menu in the brower - but without function)
It is important that i have control over the break point because each line to be shown in the tooltip might hold text of different length.
Example:
<div title="1.Exampleline1\n2.Exampleline2\n3.Exampleline3 this one is longer"> //three rows - not one!
This is an example tooltip:
EDIT: It should work in all browsers (FF too)!
If you are targeting only browsers that support the latest specification or only IE and Safari, you can use
(the carriage return). Otherwise look into CSS tooltips.
This similar question about using carriage returns in tooltips has more information.
If you can't find a good solution using only HTML, there's a nice way of doing it with JavaScript (jQuery actually). You should check out this nice tutorial by yensdesign :
http://yensdesign.com/2009/01/how-to-display-tips-creating-jquery-plugin/
UPDATED Tested in FF / Chrome
DEMO 2: http://jsbin.com/eharu5/3
CSS
a.tooltip {
position: relative;
}
a.tooltip span em {
font-style: normal;
display: block;
border-bottom: 1px dotted #000;
}
a.tooltip span {
white-space: nowrap;
border: 1px solid #CCC;
color: #333;
padding: 5px;
background: #FFF;
left: 50%;
top: 0;
width: auto;
position: absolute;
display: none
}
a.tooltip:hover span {
display: block
}
a.tooltip span br {
display: none
}
HTML
<a class="tooltip">Hello World
<span>
<em>Lorem Ipsum Est Lorem <br />Ipsum Est Lorem Ipsum Est</em>
<em>Lorem Ipsum Est</em>
<em>Lorem Ipsum Est</em>
<em>Lorem Ipsum Est Lorem Ipsum Est</em>
<em>Lorem Ipsum Est</em>
</span>
</a>
You can't make the tooltip bigger, but you can make DIV float near the cursor when they hover over it.
http://snipplr.com/view/3624/show-floating-div-near-cursor-on-mouseover-hide-on-mouseout/
I use overlib for this sort of things as it includes options like making the tooltips sticky, intelligently positioning them (eg to the left if the source is at the eight edge of the browser window etc) and you can style them easily.
http://www.bosrup.com/web/overlib/