格式化有些麻烦

时间:2014-09-04 20:11:56

标签: html css

有一些麻烦格式化我以为我做得对,但我猜不是。我希望宽度更长,并且它上面的颜色是褐色的。我也希望我的单选按钮全部位于同一行,并且在单词的左侧,如此。

o School o College o University

我做错了什么? 到目前为止,这是我的代码。

<!DOCTYPE html></Applications/MAMP/htdocs/site2/chapter04-project01.html>
<html>
    <head lang="en">
        <meta charset="utf-8">
        <title>Chapter 4</title>
        <link rel="stylesheet" href="reset.css" />
        <link rel="stylesheet" href="chapter04-project01.css" />
        <style>
            body {
                line-height: 1;
                margin: 100px 525px;
            }

            div {
                background: rgba(0, 0, 0, .1);
                border-radius: 5px;
                box-sizing: border-box;
                padding: 0px;
                width: 220px;
            }

            header {
                overflow: clear;
                position: relative;
            }

            cap {
                font-family: Georgia, Cambria, "Times New Roman", serif;
                font-size: 18px;
                font-weight: 700;
                margin: 0 0 10px;
                text-align: center;
            }

            button {
                position: absolute;
                bottom: -4px;
            }

            button:first-child {
                left: 0;
            }

            button:last-child {
                right: 0;
            }

            table {
                background: #fff;
                border-collapse: collapse;
                color: #222;
                font-family: 'Lucida Sans', Verdana, Arial, sans-serif;
                font-size: 13px;
                width: 100%;
            }

            td {
                border: 1px solid #ccc;
                color: #444;
                line-height: 22px;
                text-align: center;
            }

            tr:first-child td {
                color: #222;
                font-weight: 700;
            }

            .selected {
                background: #f0951d;
                border: 0;
                box-shadow: 0 2px 6px rgba(0, 0, 0, .5) inset;
            }

            fieldset {
                background:#B8860B
                color:#B8860B
                width:100%
            }
        </style>
    </head>
    <body style ="text-align:center;">
        <div>
            <header>
                <button>«Sep</button>
                <cap>October 2014</cap>
                <button>Nov»</button>
            </header>
            <table>
                <tr>
                    <td>S</td>
                    <td>M</td>
                    <td>T</td>
                    <td>W</td>
                    <td>T</td>
                    <td>F</td>
                    <td>S</td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                    <td>4</td>
                </tr>
                <tr>
                    <td>5</td>
                    <td>6</td>
                    <td>7</td>
                    <td>8</td>
                    <td>9</td>
                    <td>10</td>
                    <td>11</td>
                </tr>
                <tr>
                    <td>12</td>
                    <td>13</td>
                    <td>14</td>
                    <td>15</td>
                    <td>16</td>
                    <td>17</td>
                    <td>18</td>
                </tr>
                <tr>
                    <td>19</td>
                    <td>20</td>
                    <td>21</td>
                    <td>22</td>
                    <td>23</td>
                    <td>24</td>
                    <td>25</td>
                </tr>
                <tr>
                    <td>26</td>
                    <td>27</td>
                    <td>28</td>
                    <td>29</td>
                    <td>30</td>
                    <td>31</td>
                    <td></td>
                </tr>
            </table>
            <footer>
                <button>«</button>
                <h2>      </h2>
                <button>»</button>
            </footer>
        </div>
        <form method="get" action="process.php">
            <fieldset>
                <legend>Meeting Details</legend>
                <p>
                    <label> Client Name: </label>
                    <input type="text" name="Client Name"/>
                </p>
                <p>
                    <label>First Meeting? </label>
                    <input type="checkbox"name="yes">
                </p>
                <p>
                    <label>Client type:</label>
                    <input type="radio" name="where" value="1">School<input type="radio" name="where" value="2">College <input type="radio" name="where" value="3">University
                </p>
            </fieldset>
        </form>
    </body>
</html>

小提琴&gt; http://jsfiddle.net/9m5kekuc/

1 个答案:

答案 0 :(得分:1)

更新的工作演示&gt; http://jsfiddle.net/08k8m6eo/

问题1:只需将单选按钮包裹在单独的<div>中,即可将它们排成一行。

更新代码:

       <p><label>Client type:</label></p>
       <div>
            <input type="radio" name="where" value="1" />
            <label>School</label>
            <input type="radio" name="where" value="2" />
            <label>College</label>
            <input type="radio" name="where" value="3" />
            <label>University</label>
        </div>

问题2:修复布局:

更新的代码: 的 HTML

