skip to Main Content

I used tables for my layout but I must use DIVs instead because I have forms in my tables. It was a mistake rendering the code with tables because it has forms and the form functionality is experiencing unwanted sideeffects from using tables so I must use DIVs instead for the layout. Can you help me how I achieve my layout with no tables?

enter image description here

Here’s a fiddle with my code. The html is

<body>

<div id="wrapper">
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- v2 -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:728px;height:15px"
         data-ad-client="ca-pub-7211665888260307"
         data-ad-slot="9119838994"></ins>
    <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

    <div id="border1"></div>

<div id="searchbox">

<form id="search_form" action="/account/do_login" method="post">


        <div class="div-table">

            <div class="div-table-row">
                <div class="div-table-col">LOG IN</div>
                <div class="div-table-col"><input name="email" size="35" title="email" type="text"
                        ></div>
                <div class="div-table-col"><input name="password" size="35" title="password" type="password"
                        ></div>
                <div class="div-table-col"> <input value="Login" type="submit"></div>   <div class="div-table-col"> </div>
            </div>
            <div class="div-table-row">
                <div class="div-table-col logintext">YOUR E-MAIL</div>
                <div class="div-table-col logintext">PASSWORD</div>
            </div>
    </form>

    <form autocomplete="off" id="create_user" action="/create/" method="post">

        <div class="div-table">

            <div class="div-table-row">
                <div class="div-table-col">CREATE ACCOUNT</div>
                <div class="div-table-col"><input name="email" size="35" title="email" type="text"
                        ></div>
                <div class="div-table-col"><input name="password" size="35" title="password" type="password"
                        ></div>
                <div class="div-table-col">  <input value="Create Account" type="submit"></div>
                <div class="div-table-col"> </div>
            </div>
            <div class="div-table-row">
                <div class="div-table-col logintext">YOUR E-MAIL</div>
                <div class="div-table-col logintext">PASSWORD</div>
            </div>

            <div class="div-table-row">
                <div class="div-table-col">OR LOG IN WITH</div>
                <div class="div-table-col"><a href="/auth/google"><img id="googlelink" alt="Login with google" src="/_/img/transparent.gif"></a></div> <div class="div-table-col"><a href="/auth/linkedin"> <img id="linkedinlink" alt="Login with linkedin" src="/_/img/transparent.gif"></a></div>
                <div class="div-table-col"><a href="/auth/yahoo"><img id="yahoolink" alt="Login with yahoo" src="/_/img/transparent.gif"> </a></div>  <div class="div-table-col"><a href="/auth/facebook"> <img id="facebooklink" alt="Login with facebook" src="/_/img/transparent.gif"></a></div>

            </div>

        </div>

</form>


</div>
    <div id="recover"><a href="/passwordreset/"><div class="reminderlink">CLICK HERE TO RECOVER YOUR ACCOUNT</div></A></div>



</div>


</body>
</html>

After a while I tried it with bootstrap which didn’t work at all:

<!DOCTYPE html>
<html dir="ltr" lang="en-IN" class="js">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta name="description"
          content="Find free ads about all different kind of items for sale in {% if regionname and regionname != 'None' %}{{regionname}}{% else %}{% if cityname and cityname != 'None' %}{{cityname}}{% else %}{% if country and country != 'None' %}{{country}}{% endif %}{% endif %}{% endif %}">
    <meta name="googlebot" content="noarchive">
    {% if cursor %}
    <link rel="next" href="/delhi/?o=2">
    {% endif %}
    <link rel="canonical" href="/q">

    <title>Login / Create</title>
    <!-- CSS INCLUDES: -->

    <link href="/static/css/koolindex_in.css?{{VERSION}}" rel="stylesheet" type="text/css">
    <!-- Latest compiled and minified CSS -->
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">

    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

    <!-- HEADEXTRAS: -->

    <link rel="icon" href="/img/favicon_in.ico?07217" type="image/x-icon">
    <!--
        <link rel="shortcut icon" href="/img/favicon_in.ico?07217" type="image/x-icon">
        <link rel="shortcut icon" href="/img/favicon_in.png?07217" type="image/png">
        <link rel="apple-touch-icon" href="/img/favicon_ios_in.png?07217" type="image/png">
        <link rel="icon" href="/img/favicon_us.ico?51340" type="image/x-icon">
            <link href="https://plus.google.com/123122342342345" rel="publisher">-->

    <!-- JAVASCRIPTS: -->
    <script type="text/javascript" src="/static/js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="/static/js/common.min.js"></script>
    <script type="text/javascript" src="/static/js/arrays_v2.js"></script>
    <script type="text/javascript" src="/static/js/searchbox.min.js"></script>

