Set CSS property equal to another CSS property?

N

Noozer

Is it possible to set one CSS propery equal to another?

I have not set any font properties for the body of my page, so the user will
see the browsers default font. When I use the <pre> tag to preserve the
layout of some text the font applied is not the same.

Is there a way to set the font used by the <pre> tag to be the default
browser font (same as the body) if the font isn't know when the page is
created?

I assume that <pre> is using the default monospace font instead of the
default proportional font. Any way to set the <pre> tag to use the
proportional font?

Thanks!
 
N

Neal

Any way to set the <pre> tag to use the
proportional font?

pre {font-family: serif;}

This presumes the UA is using a serif font as the default, which I find to
be normally the case. But you can get them to match using:

body, pre {font-family: serif;}

To address your other question - no, you can't tell the browser to use its
default body font on pre instead of the default pre font.
 
S

Steve Pugh

Is it possible to set one CSS propery equal to another?
No.

I have not set any font properties for the body of my page, so the user will
see the browsers default font. When I use the <pre> tag to preserve the
layout of some text the font applied is not the same.

Is there a way to set the font used by the <pre> tag to be the default
browser font (same as the body) if the font isn't know when the page is
created?

pre {font-family: inherit;}

But doesn't work in all browsers.

Steve
 
J

Jukka K. Korpela

Noozer said:
Is it possible to set one CSS propery equal to another?

Yes, e.g. left: 42px; right 42px; :) But what you meant to ask isn't
possible in practice.
I have not set any font properties for the body of my page, so the
user will see the browsers default font. When I use the <pre> tag to
preserve the layout of some text the font applied is not the same.

Indeed. The <pre> element is _meant_ to set the font to a monospace, and
HTML specifications explicitly say that authors should not change this in
a style sheet. You migh decide to take a more liberal view on this, but I
think it's best to ask first what you are trying to achieve. "Preserve
the layout" in which sense? URL?
Any way to set the <pre> tag to use the proportional font?

Setting
pre { font-family: Times New Roman, serif; }
would probably be a good shot, since Times New Roman is the most common
default font at least in factory settings.

But it's better to avoid creating the problem in the first place. Avoid
<pre>, especially if you don't want monospace font. Usually there's a
better approach.
 
N

Neal

The <pre> element is _meant_ to set the font to a monospace, and
HTML specifications explicitly say that authors should not change this in
a style sheet.

"Authors are discouraged from altering this behavior through style sheets."

Not quite as strongly worded as "should not" would imply. The absence of
"should not" implies to me the discouragement is less important than if
they said "should not" but is still not quite "may".

I think if one has a good purpose to override the monospace, you shouldn't
choose not to do it based on the spec. Obviously willy-nilly abandonment
of monospace might hurt usability in some cases.
 
N

Neal

Left one other point out. The spec reads,

"... When handling preformatted text, visual user agents:
....
* May render text with a fixed-pitch font.
...."

The use of a fixed-pitch font is clearly optional for UAs, not required.
 
N

Noozer

Jukka K. Korpela said:
Yes, e.g. left: 42px; right 42px; :) But what you meant to ask isn't
possible in practice.


Indeed. The <pre> element is _meant_ to set the font to a monospace, and
HTML specifications explicitly say that authors should not change this in
a style sheet. You migh decide to take a more liberal view on this, but I
think it's best to ask first what you are trying to achieve. "Preserve
the layout" in which sense? URL?

My page is generated by ASP. One section is multiple lines of text and I
want to preserve the line breaks. Wrapping of the longer lines is not
important as long as the break at the end of the line remains.

If I use the following...

<p>This is one line.
This is another line. This line is very long and might be wider than the
browser window.
This is the last line</p>

....I don't want...
This is one line.This is another line. This line is very long and might be
wider than the browser window. This is the last line

....This would be acceptable:

This is one line.
This is another line. This line is very long and might be wider than the
browser window.
This is the last line

...as would this:

This is one line.
This is another line. This line is very long and might be
wider than the browser window.
This is the last line

Using the white-space: CSS property does not work in my case, so I am trying
to use <PRE>, which does preserve the breaks, but changes the font.
 
N

Neal

My page is generated by ASP. One section is multiple lines of text and I
want to preserve the line breaks. Wrapping of the longer lines is not
important as long as the break at the end of the line remains.

Can you not get the ASP to add <BR> at the carriage returns? I'm not
versed in ASP, so excuse me if this is incredibly stupid.
 
J

Jukka K. Korpela

Noozer said:
One section is multiple lines of text and I
want to preserve the line breaks. Wrapping of the longer lines is not
important as long as the break at the end of the line remains.

But why? What is the meaning of the breaks? Although you could force line
breaks with <br>, solving the problem in a sense (no <pre> needed), it's
best to consider first some other options. But this really depends on the
material and on the question _why_ you wish to break lines, i.e. what the
intended message is.

For one thing, line breaks as such (whether generated with <br> or <pre>
or otherwise) are insignificant (or, more exactly, equivalent to spaces)
in non-visual rendering. So is the intended message something that you
could say in a different way, a way that works as universally as
possible?
 
A

Adrienne

My page is generated by ASP. One section is multiple lines of text and
I want to preserve the line breaks. Wrapping of the longer lines is not
important as long as the break at the end of the line remains.

Then what you want to do is this:

<%
textbreak = replace(variable,vbcrlf,"<br>")
%>
<p><%=textbreak%></p>
 
M

Mitja

Neal said:
Can you not get the ASP to add <BR> at the carriage
returns? I'm not versed in ASP, so excuse me if this is
incredibly stupid.

Neither am I, but it should be dead easy. And, indeed, after two google searches: instead of using Response.write("blah"), use
Response.write(Replace("blah",Environment.NewLine,"<br>")). Untested.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top