So after hours of searching I cannot find a simple solution to this problem. I run a website, and am very limited in my self taught HTML and CSS coding. My site runs Wordpress as the foundation, and when making a post, sometimes we put in long URLs. Often times those long URLs extend outside of the boundaries of the actual post, and push into the sidebar widgets, and even sometimes extending the entire page so that there is a scroll bar. Like I said my knowledge of coding is relatively limited, and I'm looking for a simple solution to fix this problem quickly. I don't want a long drawn out way to do it, as I will likely have to implement them on a daily basis. So let me know what you think about the solutions. I've read a couple things about word-wrap and but I'm just not grasping it. Please somebody who knows what they're doing explain a solution to this using HTML in terminology that anybody could understand.
Thanks in advance.
Here's a little look at a few things you can do, and what effect they'll have:
http://jsfiddle.net/fW5bF/
In the first case, the paragraph has a set width, but the content is too long, and therefore it's height expands to enclose all the text. Notice that the text is broken up into separate lines where the white space is.
In the second case, I've used white-space: nowrap; to prevent the text from being broken up into multiple lines. This causes the text to overflow the boundaries of the paragraph element.
I then hide this overflow using overflow: hidden;.
And then I use text-overflow: ellipsis; to include ellipsis indicating that there is more text, but that we ran out of space to show it.
Now we have a single really long 'word' (such as a URL) and hence there is no white space. Therefore, by default, it just overflows it's container.
You can break up a single 'word' into multiple lines using word-wrap: break-word;.
Or again, you can use overflow: hidden; to hide the overflow, and text-overflow: ellipsis; to include ellipsis.
I suggest you look up all these properties on a reference site like MDN: https://developer.mozilla.org/en-US/docs/Web/CSS
The css rule "word-wrap:break-word" ought to do what you are looking for.
Here's a fiddle: http://jsfiddle.net/9AZtx/ using:
p
{
outline:1px solid #ccc;
width:20em;
word-wrap:break-word;
}
You can use text-overflow: ellipsis:
.element {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Related
I wanted to use a span element to style some text, but for some reason when I enter that code it will on the right side of the page show that scroll bar. It's not like that default scroll bar you will find on Google Chrome; it's really short, and when I move it it moves my text up and down for some reason.
I don't know how to fix that. I have tried reducing the padding, adding <br> at the end, etc.
This is the code:
<p>And that's it! You can play around a bit more with CSS and then move to <span style="background-color: orange; color: #fff; padding: 2px;">Day 4 - Text Areas & Input Fields</span> for further lessons!</p>
I have restricted my text to a border on the page, so it looks better, but it can't have anything to do with my problem since I haven't had it before and I've been using this border tactic for a while now. And as well I know the button "My other articles" isn't linked to anything--I'll add the link later. I just need help with this one problem.
Thanks to whomever helps me out with this in advance.
It seems to be rendering correctly for me (Chrome on Linux):
I'd suggest you update your answer with a screenshot of what's happening.
The best thing to try in this scenario is to add the following CSS to your code if it's not working for you:
span {
overflow: visible;
}
Since you're doing inline CSS (you don't appear to have a linked stylesheet), you probably want something like this as your full code:
<p>And that's it! You can play around a bit more with CSS and then move to <span style="background-color: orange; color: #fff; padding: 2px; overflow: visible;">Day 4 - Text Areas & Input Fields</span> for further lessons!</p>
overflow: visible; ensures that the element doesn't show scrollbars. In most cases (such as if this rule is applied to a <div>), then text inside the element will visually overflow if the element is a fixed size. The <span> isn't a fixed size (it grows as text is added), and so text won't appear as overflowing. Hopefully, though, it should solve the scrollbar problem.
Alternatively, you could try using overflow: hidden; which will hide the overflow entirely. Try experimenting with either visible or hidden and see if your code works!
More info about overflow: overflow - CSS: Cascading Style Sheets | MDN
It's not like that default scroll bar you will find on Google Chrome; it's really short, and when I move it it moves my text up and down for some reason.
Try also applying the CSS to the <p> element as well/instead, or even the <body>. The <span> may or may not be the element that's experiencing the overflow issue, after all. Your question is admittedly worded quite vaguely for us to tell how the problem manifests.
I like displaying emails properly, meaning not [at].
To fight the bots I reverse the text in the html and then re-reverse it with css using direction: rtl. That worked fine for many many years, until an email dared to break lines.
You can see what happens on the screenshots; kinda hard to explain–
Thats the mess that happens
This is how it looks when there is enough space
The http-host is always the same, so I figured using text-overflow: ellipsis together with white-space: nowrap and overflow: hidden on the <a>. That went south aswell;
(side note: it wasn't possible for me to fully highlight the visible text?)
(The end of the highlight is NOT the end of the box!)
Okay; the text-overflow clipping comes first, then the reversing; I get it.
So lets put overflow: hidden and text-overflow: ellipsis on the parent, which is a <p> and the white-space: nowrap on the a (scared that a telephone number will get chopped off)
I played around with a combination which styles go to the p and which to the a .. and I had one solution (which I unfortunately can't reproduce oO) where the dots were at the right side (which is what I want) but the text still gets chopped of an the visual left of the outcome, meaning the name name of the email, which I do not want to clip!
Long question short..
How can I get the following result?
S.Rossa#park-reside...
When my email markup looks like this:
<a href="/email.php?to=rossa" class="direction">
<?php echo strrev("S.Rossa#park-residenz-alfeld.de"); ?>
</a>
Out of many reasons I cannot go back from the direction: rtl thing on the emails.
Please keep that in mind when suggesting a way to
keep the email from breaking lines, no matter what
and a convenient way to clip it with ...
with css only
Thanks!
The browser is given a string. When you tell it to shrink it and replace what doesn't fit with an ellipsis, it will always cut from the end of the string. It doesn't know your string is reversed and it trusts you when you tell it: this string should be read from right to left (direction:rtl). The end is on the left side.
Therefore, with CSS alone, the closest (and most decent) thing you can get is cutting from left side and placing the ellipsis where the cut was made:
a.direction {
direction: rtl;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
/* proof of concept: */
width: 25%;
display: inline-block;
}
ed.dlefla-znediser-krap#assoR.S
You have two options now. Either
give up on text-overflow: ellipsis and fake it using JavaScript (works, but it's ugly) or...
you could reverse the string before you render it and give up on direction: rtl (which is actually a trick, it's not correct and is the source of the problem). Of course, you need to make sure you only do this for browsers, not for bots. The easiest way would be to check navigator.userAgent:
if (!/bot|crawler|spider|crawling/i.test(navigator.userAgent)) {
var directions = document.querySelectorAll('.direction');
for (var i = 0; i < directions.length; i++ ) {
directions[i].textContent = directions[i].textContent.split('').reverse().join('');
}
}
a.direction {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 25%;
display: inline-block;
}
ed.dlefla-znediser-krap#assoR.S
However, navigator.userAgent is not to be trusted, as malicious bots will never declare themselves as bots. So you might want to use safer methods of excluding bots, such as a link (clickable only by bots) pointing to a php script that would set a session variable for them. If the variable is set, just add an invisible element to your page and in the above JavaScript, instead of checking navigator.userAgent, check for the added element.
If you want the emails correctly indexed by certain search engines, you should exclude them from this check.
I am calling few sentences from a JSON file and append it in a <p> tag.
<p>
Thank you all for another magical night spent together
this last sunday at The Hippodrome in Baltimore.Thank yo...
<p>
And i'd like to shorter it, even it's already been shorten in the json, am i able to use pure css or html to limit it's length?
I don't need any javascript/Jquery suggestion because if comes to javascirpt it's easy to accomplish this task, i might just play with dom, but in this case i want to see if there's any pure html and css method can do this.
UPDATE 1:
Everyone suggest me to convert the sentences in to one single line using white-space: nowrap and then hidden text by setting text-overflow:ellipsis but there's a limitation, the html can just display single line. Is there anyway to display another line?
CSS and HTML can't get length of the sentence. So, we don't have limit for CSS and HTML can't get length of the sentence. So, can't set limit length for the sentence. But if you want use CSS to truncate a line of the sentence with max-width of element. You can do:
p {
max-width: 100px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
If you are single line, use text-overflow:ellipsis attributes to achieve a single line of text to display an ellipsis (overflow …). Of course, some browsers also need to add width attributes.
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
If it is a multi line, use WebKit CSS extended attribute (WebKit is private property) -webkit-line-clamp;. Attention: WebKit browser or mobile terminal (the majority is a WebKit based browser) page are easy to be implemented in the: This is a non-standard attribute (unsupported WebKit property) the, it does not appear in the draft of the CSS specification.
-webkit-line-clamp is used to limit the number of rows in a text displayed by a block element. In order to achieve this effect, it needs to be combined with other WebKit attributes.
Common binding properties:
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
you can use as also the link https://developer.mozilla.org/en/docs/Web/CSS/text-overflow
p {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 200px; /*width as you want */
}
Use this example:
<p style="width: 150px;height: 15px;overflow: hidden;">
Thank you all for another magical night spent together
this last sunday at The Hippodrome in Baltimore.Thank yo...
</p>
You'll want to truncate the text with CSS, and by the looks of it, you want multi-line text boxes that truncate correctly at the end (the answer by Anubhav is single-line specific). Because no pure-css options exist (that I'm aware of) to handle this, you'll probably need a jQuery plugin, such as clamp.js or similar.
The answer you probably want is from another SO thread, here:
https://stackoverflow.com/a/33061059/5580153
Edit: There is also a fairly intricate CSS solution here: http://hackingui.com/front-end/a-pure-css-solution-for-multiline-text-truncation/ although it's a bit of a hacked solution I feel.
you can use text-overflow: ellipsis; instead. please read the example below.
<div id="readmore">Thank you all for another magical night spent together
this last sunday at The Hippodrome in Baltimore.
</div>
CSS
#readmore {
white-space: nowrap;
width: 12em;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid #000;
}
For more info please through this reference
I'm working on a site wich has filters on category pages - http://www.purrfectlyyappy.com/fun-and-games/dog-toys
The filter is on the left hand side, but the text in the filter appears under the products when it's too long, is there a way i can set it to break onto a second line if the name is too long?
Seem like it should be easy, but i've been struggling on this!
This is happening because there is a css in you page
.hikashop_filter_checkbox {
white-space: nowrap;
}
Above css is already applied on your html page which is forcing elements to come in single line.
You can either remove this css and if not then use following css in label
.hikashop_filter_checkbox label{
white-space: normal;
}
Use the overflow property.
enter link description here
Here, adding :
overflow : scroll;
will make the "too long text" in a scroll area. There are many other values.
I'm trying to show boxes of people's names.
The problem is that these names can get pretty long, and with a fixed width box, crazyness is sure to ensue. Long spaced text breaks, causing problems on new rows (http://jsfiddle.net/9MhWW/) and disabling line-breaks with white-space: nowrap; will overflow the box (http://jsfiddle.net/9MhWW/1/).
Working with line breaks seem like the best option. If you agree, that begs the following question: Is there a way to make sure the row-problem doesn't occur without losing part of the text, having a div for every row or giving the paragraph a fixed height?
If just one row is ok for you, set a overflow: hidden:
p { overflow: hidden; }
A nice effect will be using ellipsis to replace the overflowing text with ...:
p { overflow: hidden; text-overflow: ellipsis; }
See this update to your fiddle.
I think I have come up with a solution. So bootstrap adds loads of stuff in to make it look nice of course, but in your case we have to undo some of that. So we have to get rid of the float left and replace it with display inline-block:
.span2{
float: none !important;
display:inline-block;
}
See the fiddle update. I had to change the text alignment to match what you had previously.