<!--Added ID to the Calender DIV so you can give **style** for this particular DIV rather making it generic for all DIVs-->
<div id="calender"> 
    <header>
        <button>«Sep</button>
        <cap>October 2014</cap>
        <button>Nov»</button>
    </header>
    <table>
        <tr>
            <td>S</td>
            <td>M</td>
            <td>T</td>
            <td>W</td>
            <td>T</td>
            <td>F</td>
            <td>S</td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td>1</td>
            <td>2</td>
            <td>3</td>
            <td>4</td>
        </tr>
        <tr>
            <td>5</td>
            <td>6</td>
            <td>7</td>
            <td>8</td>
            <td>9</td>
            <td>10</td>
            <td>11</td>
        </tr>
        <tr>
            <td>12</td>
            <td>13</td>
            <td>14</td>
            <td>15</td>
            <td>16</td>
            <td>17</td>
            <td>18</td>
        </tr>
        <tr>
            <td>19</td>
            <td>20</td>
            <td>21</td>
            <td>22</td>
            <td>23</td>
            <td>24</td>
            <td>25</td>
        </tr>
        <tr>
            <td>26</td>
            <td>27</td>
            <td>28</td>
            <td>29</td>
            <td>30</td>
            <td>31</td>
            <td></td>
        </tr>
    </table>
    <footer>
        <button>«</button>
         <h2>      </h2>

        <button>»</button>
    </footer>
</div>

<!--Wrapped the <form> in a separate <div>, again so you can give **style** for this particular DIV -->
<div id="meetingDetails">
    <form method="get" action="process.php">
        <fieldset>
            <legend>Meeting Details</legend>
            <p>
                <label>Client Name:</label>
                <input type="text" name="Client Name" />
            </p>
            <p>
                <label>First Meeting?</label>
                <input type="checkbox" name="yes" />
            </p>
            <p>
                <label>Client type:</label>
            </p>
<!--Wrapped the "Radio Buttons" in a separate <div>, so they come in a single line -->
            <div>
                <input type="radio" name="where" value="1" />
                <label>School</label>
                <input type="radio" name="where" value="2" />
                <label>College</label>
                <input type="radio" name="where" value="3" />
                <label>University</label>
            </div>
        </fieldset>
</div>

更新CSS

    body {
        line-height: 1;
        margin: 0 auto; /*FIX ADDED*/
        padding:0; /*FIX ADDED*/
        width:100%; /*FIX ADDED*/
    }

 /*FIX ADDED - Removed General DIV and gave style to the Calender ID */
    #calender {
        background: rgba(0, 0, 0, .1);
        border-radius: 5px;
        box-sizing: border-box;
        padding: 0px;
        width: 220px;
        text-align:center; /*FIX ADDED*/
        margin:0 auto; /*NEW FIX FOR CENTER BOX*/
    }

 /*FIX ADDED - Updated style to be Nested for Calender, so elements which are under "#calender" ID, only they get updated */

    #calender header {
        overflow: clear;
        position: relative;
    }
    #calender cap {
        font-family: Georgia, Cambria, "Times New Roman", serif;
        font-size: 14px; /*FIX ADDED*/
        font-weight: 700;
        margin: 0 0 10px;
        line-height:22px; /*FIX ADDED*/
    }
    #calender button {
        position: absolute;
        bottom: -2px; /*FIX ADDED*/
    }
    #calender button:first-child {
        left: 0;
    }
    #calender button:last-child {
        right: 0;
    }
    #calender table {
        background: #fff;
        border-collapse: collapse;
        color: #222;
        font-family:'Lucida Sans', Verdana, Arial, sans-serif;
        font-size: 13px;
        width: 100%;
    }
    #calender td {
        border: 1px solid #ccc;
        color: #444;
        line-height: 22px;
        text-align: center;
    }
    #calender tr:first-child td {
        color: #222;
        font-weight: 700;
    }
    #calender .selected {
        background: #f0951d;
        border: 0;
        box-shadow: 0 2px 6px rgba(0, 0, 0, .5) inset;
    }

/*FIX ADDED - Added style for "Meeting Details box" */

    #meetingDetails {
        background-color: #ccc;
        width:500px;
        margin:0 auto; /*NEW FIX FOR CENTER BOX*/
    }

新更新:

将两个框放入屏幕中心在“margin:0 auto;”和“#calender”中添加“#meetingDetails”属性

以下是代码:

#calender {
    background: rgba(0, 0, 0, .1);
    border-radius: 5px;
    box-sizing: border-box;
    padding: 0px;
    width: 220px;
    text-align:center;
    margin:0 auto; /*NEW FIX FOR CENTER BOX*/
}

#meetingDetails {
    background-color: #ccc;
    width:500px;
    margin:0 auto; /*NEW FIX FOR CENTER BOX*/
}

注意:根据新请求更新了小提琴!