1

I am trying to learn table-less design and having a difficult time with something that should be easy

I am trying to make a save or cancel button at the bottom right of the screen in the designer it looks good but in the browser (IE and Chrome) the buttons move into the the right part of the form

Top Is Design Mode Bottom Is Browser

I have tried height auto and leaving it out all together. If I fix the height of the main div then it works, but I don't always know that height. Is there anyway to make the buttons "flow" at the bottom of the main div?

Thank You

The Code

    <%@ Page Title="" Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="NewAccount.aspx.cs" Inherits="BudgetApplicationCSharp.NewAccount" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
  <style type="text/css" media="screen">
      #container
      {
          width:500px;
          margin: 5px;           
      }
      #main 
      {
          width:500px;
          height:auto;
          margin:1px;  
      }
      #left 
      {
          float:left;
          width:50%;
          padding-left:0px;
          margin:0px;

      }
      #right
      {
          float:right;
          width:50%
      }
      ol 
      {
          list-style:none;
      }
      input[type=button]
      {
          float:right;
          clear:right;
      }
       input[type=Text]
      {
           font:15px "MS Sans Serif";
      }
      label 
      {
          font:15px "MS Sans Serif";

      }
      fieldset 
      {
          padding:0px;
          margin:0px;
          border:0px none;
      }
      ol 
      {
          padding:0px;
          margin:0px;
          border:0px none;
      }
  </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="container">
    <div id="main">
        <div id="left">
            <fieldset>
                <ol>
                    <li>
                        <label for="AccountName">
                            Account Name</label>
                        <input id="AccountName" runat="server" />
                    </li>
                    <li>
                        <label for="Description">
                            Description</label>
                        <input id="Description" runat="server" />
                    </li>
                    <li>
                        <label for="InstituteName">
                            Institute Name</label>
                        <input id="InstituteName" runat="server" />
                    </li>
                    <li>
                        <label for="AccountType">
                            Institute Name</label>
                        <select id="cboAccountType" runat="server">
                        </select>
                    </li>
                </ol>
            </fieldset>
        </div>
        <div id="right">
            <fieldset>
                <ol>
                    <li>
                        <label for="AccountNumber">
                            Account Number</label>
                        <input id="AccountNumber" runat="server" />
                    </li>
                    <li>
                        <label for="RoutingNumber">
                            Routing Number</label>
                        <input id="RoutingNumber" runat="server" />
                    </li>                       
                </ol>
            </fieldset>
        </div>
    </div>
    <div id="buttons">
    <input id="btnSave" type="button" value="Save" runat="server" />
    <input id="btnCancel" type="button" value="Cancel" runat="server" />
    </div>
</div>
</asp:Content>
Mike
  • 5,918
  • 9
  • 57
  • 94
  • 2
    Use what is suitable to you, don't increase your markup unnecessarily just to ignore tables for no good reason, tables are often used to design form or report layouts so you can use tables, so don't mess up your markup and increase the styles – Mr. Alien Oct 30 '12 at 18:56
  • 2
    Very bad advice by Mr. Alien. Tables should be used for data presentation only. nothing more. surely not to design a webpage. your `buttons` div should have a clear both. – Rafael Herscovici Oct 30 '12 at 18:59
  • 1
    Since this IS a simple form for data entry, there is nothing wrong with tables. But, you could use divs as cells and do display: in-line block and nest them within other divs to create rows. This will give you greater flexability than tables – AntLaC Oct 30 '12 at 19:04
  • 1
    http://stackoverflow.com/questions/2164686/best-practice-for-making-web-forms - nothing more to say. – Rafael Herscovici Oct 30 '12 at 19:15
  • @Dementic what is the minimum number columns/rows to qualify as tabular data? Is it 3x3? How about 3x2 or 2x2? If you search a collection of tabular data and only get a single result, do you display it in something other than a table? Did it stop being tabular data because there's only 1 result? A data entry form is typically a single record of a collection of tabular data. To say that it shouldn't belong in a table is nonsense. – cimmanon Oct 30 '12 at 20:57
  • tabular data is DATA. not forms, not buttons, not text, NOT ANYTHING THAT IS NOT DATA. simple as that. if you still dont understand, it is a result of a query on any kind of DB, not the how to enter the things into the database. and entry row (as you claim) IS STILL NOT A RESULT. one result is still tabular data, 1,000,000 results are also. Data entry forms on the other hand, ARE NOT TABULAR DATA. they are ENTRY forms. would you use toilet paper to address your government? why not? it is still paper... – Rafael Herscovici Oct 30 '12 at 20:58

4 Answers4

4

this is a floating-problem. you need some kind of "clearfix". in your case i would add an overflow:hidden; to #main... this will create a new box model context, which will solve your issue. here you got a jsfiddle to demonstrate this behaviour (just remove the overflow:hidden there to see the difference) -> http://jsfiddle.net/3k3yd/

mr.alex
  • 503
  • 1
  • 8
  • 16
  • Can you explain why to add an `overflow:hidden` and what will be the result of that? jsfiddle if possible. – Rafael Herscovici Oct 30 '12 at 19:01
  • `overflow: hidden` will create a new box model context which has the effect of causing an element with floated children to expand around that content. – Kevin Boucher Oct 30 '12 at 19:06
  • because the floating elements are children of #main... overflow: hidden; is clearing this... he has no elements inside #main that need to be visible. and here you got the js-fiddle http://jsfiddle.net/3k3yd/ – mr.alex Oct 30 '12 at 19:07
  • Yes solving the issue that occurs with floated nested divs in relation to the height of their container. – Kevin Bowersox Oct 30 '12 at 19:08
  • Now that you answered my question, it makes you answer complete. You should add it to your answer and make it complete. (and then i could also vote you up). Teach a man to fish.... – Rafael Herscovici Oct 30 '12 at 19:15
4

Adding the style rule #buttons { clear: both; } should cause the button div to go below the floated divs.

Tom Smilack
  • 2,057
  • 15
  • 20
2

Add

overflow: auto 

to the #main definition.

This solves what others have said without the need for additional markup (ie adding an empty div)

Here's a fiddle with the result.

Forty-Two
  • 7,535
  • 2
  • 37
  • 54
0

Your experiencing an issue common across browsers that occurs when you float two divs within a container. The issue is that the container's height does not expand to the height of the floated divs within it. The fix to this issue is commonly referred to as the clearfix.

I have applied the clearfix to your markup in this example: http://jsfiddle.net/3D7hz/

It adds this styling to your stylesheet:

/* float clearing for IE6 */
* html .clearfix{
  height: 1%;
  overflow: visible;
}

/* float clearing for IE7 */
*+html .clearfix{
  min-height: 1%;
}

/* float clearing for everyone else */
.clearfix:after{
  clear: both;
  content: ".";
  display: block;
  height: 0;
  visibility: hidden;
  font-size: 0;
}

And adds the clearfix class to your main element in the markup:

 <div id="main" class="clearfix">

This link describes the clearfix problem in detail: http://www.positioniseverything.net/easyclearing.html

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189