Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > CSS > CSS Cascading Style Sheets
CSS Cascading Style Sheets All issues relating to Cascading Style Sheets (CSS).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the CSS Cascading Style Sheets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 9th, 2007, 10:35 PM
Registered User
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

I have created a css button like title.The code is listed below. But I want the title background to grow as the text expands instead of a fixed width. I noticed that if I dont give a fixed width it totally enlarges to the whole screen.
Is there any way I can change it so that the title background grows as the text grows??

Thanks in advance

#product_content_r .product_box h6.news {
width: 6em;
padding: 0.2em;
line-height: 1.6;
background-color: #C83091;
border: 0px solid black;
color: #fff;
text-decoration: none;
text-align: center;
margin-right:5px; font-size:12px;


<h6 class="news">NEWS</h6>

Old December 9th, 2007, 10:44 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts

Are you talking about a background image? Background images tile by default, so you must have done something to stop that. I don't know what, because there is no trace of any background image in the code you posted.

Old December 19th, 2007, 12:36 AM
Friend of Wrox
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts

No, I've been playing around with this and pouring over all the pages of my sites, and I've never done this either apparently.

When you use the width: 6em; style rule, it creates a magenta box 6em long. But depending on the text you have in the XHTML file, this may or may not be enough for the text. It may force the text to wrap onto a second line. If you remove the width rule, you get the heading onto one line, but the magenta box instantly snaps to the width of the screen (adjusting only for the margins). I've played with the margins and using percents and other units for the width, but the same basic problem remains. It sounds like you want the box to automatically expand to fit the length of the content. So far I haven't been able to find a solution.

...Depending on how many people you want to piss off, you could create a one cell table. I believe that would display the behavior you're looking for. ;) (Just a bad joke, and besides I'm not sure. It's been years since I did a table based layout.)


Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change background color using CSS pigtail Javascript How-To 9 April 4th, 2010 11:13 AM
Calendar Control Title Doesn't Position with CSS.. kevorkian ASP.NET 2.0 Basics 5 June 19th, 2008 11:33 AM
background image width through CSS problem inOpera iamrakesh22 CSS Cascading Style Sheets 0 May 31st, 2007 06:09 AM
CSS Background images not loading in ASP.NET 2.0 vinyel23 ASP.NET 2.0 Basics 0 January 5th, 2007 12:54 PM
Problem with background images in CSS & Tomcat MW_ Apache Tomcat 2 April 18th, 2005 08:07 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.