Solved

WordWrap/Overflow CSS solution

Posted on 2009-06-27
10
510 Views
Last Modified: 2012-06-22
Hi,

I need a CSS class that can wrap spaceless (if at all the dictionaries permit!) lines nicely, without showing a horizontal scroll bar.

For example a line like this:
jhkjghjkhjhh.jkhksjhgjsdhgkh.gjksdhgjksdhgkh.gjksdhgkjhsdgkjhgdjshgsdhgdshgkhdsghdjshdjhgghjhgghdsgkjsdhgdshgjhgkjsdhgdshghdskjghdskjgh

floats across the screen when "overflow" attrib is not specified. If set to "scroll" the horizontal scroll bar appears. Is there a better solution?
0
Comment
Question by:csgp_1412
  • 5
  • 4
10 Comments
 
LVL 6

Expert Comment

by:mudbuggle
ID: 24728849
check out this:
http://www.css3.com/css-word-break/ (browser compatability is listed in the comments)

check out the example below: (I am attempting to find a solution for FF functionality)
<html>

<head>

<style>

div{

	width :100px;

	height : 100px;

	word-break : break-all;

	overflow : auto;

}

</style>

</head> 

<body>

	<div>fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</div>

</div>

</body>

</html>

Open in new window

0
 

Author Comment

by:csgp_1412
ID: 24728872
Well, FireFox is the one for which I need expert help :)
0
 
LVL 6

Expert Comment

by:mudbuggle
ID: 24728882
0
 
LVL 6

Expert Comment

by:mudbuggle
ID: 24728900
after a bit of research it appears the only solution appears to be javascript.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:csgp_1412
ID: 24730151
Ok. But how?
0
 
LVL 6

Expert Comment

by:mudbuggle
ID: 24731058
I am working on some code for you.
0
 

Author Comment

by:csgp_1412
ID: 24731076
Oh. Thanks a lot. That'll be great.
0
 
LVL 6

Accepted Solution

by:
mudbuggle earned 500 total points
ID: 24731209
here you go this should work. let me know if you run into any snags
<html>

<head>

<style>

div{

	width :100px;

	height : 100px;

	word-break : break-all;

	overflow : auto;

}

</style>

<script type="text/javascript">

function breakword(obj,cc)

{

	var el = document.getElementById(obj);

	var str = el.innerHTML;

	var end = str.length;

	var count = end / cc;

	var newstr = '';

	var i = 0;

	for(i=0;i<count;i++)

	{

		var start = cc * i;

		var stop = (cc * i) + cc;

		var buffer = '';

		buffer = str.substring(start,stop) + '<wbr>';

		newstr = newstr + buffer;

	}

	el.innerHTML = newstr;

}
 

</script>

</head> 

<!--- The breakword function must be run in the bodies onload to work properly --->

<!--- The breakword function can be applied to multiple text elements --->

<!--- To apply it to an element use the following syntax. breakword('element_id',amount of characters before break) --->

<!--- The one listed below will look for an element with an id equal to break and will insert word breaks every 10 characters --->

<body onload="breakword('break',10);">

	<div id="break">abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz</div>

</div>

</body>

</html>

Open in new window

0
 

Author Comment

by:csgp_1412
ID: 24731856
Thanks a lot, we will try this out.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery detect if it is a mobile device 3 98
Centering Vertically 3 27
Error in JQuery 5 37
How can i create a customized Login page based on Wordpress ? 8 27
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now