Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-21-2008, 03:42 PM   PM User | #1
tdoggette
New to the CF scene

 
Join Date: May 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
tdoggette is an unknown quantity at this point
80-column fixed-width column of test in CSS?

How can I style a paragraph to have a specific number of text columns of fixed-width text in CSS? I know I could style it that way manually and use <pre> tags, but I was hoping that there is a way to do it in CSS.

Thanks!
tdoggette is offline   Reply With Quote
Old 05-21-2008, 03:50 PM   PM User | #2
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
Are you talking about styling a <p> tag?

like ex...
Code:
p {
width:300px;
height:300px;
font-family:Arial;
font-size:12px;
}
Not sure if that is what you mean?
jcdevelopment is offline   Reply With Quote
Old 05-21-2008, 03:54 PM   PM User | #3
effpeetee
Senior Coder

 
effpeetee's Avatar
 
Join Date: Feb 2007
Location: Clapham Junction - London SW
Posts: 4,884
Thanks: 228
Thanked 204 Times in 203 Posts
effpeetee is an unknown quantity at this point
Quote:
How can I style a paragraph to have a specific number of text columns of fixed-width text in CSS? I know I could style it that way manually and use <pre> tags, but I was hoping that there is a way to do it in CSS.
If you fix the width of the div and use a non-proportional font; would that not work?

FRANK
__________________
* Sources (updated: 21.11.2012.
Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.
effpeetee is offline   Reply With Quote
Old 05-21-2008, 04:03 PM   PM User | #4
tdoggette
New to the CF scene

 
Join Date: May 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
tdoggette is an unknown quantity at this point
I want the width of the paragraph to expand if text grows bigger, like if someone were to ctrl+. Every line having 80 characters of a fixed-width font in the paragraph, no matter what.
tdoggette is offline   Reply With Quote
Old 05-21-2008, 04:13 PM   PM User | #5
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
Then dont attach a width to the div, that way it will grow with the amount of content.
jcdevelopment is offline   Reply With Quote
Old 05-21-2008, 04:27 PM   PM User | #6
tdoggette
New to the CF scene

 
Join Date: May 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
tdoggette is an unknown quantity at this point
Quote:
Originally Posted by jcdevelopment View Post
Then dont attach a width to the div, that way it will grow with the amount of content.
I know how to make a flexible-width element; I need to know how to make it have a set number of characters per line.
tdoggette is offline   Reply With Quote
Old 05-21-2008, 04:33 PM   PM User | #7
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
Code:
h1 {
font:whatever;
color:whatever;
width:/*set a width of how long u want the line to be*/
}
Is that what you are looking for? Other then that you may need JS.
jcdevelopment is offline   Reply With Quote
Old 05-21-2008, 04:34 PM   PM User | #8
effpeetee
Senior Coder

 
effpeetee's Avatar
 
Join Date: Feb 2007
Location: Clapham Junction - London SW
Posts: 4,884
Thanks: 228
Thanked 204 Times in 203 Posts
effpeetee is an unknown quantity at this point
Quote:
Originally Posted by tdoggette View Post
I know how to make a flexible-width element; I need to know how to make it have a set number of characters per line.
This means RIGID not FLEXIBLE.

A set number of characters per line suggests a fixed width not a flexible one, surely.
(80 x 14)px per line/each line/ means (80 x 14)px each line. NO VARIATION.

You can't have it both ways. Can you?

If you do a control+ it expands the text, but still keeps the same number per line. It just adds the scroll bar.

Try it on any page of this forum.

Frank
__________________
* Sources (updated: 21.11.2012.
Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

Last edited by effpeetee; 05-21-2008 at 04:39 PM..
effpeetee is offline   Reply With Quote
Old 05-21-2008, 04:39 PM   PM User | #9
tdoggette
New to the CF scene

 
Join Date: May 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
tdoggette is an unknown quantity at this point
Quote:
Originally Posted by jcdevelopment View Post
Code:
h1 {
font:whatever;
color:whatever;
width:/*set a width of how long u want the line to be*/
}
Is that what you are looking for? Other then that you may need JS.
No, width is pixels, ems, or percentage, not characters.
tdoggette is offline   Reply With Quote
Old 05-21-2008, 04:42 PM   PM User | #10
tdoggette
New to the CF scene

 
Join Date: May 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
tdoggette is an unknown quantity at this point
Quote:
Originally Posted by effpeetee View Post
This means RIGID not FLEXIBLE.

A set number of characters per line suggests a fixed width not a flexible one, surely.
(80 x 14)px per line/each line/ means (80 x 14)px each line. NO VARIATION.

You can't have it both ways. Can you?

If you do a control+ it expands the text, but still keeps the same number per line. It just adds the scroll bar.

Try it on any page of this forum.

Frank
Okay, my goal is this: I have a paragraph within a div. The div expands to the width of its contents, no problem. The text in the paragraph needs to be 80 characters per line, NO MATTER WHAT. Is that possible to do with CSS?
tdoggette is offline   Reply With Quote
Old 05-21-2008, 05:05 PM   PM User | #11
effpeetee
Senior Coder

 
effpeetee's Avatar
 
Join Date: Feb 2007
Location: Clapham Junction - London SW
Posts: 4,884
Thanks: 228
Thanked 204 Times in 203 Posts
effpeetee is an unknown quantity at this point
Quote:
Originally Posted by tdoggette View Post
Is that possible to do with CSS?.
I don't think so.

This is all that I have been able to find so far.

Perhaps it will help you.

Here

or Here.

or perhaps Here

or yet again Here?
__________________
* Sources (updated: 21.11.2012.
Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

Last edited by effpeetee; 05-21-2008 at 05:56 PM..
effpeetee is offline   Reply With Quote
Users who have thanked effpeetee for this post:
tdoggette (05-21-2008)
Old 05-21-2008, 06:55 PM   PM User | #12
rmedek
Senior Coder

 
Join Date: Nov 2003
Location: Minneapolis, MN
Posts: 2,879
Thanks: 2
Thanked 65 Times in 56 Posts
rmedek is on a distinguished road
Quote:
Originally Posted by tdoggette View Post
Okay, my goal is this: I have a paragraph within a div. The div expands to the width of its contents, no problem. The text in the paragraph needs to be 80 characters per line, NO MATTER WHAT. Is that possible to do with CSS?
As far as I know, there's no real way to do that with just CSS. You can come close, by defining the width of the container in ems, which will make the width relative to the font-size, but since ems are calculated by font height the numbers aren't exact and will need some fudging:

Code:
#container {
	font-family: courier;
	width: 50em; /* more or less 80 chars wide on Safari with a default text size */
}
A better thing to do, I think, if it were absolutely necessary to keep a strict character count, would be to use an em-defined width in your CSS but Javascript to count the characters as they are displayed and wrap the text automatically.
__________________
drums | web
rmedek is offline   Reply With Quote
Old 05-21-2008, 09:32 PM   PM User | #13
tdoggette
New to the CF scene

 
Join Date: May 2008
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
tdoggette is an unknown quantity at this point
Quote:
Originally Posted by effpeetee View Post
I don't think so.

This is all that I have been able to find so far.

Perhaps it will help you.

Here

or Here.

or perhaps Here

or yet again Here?
Thank you very much. In the comments of your first link, there is a suggesting to use the unit ex, which is the height of an X in the font. I think it's just what I'm looking for.
tdoggette is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:05 AM.


Advertisement
Log in to turn off these ads.