School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,007 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,005 people online right now. Registration is fast and FREE... Join Now!




Perameter CSS?

 

Perameter CSS?

Crazydave1990

26 Oct, 2009 - 07:20 AM
Post #1

New D.I.C Head
*

Joined: 28 Sep, 2009
Posts: 6

Hi guys...

In CSS is there a way to declare a width, without having to type the EXACT measurement, for example, if we had a line of code which was simply this

CODE
<div class="google">google</div>


now, lets say we used this code, to then color the background.

CODE
<Style Type="Text/CSS">

.google {width: 100px; background-color:#999}

</style>


simples!

ok, now, is there a way, where, instead of defining the width as 100px, to make it so that its only as long as the text is... you know, makes things nice and tidy in the long run... thanks for your input!


User is offlineProfile CardPM
+Quote Post


arthurakay

RE: Perameter CSS?

26 Oct, 2009 - 09:18 AM
Post #2

D.I.C Head
**

Joined: 17 Feb, 2009
Posts: 187



Thanked: 17 times
My Contributions
I *think* that, by default, containers will be as large as the content they hold when no width/height is specified.

What happens when you remove the width declaration, leaving just the background? (You might want to add some padding so that it looks a bit neater).
User is offlineProfile CardPM
+Quote Post

Daegan

RE: Perameter CSS?

26 Oct, 2009 - 11:47 PM
Post #3

D.I.C Head
Group Icon

Joined: 17 Mar, 2009
Posts: 64



Thanked: 3 times
Dream Kudos: 25
My Contributions
QUOTE(arthurakay @ 26 Oct, 2009 - 10:18 AM) *

I *think* that, by default, containers will be as large as the content they hold when no width/height is specified.

What happens when you remove the width declaration, leaving just the background? (You might want to add some padding so that it looks a bit neater).

P and H tags have a width of 100% set, but aside from these things will only take as much width as specified. If no specification is set they will take as much room as needed. You should set specific widths of things as a general rule, though.
User is offlineProfile CardPM
+Quote Post

thehat

RE: Perameter CSS?

27 Oct, 2009 - 02:07 AM
Post #4

awake ? web();
Group Icon

Joined: 28 Feb, 2008
Posts: 940



Thanked: 99 times
Dream Kudos: 200
My Contributions
A div will always fill the width of it's parent element unless you specify a width. To only colour the background of the text I would use a <span> instead.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:02AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month