473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to limit text background colour to text itself?

Hi,

On a webpage I'm authoring I'm having a problem with setting the text
background colour. I'm using this:

P {color ="FFFFFF"; background-color:"000000"; font-size:10pt;
font-family: verdana, courier, monospace}

with this:

<P>Body text goes here.</P>

I want to limit the background colour to just the text itself, but it
extends to the whole paragraph, often covering a large amount of space
that I don't want to be changed(am I right that this is a recent
property of IE and NN, that earlier versions supported what I
require?).

Does anyone know a way around this? I've tried trawling the groups but
couldn't find anything on this in paticular. Any help would be
appreciated, even if it's simply pointing out where I've missed this
already...

Thanks,
Mike D.
Jul 20 '05 #1
7 14889
in post <news:e6**************************@posting.google. com>
miked said:
P {color ="FFFFFF";
#ffffff no quotes
background-color:"000000";
#000000 no quotes
font-size:10pt;
100%
font-family: verdana, courier, monospace}


monospace

instead of just making stuff up have you considered reading a tutorial
or two?
--
brucie
27/December/2003 09:38:04 pm kilo
Jul 20 '05 #2
in post <news:bs************@ID-117621.news.uni-berlin.de>
brucie said:
P {color ="FFFFFF";
#ffffff no quotes


or =
--
brucie
27/December/2003 09:42:40 pm kilo
Jul 20 '05 #3
brucie wrote:
font-family: verdana, courier, monospace}


monospace

instead of just making stuff up have you considered reading a tutorial
or two?


Well... it is valid, although offering courier and the monospace font family
as alternatives to Verdana does rank as weird in the extreme.

--
David Dorward <http://dorward.me.uk/>
Jul 20 '05 #4
in post <news:bs*******************@news.demon.co.uk>
David Dorward said:
font-family: verdana, courier, monospace}
monospace
instead of just making stuff up have you considered reading a tutorial
or two?
Well... it is valid,
i wasn't referring to that particular line
although offering courier and the monospace font family
as alternatives to Verdana does rank as weird in the extreme.


i thought it better just to not ask or even wonder.

--
brucie
27/December/2003 09:54:48 pm kilo
Jul 20 '05 #5
m.*******@student.umist.ac.uk (miked) wrote:
P {color ="FFFFFF"; background-color:"000000"; font-size:10pt;
font-family: verdana, courier, monospace}
Only two of the declarations are formally correct by CSS
specifications, and they too are very poor pragmatically. Instead of
explaining all the details of why the above is all wrong, here's a
sensible rule:

p { color: #fff; background: #000; font-family: Arial, sans-serif; }

But the background applies to the p element, not just the text inside
it. This is how things are by definition in CSS.
I want to limit the background colour to just the text itself,
There's no such concept as "the text itself" in CSS.
(am I right that this is a
recent property of IE and NN, that earlier versions supported what
I require?).


In a weird way, you are right in an odd sense. Some previous versions
of some browsers got it wrong, coloring just the text (I guess this
applies mainly to NN 4, the zombie), which is what you want here. That
is, what you want is what browsers definitely must not do when a rule
like the above is used.

What you can do is to add a level of markup, making the content of the
p element an inline element, to which you can then apply background in
a manner that works by the rendering model of inline elements:

<p><span>Body text goes here.</span></p>

And you would then use p.span instead of p in CSS. Naturally, if you
use some properties that apply toblock elements only, you would use the
selector p when setting them (e.g., p { margin-left: 1em; }).

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #6
Thanks, Jukka, for your constructive comments.

"Jukka K. Korpela" <jk******@cs.tut.fi> wrote in message news:<Xn*****************************@193.229.0.31 >...
m.*******@student.umist.ac.uk (miked) wrote:
P {color ="FFFFFF"; background-color:"000000"; font-size:10pt;
font-family: verdana, courier, monospace}
Only two of the declarations are formally correct by CSS
specifications, and they too are very poor pragmatically.


I think the problem here is that I've only been learning this for a
few days, and I've been buzzing between a few tutorials...
Instead of
explaining all the details of why the above is all wrong, here's a
sensible rule:

p { color: #fff; background: #000; font-family: Arial, sans-serif; }

But the background applies to the p element, not just the text inside
it. This is how things are by definition in CSS.
I want to limit the background colour to just the text itself,
There's no such concept as "the text itself" in CSS.


Hopefully, I begin to understand a little better. I think you're
saying that since the p element is more than just the text contained
in it, then anything applied will apply to more than just the text.
(am I right that this is a
recent property of IE and NN, that earlier versions supported what
I require?).
In a weird way, you are right in an odd sense. Some previous versions
of some browsers got it wrong, coloring just the text (I guess this
applies mainly to NN 4, the zombie), which is what you want here. That
is, what you want is what browsers definitely must not do when a rule
like the above is used.


And so things don't display as I'd like because the browsers have
tightened up. Interesting!

What you can do is to add a level of markup, making the content of the
p element an inline element, to which you can then apply background in
a manner that works by the rendering model of inline elements:

<p><span>Body text goes here.</span></p>

And you would then use p.span instead of p in CSS. Naturally, if you
use some properties that apply toblock elements only, you would use the
selector p when setting them (e.g., p { margin-left: 1em; }).


I'll try this. Thanks again for your help.

Mike D.
Jul 20 '05 #7
m.*******@student.umist.ac.uk (miked) wrote:
I think you're
saying that since the p element is more than just the text contained
in it, then anything applied will apply to more than just the text.


Yes. In rendering, the p element is a rectangle, with its width being
(by default) the entire available width. Text lines can be shorter than
that width and normally vary in length.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
2
by: Martin | last post by:
Dear Experts! I'd be grateful if you can help me with this. I'm having an inline frame which points to 'www.externalsite.com'. The page which contains the inline frame has an orange...
7
by: KiwiBrian | last post by:
Using a div and css how do I have a text background colour that automatically adjusts to the size and amount of the text string? TIA Brian Tozer
3
by: Hans Karman | last post by:
Is it possible to set the background colour for each record in a continuous form to the colour stored in a datafield within that record? Hans Karman, Canberra, Australia
4
by: Lachlan Hunt | last post by:
Hi, I'm looking for an interoperable method of determining the current background colour of an element that is set using an external stylesheet. I've tried: elmt.style.backgroundColor; but...
3
by: Bundy | last post by:
Hi How do I change the background colour of an input box in a form as soon as the value is changed? Also the background should revert back to it's original colour if the user decides that they...
3
by: Yashesh Bhatia | last post by:
Hi Sorry if it's a trivial question. I'm a newbie to js and did some reading since the last 3-4 hrs but have not been able to get the answers, hence this post. essentially i'm trying to...
11
by: quartzy | last post by:
I am trying to set up an elastic layout with a background colour, then the body centred. But it is not working in the browsers. Here is the HTML and CSS, it looks OK to me but I must be doing...
3
by: bettyboo | last post by:
Hi I'm new to the forum and also a VERY new user of Access to develop databases. I'm building a DB for a driving instructor acquaintance, and he wants a button on the pupil data entry form which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.