标签和输入的对齐

时间:2014-05-26 18:32:32

标签: html css forms input

我正在尝试使标签和范围输入字段移动到同一行。

研究建议设置display: inline-block,但这不起作用。

据我所知,没有相互冲突的风格,所有的研究都表明这应该有效。

HTML

<form id="msform" method="post" action="quoteresult.php">
    <!-- progressbar -->
    <ul id="progressbar">
        <li class="active">Debts</li>
        <li>Assets</li>
        <li>Contact</li>
    </ul>
    <!-- fieldsets -->
    <fieldset>
        <h2 class="fs-title" style="margin-bottom: 0px;">What You Owe</h2>
        <h3 class="fs-subtitle">Your companys financial possition</h3>
        <label style="display:inline-block;" for="overdraft">Overdraft:</label><input type="range" name="overdraft" id="overdraft" value=0 min=0 max=1000000 step="500" />
        <output for="overdraft">1</output>
        <label for="vat">VAT:</label>
        <input type="range" name="vat" id="vat" value=0 min=0 max=1000000 step="500" />
        <output for="vat">1</output>
        <label for="paye">PAYE:</label>
        <input type="range" name="paye" value=0 min=0 max=1000000 step="500"/>
        <output for="paye">1</output>
        <label for="corporationtax">Corporation Tax:</label>
        <input type="range" name="corporationtax" value=0 min=0 max=1000000 step="500" />
        <output for="corporationtax">1</output>
        <label for="tradecreditors">Trade Creditors:</label>
        <input type="range" name="tradecreditors" value=0 min=0 max=1000000 step="500"  />
         <output for="tradecreditors">1</output>
         <label for="rent">Rent:</label>
        <input type="range" name="rent" value=0 min=0 max=1000000 step="500" />
        <output for="rent">1</output>
        <input type="button" name="next" class="next action-button" value="Next" />
    </fieldset>
    <fieldset>
        <h2 class="fs-title" style="margin-bottom: 0px;">Asset Values</h2>
        <h3 class="fs-subtitle">What are you assets worth?</h3>
        <label for="debtors">Debtors:</label>
        <input type="range" name="debtors" value=0 min=0 max=1000000 step="500" />
        <output for="debtors">1</output>
        <label for="fixtures">Fixtures:</label>
        <input type="range" name="fixtures"  value=0 min=0 max=1000000 step="500"/>
        <output for="fixtures">1</output>
        <label for="stock">Stock:</label>
        <input type="range" name="stock" value=0 min=0 max=1000000 step="500" />
        <output for="stock">1</output>
        <label for="vehicles">Vehicles:</label>
        <input type="range" name="vehicles" value=0 min=0 max=1000000 step="500" />
        <output for="vehicles">1</output>
        <label for="cash">Cash:</label>
        <input type="range" name="cash" value=0 min=0 max=1000000 step="500" />
        <output for="cash">1</output>
        <label for="plant">Plant/Machinery:</label>
        <input type="range" name="plant" value=0 min=0 max=1000000 step="500"/>
        <output for="plant">1</output>
        <label for="property">Property:</label>
        <input type="range" name="property" value=0 min=0 max=1000000 step="500" />
        <output for="property">1</output>
        <label for="other">Other:</label>
        <input type="range" name="other" value=0 min=0 max=1000000 step="500" />
        <output for="other">1</output>
        <input type="button" name="previous" class="previous action-button" value="Previous" />
        <input type="button" name="next" class="next action-button" value="Next" />
    </fieldset>
    <fieldset>
        <h2 class="fs-title"  style="margin-bottom: 0px;">Personal Details</h2>
        <h3 class="fs-subtitle">We will never sell it</h3>
        <input type="text" name="fname" placeholder="First Name" />
        <input type="text" name="lname" placeholder="Last Name" />
        <input type="text" name="company" placeholder="Company Name" />
        <input type="text" name="phone" placeholder="Phone" />
        <input type="text" name="email" placeholder="Email" />
        <input type="button" name="previous" class="previous action-button" value="Previous" />
        <input type="submit" name="submit" class="submit action-button" value="Submit" />
    </fieldset>
</form>

CSS

/*custom font*/
@import url(http://fonts.googleapis.com/css?family=Montserrat);

/*basic reset*/
* {margin: 0; padding: 0;}

html {
    height: 100%;
    /*Image only BG fallback*/
    background: url('http://thecodeplayer.com/uploads/media/gs.png');
    /*background = gradient + image pattern combo*/
    background: 
        linear-gradient(rgba(196, 102, 0, 0.2), rgba(155, 89, 182, 0.2)), 
        url('http://thecodeplayer.com/uploads/media/gs.png');
}

body {
    font-family: montserrat, arial, verdana;
}
/*form styles*/
#msform {
    width: 95%px;
    margin: 0px auto;
    text-align: center;
    position: relative;
}
#msform fieldset {
    background: white;
    border: 0 none;
    border-radius: 3px;
    box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4);
    padding: 10px 15px;

    box-sizing: border-box;
    width: 80%;
    margin: 0 10%;

    /*stacking fieldsets above each other*/
    position: absolute;
}
/*Hide all except first fieldset*/
#msform fieldset:not(:first-of-type) {
    display: none;
}
/*inputs*/
#msform input, #msform textarea {
    padding: 15px;
    border: 1px solid #ccc;
    border-radius: 3px;
    margin-bottom: 10px;
    width: 100%;
    box-sizing: border-box;
    font-family: montserrat;
    color: #2C3E50;
    font-size: 13px;
    display:inline-block;}

#msform label {
    display:inline-block;
}

/*buttons*/
#msform .action-button {
    width: 100px;
    background: #27AE60;
    font-weight: bold;
    color: white;
    border: 0 none;
    border-radius: 1px;
    cursor: pointer;
    padding: 10px 5px;
    margin: 10px 5px;
}
#msform .action-button:hover, #msform .action-button:focus {
    box-shadow: 0 0 0 2px white, 0 0 0 3px #27AE60;
}
/*headings*/
.fs-title {
    font-size: 15px;
    text-transform: uppercase;
    color: #2C3E50;
    margin-bottom: 10px;
}
.fs-subtitle {
    font-weight: normal;
    font-size: 13px;
    color: #666;
    margin-bottom: 20px;
}
/*progressbar*/
#progressbar {
    margin-bottom: 30px;
    overflow: hidden;
    /*CSS counters to number the steps*/
    counter-reset: step;
}
#progressbar li {
    list-style-type: none;
    color: white;
    text-transform: uppercase;
    font-size: 9px;
    width: 33.33%;
    float: left;
    position: relative;
}
#progressbar li:before {
    content: counter(step);
    counter-increment: step;
    width: 20px;
    line-height: 20px;
    display: block;
    font-size: 10px;
    color: #333;
    background: white;
    border-radius: 3px;
    margin: 0 auto 5px auto;
}
/*progressbar connectors*/
#progressbar li:after {
    content: '';
    width: 100%;
    height: 2px;
    background: white;
    position: absolute;
    left: -50%;
    top: 9px;
    z-index: -1; /*put it behind the numbers*/
}
#progressbar li:first-child:after {
    /*connector not needed before the first step*/
    content: none; 
}
/*marking active/completed steps green*/
/*The number of the step and the connector before it = green*/
#progressbar li.active:before,  #progressbar li.active:after{
    background: #27AE60;
    color: white;
}

.msform label, .myfields input {

}

.msform label {
  width:200px; /* or whatever size you want them */
}

1 个答案:

答案 0 :(得分:0)

错!

#msform {
text-align: center;
}

正确的例子

<form id="msform" method="post" action="quoteresult.php">
<fieldset>
<div id="box">
<label for="overdraft">Overdraft:</label>
<input type="range" name="overdraft" id="overdraft" value=0 min=0 max=1000000 step="500" required/>
<output for="overdraft">1</output>
</div>
<div id="box">
<label for="vat">VAT:</label>
<input type="range" name="vat" id="vat" value=0 min=0 max=1000000 step="500" required/>
<output for="vat">1</output>
</div>
</fieldset>
</form>

CSS

#msform fieldset{
    background: white;
    border: 0 none;
    border-radius: 3px;
    box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4);
    padding: 10px 15px;

    box-sizing: border-box;
    width: 80%;
    margin: 0 10%;

    /*stacking fieldsets above each other*/
    position: absolute;
}
#box{
    display:inline-block;
    background-color:green;
    width:100%;
    text-align:center;
    /*not is important*/
    margin-top:1px;
}
input[type=range] {
    -webkit-appearance: none;
    background-color: silver;
    width: 200px;
    border: 1px solid #ccc;
    width: 80%;
}

input[type="range"]::-webkit-slider-thumb {
     -webkit-appearance: none;
    background-color: #666;
    opacity: 0.5;
    width: 10px;
    height: 26px;
}