?
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
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 

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

Technology Partners: 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 will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

801 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