473,699 Members | 2,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Text background colour

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
Jul 21 '05 #1
7 4799
Op Sun, 6 Mar 2005 05:12:13 +1300 schreef "KiwiBrian"
<br******@ihug. co.nz>:
Using a div and css how do I have a text background colour that
automaticall y adjusts to the size and amount of the text string?

TIA
Brian Tozer


You mean the bacground only applies to the text, not to the entire
div?
In that case:

in your HTML

<div>
This text does not have background color yellow.
<span class="test">So me text with background color yellow.</span>
This text does not have background color yellow either.
</div>
In your CSS

span.test{
/* pick any color you like */
color: black;
background-color: yellow;
}

(not tested, just on the top of my head [if that's correct English])

Bart

--
Bart Broersma
br************* ********@tiscal i.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Jul 21 '05 #2
> 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?


You can't; you need a SPAN inside the DIV.

--Phil.

Jul 21 '05 #3

"KiwiBrian" <br******@ihug. co.nz> wrote in message
news:d0******** **@lust.ihug.co .nz...
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?


Thanks Bart and Phil.
Really appreciate it.
Brian.
Jul 21 '05 #4
wrote on 05 mrt 2005 in comp.infosystem s.www.authoring.stylesheets:
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?


You can't; you need a SPAN inside the DIV.


I think you can.

<div style='display: inline;backgrou nd-color:red;'>abc xyz</div>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 21 '05 #5
>>> 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?

You can't; you need a SPAN inside the DIV.

I think you can.
<div style='display: inline;backgrou nd-color:red;'>abc xyz</div>


OK, you can. But then it doesn't look like a DIV any more. You can
also do it by floating it, for example. But I suspect that Brian wants
to have a background color while keeping the normal DIV behaviour.

--Phil.

Jul 21 '05 #6
wrote on 06 mrt 2005 in comp.infosystem s.www.authoring.stylesheets:
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?
You can't; you need a SPAN inside the DIV.

I think you can.
<div style='display: inline;backgrou nd-color:red;'>abc xyz</div>


OK, you can. But then it doesn't look like a DIV any more. You can
also do it by floating it, for example. But I suspect that Brian wants
to have a background color while keeping the normal DIV behaviour.


Sure Phil,

I agree with your suspicion,
but answering on what you believe the OP is asking
only makes things worse.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 21 '05 #7
in comp.infosystem s.www.authoring.stylesheets, KiwiBrian wrote:
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?


Your question is quite unclear, but you can use:
display:table;

float:left;

display: inline;display: inline-table;display:i nline-block;

or

display:inline

Each has issues. To know what is suitable for your case, context would be
needed.


--
Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
Utrecht, NL.
Jul 21 '05 #8

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

Similar topics

4
2484
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 backgound colour? I have a table with a background that has a picture. When the user hovers over the picture I want the background to change to the background colour of the rest of the page, as if to make the picture disappear.
3
7165
by: kj | last post by:
Is there any way to disable text selection in a web page (or at least render it invisible to the user)? If there is a way to control how selected text and its background are rendered, then the desired effect could be achieved by setting these parameters to match those of regular text. In this way, even if text was selected, the user would not see that it was. Thanks!
4
2454
by: Werner Partner | last post by:
I'm looking for something like that: http://www.sonoptikon.de/praxis-mt/test.php The text should have a certain indent, and from the left border should come a "marker" which goes over the text for a certain length. Please don't look at the source text, ;-) it's terrrible, but I just wanted to show how about it should look like. Of course in my test case I cannot realize two features: - the couloured marker should always have same...
7
14935
by: miked | last post by:
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:
3
4756
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
14
3123
by: Eric Lindsay | last post by:
I've seen a page using display, and especially display table that did some neat things with boxes, but basically it only worked with Mozilla browsers. Fell over fairly badly with Opera and Safari (I don't have IE, but I have my suspicions that wouldn't work either). I'd like to use CSS to put some boxes down the middle of a page. The page is intended to be fluid, but the boxes all need to be the same width, which can be variable...
9
2959
by: al jones | last post by:
Sorry, it's getting late and I'm tired. I'm trying to fill a richtect box with text derived from the array I was asking about earlier (thank you). I'm not sure what I'm seeing - since most of the examples show how to load and save an rtf file into / from a rtbox (may want to save this guy, so that'll come in handy, later). Does anyone one know of a sample showing how to append, piecemeal, text into an rtb with format changes as...
28
40572
by: eastcoastguyz | last post by:
I'm a newbie to CSS, so be kind. :-) I have looked at examples of CSS and have not seen this yet. How can you change the colors of the text in the same word in CSS? For example, when how can you take the word "infosystems" and make the "info" part red, and the "systems" part blue? I don't want to have to hard-code this in HTML which is why I'm looking to CSS to do this. Thanks!
26
6092
by: Swifty | last post by:
I'm sending an HTML email to Lotus Notes and I'd like to hide some text from casual observation. There is nothing sinister in this; the text to be hidden is simply a 12-digit number that I use to indicate to the recipient (me!) that the mail can be archived without reading (It is a "Job ran successfully" note). It makes writing message filters simpler. So the challenge is to find something that Lotus Notes will "see", but I won't. How...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.