tags:

views:

199

answers:

4

I have two elements (a button and an anchor tag) both with a dynamical text inside that grow to the length of their content.
I cannot know which one of them will be the longest at compile time, nor can I know what the maximum/minimum width will be.
The shorter one should always adapt to the longest one.

<span id="buttonsColumn">
 <button type="submit" name="powerSearchSubmitButton" id="powerSearchSubmitButton">
  <span><em><%=ViewData.Model.T9nProvider.TranslateById("CommonWeb.Search")%></em></span>
 </button>                    
 <a class="linkButton" href="something">
  <span><em><%=ViewData.Model.T9nProvider.TranslateById("CommonWeb.Advanced")%></em></span>
 </a>
</span>

The wrapping span can be changed to anything desired.
Any ideas?

A: 

As I see it, you could do it two ways:

  1. Figure out the length on the ASP side and set a variable with the length of the larger, then use that in a size property on each.
  2. Write a javascript function to figure out which of the two is larger and set the length of both to that.
R. Bemrose
don't wanna go the java tour (jquery has it's time and place and I don't feel this is it).Maybe the asp route would be something, but if possible I would want to solve it in a css way.
borisCallens
+1  A: 

You could try something like this:

#buttonsColumn {
    display: block;
    float: left;
    background-color: #F88;
}
#buttonsColumn button,
#buttonsColumn a {
    display: block;
}
#buttonsColumn button {
    width: 100%;
    background-color: #8F8;
}
#buttonsColumn a {
    width: 100%;
    background-color: #88F;
}
Gumbo
Could be a little better#buttonsColumn button,#buttonsColumn a { display: block; width: 100%;}#buttonsColumn button { background-color: #8F8;}#buttonsColumn a { background-color: #88F;}
Julio Greff
A: 

Might I suggest you give up and use tables?

They are still part of the specification after all, and what you're doing could be construed as tabular data. All you'd need to add would be a style="width:50%" to each table data tag and a style="width:100%" tag to the button.

<table>
<tr>
    <td style="width:50%">
    <button type="submit" style="width:100%" name="powerSearchSubmitButton" id="powerSearchSubmitButton">
     <span><em><%=ViewData.Model.T9nProvider.TranslateById("CommonWeb.Search")%></em></span>
    </button>
    </td>
    <td style="width:50%">
    <a class="linkButton" href="something">
     <span><em><%=ViewData.Model.T9nProvider.TranslateById("CommonWeb.Advanced")%></em></span>
    </a>
    </td>
</tr>
</table>

You can probably get rid of those spans within the button and anchor tags, they don't seem to serve a purpose unless your CSS is doing something with the span children of the container.

inferis
currently, I wouldn't mind using tables. But I don't think your solution would solve it..How would setting my cell's width to 50% help anything?
borisCallens
Also, the more I'm working in this job, the more I have to agree with your post. Mostly because of <a href="http://www.upstartblogger.com/images/tech/stupidie.jpg">stupid IE</a>
borisCallens
Edited to show how it would work.
inferis
it only works whilst the table is not constrained. As soon as the table hits it's maximum allowable size, one of the <td>s starts collapsing.
annakata
Well, obviously yes, but you're going to get that problem with almost any solution. The question doesn't specify anything about solving the problem for an explicitly bounded area. Besides, you could deal with that by setting overflow:hidden and table-layout:fixed, it depends what you want to happen.
inferis
the extra spans are for making the buttons styled (rounded edges etc)
borisCallens
A: 

Hmmm. IE's proprietary expression will get you out of this for IE, but I can't think of a way to do this without JS for other browsers. Experimenting now...

annakata