?
Solved

How do I get a div's width to display (and expand) based upon the text?

Posted on 2011-03-25
10
Medium Priority
?
262 Views
Last Modified: 2012-05-11
I have created a css box-like display with borders, etc. (ie.: <div><div><div> </div</div></div>).  The outer div is currently displaying the full width of the page.  I only want the "box" to display with a bit of padding to the text.  Without setting a specific width for the outer div, how do I get the outer div's width to display (and expand) based upon the text? I'm trying to avoid using an additional "wrap" div to set a specific width.

.subTitleOuter {
	padding:2px 0 2px 0;
	background-color:#bf2f00;
	border:1px solid #811d05;
}
.subTitleInner {
	border-top:1px solid #d36f37;
	border-bottom:1px solid #d36f37;
	padding:3px 0 3px 0;
}
.subTitleText {
	color:#fff;
	font-weight:bold;
	text-indent:6px;
	text-shadow:0.1em 0.1em 0.05em #a42b00;
}

Open in new window


<div style="width:160px;">
<div class="subTitleOuter"><div class="subTitleInner"><div class="subTitleText">
Text to be displayed here
</div></div></div>
</div>

Open in new window

0
Comment
Question by:mar2195
  • 6
  • 4
10 Comments
 
LVL 16

Accepted Solution

by:
JF0 earned 200 total points
ID: 35216393
change your divs to spans.
0
 
LVL 16

Expert Comment

by:JF0
ID: 35216409
for padding just add it to your subTitleText class
0
 

Author Comment

by:mar2195
ID: 35216425
Nope.  Didn't work.  It's still displaying the "box" 100% with spans.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:mar2195
ID: 35216454
If this helps... This would be the difference between omitting the width param from a TABLE vs. adding 100% width to a TABLE.  Without the width param, the table's width is based upon the content.
0
 
LVL 16

Expert Comment

by:JF0
ID: 35216486
Did you change all of them to spans? Do you have a live link?
0
 

Author Comment

by:mar2195
ID: 35218033
I have no idea why using spans didn't work the first time.  It is working now using spans.  BUT... I have lost my CSS layout for the "box."  Using spans instead of divs killed the formatting.
0
 
LVL 16

Expert Comment

by:JF0
ID: 35218057
you will just need to tweak your margins and/or  paddings a bit. Give it a try and let me know if you need more help.
0
 

Author Comment

by:mar2195
ID: 35221499
OK.  So here's the latest... Everything is working correctly regarding the expanding width ... except... I cannot get padding or margin to be added to the top/bottom above/below the text.  For some reason, the 9px padding adds spacing to the the left & right... but does not add the padding to the top & bottom.

Here's the new coding:

.subTitleOuter {
	padding:2px 0 2px 0;
	background-color:#bf2f00;
	border:1px solid #811d05;
}
.subTitleInner {
	border-top:1px solid #d36f37;
	border-bottom:1px solid #d36f37;
	margin:3px 0 4px 0;
}
.subTitleText {
	color:#fff;
	font-size:15px;
	font-weight:bold;
	padding:9px;
	text-shadow:0.1em 0.1em 0.05em #a42b00;
}

Open in new window


<span class="subTitleOuter"><span class="subTitleInner"><span class="subTitleText">
Any text you want in a box-like image
</span></span></span>

Open in new window


I have tried adding another span ( and div just for yuks ).  I've also tried individual margin/padding, etc.  Nothing seems to add spacing above & below the text.



0
 

Author Comment

by:mar2195
ID: 35224117
Latest...

I have tried using an image as the background and using spans.  But still... the top/bottom of the text will not adjust using CSS.

.subTitleBanner {
	background:url('sm_banner_bkgd.gif') repeat-x;
	height:28px;
	border:1px solid #811d05;
}
.subTitleText {
	color:#fff;
	font-size:15px;
	font-weight:bold;
	padding:3px 24px 4px 9px;
	text-shadow:0.1em 0.1em 0.05em #a42b00;
}

Open in new window


<span class="subTitleBanner"><span class="subTitleText">
Any text you want in a ribbon-like image
</span></span>

Open in new window



 sm-banner-bkgd.gif

0
 

Author Comment

by:mar2195
ID: 35224133
I have no idea WTF is going on.  I know that I had coded the padding into the .subTitleBanner class before... now it IS working.

.subTitleBanner {
	background:url('sm_banner_bkgd.gif') repeat-x;
	height:28px;
	border:1px solid #811d05;
	padding:6px;
}

Open in new window


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question