Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on 

ensure div is always the width of the text and text is not wrapped

I wrap a lot of my text in divs, because I like being able to position the text on the web page and style the text inside the div by applying styling.

Something I run into with the different themes I have for different clients is that depending on the font size, etc. text that all fits on one line for one client may end-up wrapping for another client.  Is there a way to ensure that the text always stays on ONE line?

Thanks!
CSS

Avatar of undefined
Last Comment
Tom Knowlton
Avatar of LZ1
LZ1
Flag of United States of America image

It will depend on what browser each person is using.  It will also depend on whether or not  your using a CSS reset.

Do you have a specific example you could share?
Avatar of HainKurt
HainKurt
Flag of Canada image

try
<div style="width:200px; height:200px; border:1px solid silver"><nobr>ensure div is always the width of the text and text is not wrapped</nobr></div>
<div style="width:200px; height:200px; border:1px solid silver">ensure div is always the width of the text and text is not wrapped</div>

Open in new window

Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

ASKER

Hain's examples match what I am doing, pretty much.

Except...while the <nobr> tag forces the text to a single line, it does not increase the width of the div.
SOLUTION
Avatar of LZ1
LZ1
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Designbyonyx
Designbyonyx
Flag of United States of America image

Just want to throw this out there... If you position the div absolutely and do not specify a width, then it will continue to grow in width as you put more text.  This, of course, removes the text from the natural flow of the web page.
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

ASKER

positioning the div absolutely will not work for this particular page (sorry).
ASKER CERTIFIED SOLUTION
Avatar of Designbyonyx
Designbyonyx
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

ASKER

thanks...

jQuery to the rescue again.

It's a mighty fine library, is it not?  :P  I am doing so much now with it that previously was kind of a pain.
CSS
CSS

Cascading Style Sheets (CSS) is a language used for describing the look and formatting of a document written in a markup language. Usually used to change web pages and user interfaces written in HTML, it can also be applied to any kind of XML document. CSS is designed primarily to distinguish the content of a document from its presentation.

43K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo