How to style and align forms without tables?

前端 未结 11 2429
梦如初夏
梦如初夏 2020-12-05 04:27

I\'ve gotten used to using

s for aligning my form fields perfectly. This is how I commonly write my forms:

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 05:18

    There are tons of ways out there to do it without tables. Once you get the basic format down it's as easy to work with as tables are, it's just the initial playing around that can be a pain. So, just look to others that have already done the work of figuring it all out for you:

    • http://www.alistapart.com/articles/prettyaccessibleforms
    • http://woork.blogspot.com/2008/06/clean-and-pure-css-form-design.html

    I also documented the method I've settled on last week (a snippet):

    Basic Information
    1. YYYY-MM-DD

    And the CSS:

    fieldset { 
        margin: 0 0 20px 0; } 
    
    fieldset legend { 
        font-weight: bold; 
        font-size: 16px; 
        padding: 0 0 10px 0; 
        color: #214062; } 
    
    fieldset label { 
        width: 170px; 
        float: left; 
        margin-right:10px; 
        vertical-align: top; } 
    
    fieldset ol { 
        list-style:none; 
        margin: 0;
        padding: 0;} 
    
    fieldset ol li { 
        float:left; 
        width:100%; 
        padding-bottom:7px; 
        padding-left: 0; 
        margin-left: 0; } 
    
    fieldset ol li input, 
    fieldset ol li select, 
    fieldset ol li textarea { 
        margin-bottom: 5px; } 
    
    form fieldset div.inputWrapper { 
        margin-left: 180px; } 
    
    .note { 
        font-size: 0.9em; color: #666; }
    
    .error{ 
        color: #d00; }
    

    jsFiddle

提交回复
热议问题