Forum Moderators: not2easy

Message Too Old, No Replies

Expandable element with minimum width

         

zCat

11:40 am on Aug 22, 2007 (gmt 0)

10+ Year Member



Another one of these things I'm not sure is possible, and if it is how to find the answer using a search engine.

The problem is: I have a web application which provides user feedback when events are completed, such as updating a page. I want to display the message highlighted with a tasteful border and background so it stands out. However, some of the messages can be quite short, so I'd like to have the highlighted area with a minimum width, say 140px - and if the message is longer, the area expands accordingly without wrapping the text (unless the text is very long of course).

Can I do this with plain, reasonably standard CSS?

This is the CSS definition:

<style type="text/css">
.message {
border:1px solid red;
background-color:orange;
padding:4px;
min-width:140px;
text-align:center;
}
</style>


The first message should be 140px wide, and the second one as wide as it needs to be.

<div class="message">
Page updated
</div>
<br>
<div class="message">
Thankyou for your feedback. We have printed it out and fed it to our goat.
<div>

Marshall

12:41 pm on Aug 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



zCat,

Might I suggest setting you widths in em's (or %) with a minimum left and right padding in the box.

<style type="text/css">
.message {
border:1px solid red;
background-color:orange;
padding:.25em 1em .25em 1em ;
min-width:10em;
text-align:center;
}
</style>

This should provide a flexability you are looking for.

Marshall

zCat

10:21 am on Aug 24, 2007 (gmt 0)

10+ Year Member



Hmm, thanks but that doesn't seem to solve the main problem. Maybe a better way to describe it would be: I want to display a single line of text - centered within the surrounding element - with a border around it. The area surrounded by border should be at least (say) 140px wide, even if the text is not very short. Should the text be longer, the bordered area should expand accordingly.

CSS isn't my forte, I have no idea if it's even possible. And trying various combinations involving e.g. min-width doesn't seem to work. Putting the text in a <span> with a border solves the expansion problem, but a <span> can't have a defined width, it seems.

rocknbil

6:11 pm on Aug 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



zCat are you using a valid document type? min-width should work.

Well, except for IE 6. I recently encountered this with a project, you are supposed to be able to use the star hack to get IE 6 to play along with min-width,couldn't get it to work right.