4

I have several Razor pages in an MVC4 project that follow a general layout that can be viewed here. Each page will have a fieldset, and most will have either a Save or Next or whatever kind of button. What I'd really like and can't figure out is how to get the Save/Next/Whatever button to always position in the lower-right corner of the fieldset. I've attempted solutions from a couple of other questions, but sadly none seem to apply to this situation. Is this even possible?

Here's the stylesheet.

Community
  • 1
  • 1
AJ.
  • 16,368
  • 20
  • 95
  • 150

3 Answers3

6

Put the fieldset in position:relative and put the button in Position:Aboslute with bottom:0 and right:0, this should work for one button, to place the others, do the same thing but change the right value to the combine width of the other buttons.

Example:

.lower-right-button{
    position:absolute;
    bottom: 0;
    right: 0;
}
<fieldset style="position: relative">
<input type="submit" value="Save" class="lower-right-button">
<input type="submit" value="New" class="lower-right-button" style="right: 110 px">
</fieldset>

EDIT: The bottom and right attributes align the bottom and right edge of the element with the bottom and right edge of its container. In that case, bottom: 0 and right: 0 will place it at 0 pixel from the bottom-right corner, you might want to put something else like bottom: 5px right:5px

EDIT AGAIN: Fixed, initial proposition didn't work, here's a JSFiddle

EDIT ONCE AGAIN: With Romias proposition, put the button in a div and position the div at bottom right instead, here's the updated JSFiddle

DangerMonkey
  • 385
  • 1
  • 5
  • The best is putting the inputs in a div... to position the whole container. – Romias May 03 '12 at 15:07
  • @Romias You are right, it would actually be better to put the div in `position: absolute` with `bottom:0` and `right:0` and place the buttons inside this div where you can position them however you like. – DangerMonkey May 03 '12 at 15:12
  • Absolutely perfect. Thanks for the JSFiddles, helped a ton. – AJ. May 03 '12 at 16:07
6

Relative first, then absolute.

It's quite simple really. The first step is to set the parent container's position property to relative as follows:

<fieldset style="position: relative;">
    ...
</fieldset>

This will set the boundaries for your next element to be positioned, only this time, using absolute positioning.

<div style="position: absolute; bottom: 0; right: 0;">
    <input type="submit" value="Save" />
</div>

Putting the two together:

<fieldset style="position: relative;">

    ...

    <div style="position: absolute; bottom: 0; right: 0;">
        <input type="submit" value="Save" />
    </div>
</fieldset>

After this, you can add some margin to this div tag (or pull away from the bottom right corner a little) to add some padding, throw in some styles, etc.

Matt Borja
  • 1,509
  • 1
  • 17
  • 38
0

use following CSS for buttons (please adjust margins)

position: relative;
margin-top: 45%;
margin-left: 90%;
rt2800
  • 3,045
  • 2
  • 19
  • 26