</head>
<body>
{% include "kooltopbar.html" %}


<div id="wrapper">
 {% if request.host == "www.koolbusiness.com"  %}
<a href="/">
    <h1 id="logo" class="sprite_index_in_in_en_logo spritetext">koolbusiness.com - The right choice for buying &amp;
        selling in india</h1></a>
{% endif %}


    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- v2 -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:728px;height:15px"
         data-ad-client="ca-pub-7211665888260307"
         data-ad-slot="9119838994"></ins>
    <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

    <div id="border1"></div>

<div id="searchbox">
    <div class="container">
<form id="search_form" action="/account/do_login" method="post">

    <div class="row">
        <div class="col-md-1">LOG IN WITH</div>
        <div class="col-md-1"><a href="/auth/google"><img id="googlelink" alt="Login with google" src="/_/img/transparent.gif"></a></div>
        <div class="col-md-1"> <a href="/auth/linkedin"> <img id="linkedinlink" alt="Login with linkedin" src="/_/img/transparent.gif"></a></div>
        <div class="col-md-1"><a href="/auth/yahoo"><img id="yahoolink" alt="Login with yahoo" src="/_/img/transparent.gif"> </a></div>
        <div class="col-md-1"><a href="/auth/facebook"> <img id="facebooklink" alt="Login with facebook" src="/_/img/transparent.gif"></a></div>

    </div>
    <div class="row">
        <div class="col-md-1">LOG IN</div>
        <div class="col-md-1"><input name="email" size="35" title="email" type="text">
        </div>
        <div class="col-md-1"><input name="password" size="35" title="password" type="password"></div>
        <div class="col-md-2"><input value="Login" type="submit"></div>
    </div>
    <div class="row">
        <div class="col-md-1">.col-md-4</div>
        <div class="col-md-2 logintext">YOUR E-MAIL</div>
        <div class="col-md-2 logintext">PASSWORD</div>
    </div>

    </form>

    <form autocomplete="off" id="create_user" action="/create/" method="post">
        <div class="row">
            <div class="col-md-1">CREATE ACCOUNT</div>
            <div class="col-md-1"><input name="email" size="35" title="email" type="text">
            </div>
            <div class="col-md-1"><input name="password" size="35" title="password" type="password"></div>
            <div class="col-md-2"><input value="Create Account" type="submit"></div>
        </div>


</form>

</div>
</div>
    <div id="recover"><a href="/passwordreset/"><div class="reminderlink">CLICK HERE TO RECOVER YOUR ACCOUNT</div></A></div>



</div>


</body>
</html>

Edit

The way I finally did it was with twitter bootstrap and I’m happy with it. But rearranging everything into DIVs didn’t solve the problem of autocomplete with the form so I had to resort to a dirty trick to clear the form for the create field. Strange thing was that I had to restart everything to make twitter bootstrap work.

enter image description here

<div id="mybox">
    <div class="container">
<form id="search_form" action="/account/do_login" method="post">

    <div class="row">
        <div class="col-md-1">LOG IN WITH</div>
        <div class="col-md-2"><a href="/auth/google"><img id="googlelink" alt="Login with google" src="/_/img/transparent.gif"></a></div>
        <div class="col-md-2"> <a href="/auth/linkedin"> <img id="linkedinlink" alt="Login with linkedin" src="/_/img/transparent.gif"></a></div>
        <div class="col-md-2"><a href="/auth/yahoo"><img id="yahoolink" alt="Login with yahoo" src="/_/img/transparent.gif"> </a></div>
        <div class="col-md-2"><a href="/auth/facebook"> <img id="facebooklink" alt="Login with facebook" src="/_/img/transparent.gif"></a></div>

    </div>
    <div class="row">
        <div class="col-md-1">LOG IN</div>
        <div class="col-md-3">
            <input name="email" size="35" title="email" type="text">
        </div>
        <div class="col-md-3">
            <input name="password" size="35" title="password" type="password">
        </div>
        <div class="col-md-2">
            <input value="Login" type="submit">
        </div>
    </div>
    <div class="row">
        <div class="col-md-1"></div>
        <div class="col-md-3 logintext">YOUR E-MAIL</div>
        <div class="col-md-3 logintext">PASSWORD</div>
    </div>

    </form>

    <form autocomplete="off" id="create_user" action="/create/" method="post">
        <input style="display:none">
        <input type="password" style="display:none">
        <div class="row">
            <div class="col-md-1">CREATE ACCOUNT</div>
            <div class="col-md-3">
                <input name="email" id="email" size="35" autocomplete="off" title="email" type="text" value="">
            </div>
            <div class="col-md-3">
                <input name="password" id="password" size="35" autocomplete="off" title="password" type="password" value="">
            </div>
            <div class="col-md-2">
                <input value="Create Account" type="submit">
            </div>
        </div>


