tags:

views:

133

answers:

4

I am creating an MVC 1.0 form to use in multiple views. I have some elements that need to be shown on the same line, and I have done this by setting the display to "display: inline" for the style. I have also added the margin-left setting to the CSS in order to force the gap between the inline elements but this doesn't appear to be being set.

My CSS has:

fieldset label.inline { display: inline; margin-left: 2em; }

The view code is:

<fieldset>
    <legend>Details</legend>
    <p>
        <label for="StartTime">Start Time:</label>
        <%= Html.TextBox("StartTime", Model.StartTime.ToShortTimeString())%>
        <label for="NextDay" class="inline">Next Day?</label>
        <%= Html.CheckBox("NextDay") %>
        <%= Html.ValidationMessage("StartTime", "*")%>
    </p>
</fieldset>

Setting the size in the "margin-left" style has no impact on the space between the StartTime control and the NextDay label. How can I create this gap between the elements?

A: 

What browser are you testing in?

If you're using Firefox, use the Firebug extension. Use the pointer tool to select one of your elements, and then use the Layout tab to look at the box model. That will show you the padding, border and margins that are being applied. If you post the HTML being generated and the box model properties that are being calculated you might get better answers.

Seth Petry-Johnson
The style being applied (as shown in Firebug) is:fieldset label.inline {display:inline;padding-left:4em;}so as I'd expect.The HTML is:<p> <label for="StartTime">Start Time:</label> <input id="StartTime" name="StartTime" type="text" value="00:00" /> <label for="NextDay" class="inline">Next Day?</label> <input id="NextDay" name="NextDay" type="checkbox" value="true" /><input name="NextDay" type="hidden" value="false" /> </p> It isn't being shown as right-aligned in IE. It is in Firefox.
Val M
A: 

Just use padding insted of margin. Padding left and right will work. Padding top and bottom won't since it is an inline element (would work on inline block). You can set line-height to adjust the top and bottom margin.

easwee
Changing the style sheet to:fieldset label.inline { display: inline; padding-left: 4em;}han't made a difference. I still don't have a gap before the label.
Val M
Check for any css styles that might override your padding-left property. I'm 100% sure this works - even in IE7. You can try setting padding-left: 4em !important; to see if this causes the problem.
easwee
Using Firebug to check the actual style being rendered I get this:fieldset label.inline { display:inline; padding-left:4em; } so the style is being set but doesn't appear to be being applied by IE7.
Val M
Did you try use !important on the tag? This is your same exact example: <style type="text/css">p {background:#ccc;font-family:Arial, Helvetica, Sans-Serif;}label.inline {display:inline;padding-left:30px;}</style></head><body><p><label for="StartTime">Start Time:</label><input id="StartTime" name="StartTime" type="text" value="00:00" /><label for="NextDay" class="inline">Next Day?</label><input id="NextDay" name="NextDay" type="checkbox" value="true" /><input name="NextDay" type="hidden" value="false" /></p></body>
easwee
If you try running it in a separate file you will see it works in IE7 and all other browsers. If this does not work for you than sorry I can't help because you must have some other kind of problems.
easwee
A: 

The "margin" style works different for inline elements. You can use the "inline-block" display-mode:

fieldset label.inline { display: inline-block; margin-left: 2em; }
Tomas
inline-box is not a css property. You probably mean inline-block. Altough there is a firefox specific -moz-inline-box.
easwee
I have now triedfieldset label.inline { display: inline-block; margin-left: 4em; padding-left: 4em;}but still without success.
Val M
A: 

Use display: inline-block;

chopsticks