</form>
</table>
</div>
</div>
    <div id="recover"><a href="/passwordreset/"><div class="reminderlink">CLICK HERE TO RECOVER YOUR ACCOUNT</div></A></div>

3

Answers


  1. As you may be discovering, tables should not be used for layout. As a matter of fact, they should only be used for displaying data.

    As far as building a layout with divs, here’s what you need to know to get started.

    Use width, max-width, and min-width to your advantage to create intuitive and responsive layouts.

    Use percent, em, and vh in place of pixels where you can.

    Consider learning and using floats, and clear: both to help with responsive layout.

    Also, consider using the twitter bootstrap CSS framework. Specifically the grid functionality. You can learn it and use it in minutes.

    I hope this helps.

    Login or Signup to reply.
  2. Excuse me but its htmlcss basics. Where exactly your problem is? I only see the problem with top yellow bar which can be fixed by something like this:

    html {
        position:absolute;
        min-width:100%;
    }
    

    But still it looks ugly enough (:

    Login or Signup to reply.
  3. This layout is ridiculously simple, and you’re making it far more complex than it needs to be. I stripped out all the google ad stuff, which you can add back, but there is way more markup here than you need and way more junk.

    Here’s a quick fiddle I threw together in about 10 minutes that gives you the basic layout. I’m sure you can tweak it to the exact dimensions you need.

    http://jsfiddle.net/fop9vLjh/1/

    <style type="text/css">
        body { font-family: sans-serif; }
        #wrapper { width: 900px; margin: 0 auto; }
        div { margin-top: 15px; }
        #login-box { background-color: #ffc801; padding: 10px; }
        span { float: left; width: 10em; }
        #recover { float: right; }
        a { text-decoration: none; }
        input[type='text'],input[type='password'] { width: 18em; }
        .form-field { width: 15em; display: inline-block; vertical-align: top; margin-top: 0; }
        label { display: block; font-size: small; }
    </style>
    
    <div id="wrapper">
        <div id="login-box">
            <div id="login">
                <span>LOGIN</span>
                <form action="/account/do_login" method="post">
                    <div class="form-field">
                        <input name="email" type="text"/>
                        <label for="email">YOUR EMAIL</label>
                    </div>
                    <div class="form-field">
                        <input name="password" type="password"/>
                        <label for="password">PASSWORD</label>
                    </div>
                    <button type="submit" value="Login">Login</button>
                </form>
            </div>
            <div id="create">
                <span>CREATE ACCOUNT</span>
                <form autocomplete="off" id="create_user" action="/create/" method="post">
                    <div class="form-field">
                        <input name="email" type="text"/>
                        <label for="email">YOUR EMAIL</label>
                    </div>
                    <div class="form-field">
                        <input name="password" type="password"/>
                        <label for="password">DESIRED PASSWORD</label>
                    </div>
                    <button type="submit" value="Create">Create Account</button>
                </form>
            </div>
            <div id="alt-login">
                <span>OR LOG IN WITH</span>
                <input name="google" type="image" src="#"/>
                <input name="linkedin" type="image" src="#"/>
                <input name="yahoo" type="image" src="#"/>
                <input name="facebook" type="image" src="#"/>
            </div>
        </div>
        <div id="recover">
            <a href="">CLICK HERE TO RECOVER YOUR ACCOUNT</a>
        </div>
    </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search