简体   繁体   English

格式化有些麻烦

[英]Having some troubles with formatting

Having some troubles formatting my I thought I was doing it right, but I guess not. 格式化时遇到了一些麻烦,我以为我做对了,但我想不是。 I want the width to be longer, and the color on it to be brownish. 我希望宽度更长,并且其颜色为褐色。 I also want my radio buttons to all be on the same line, and to the left of the words like so. 我还希望我的单选按钮都在同一行上,并在单词的左边。

o School o College o University

What am I doing wrong? 我究竟做错了什么? Here's my code so far. 到目前为止,这是我的代码。

<!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>

Fiddle > http://jsfiddle.net/9m5kekuc/ 小提琴> http://jsfiddle.net/9m5kekuc/

UPDATED Working Demo > http://jsfiddle.net/08k8m6eo/ 更新的工作演示> http://jsfiddle.net/08k8m6eo/

Issue 1: Simply Wrap the radio buttons in a separate <div> to put them in single line. 问题1:只需将单选按钮包装在单独的<div>以将它们放在一行中。

Updated Code: 更新的代码:

       <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>

Issue 2: Fix the layout : 问题2:修复布局:

Updated code: HTML 更新的代码: 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>

UPDATED CSS 更新的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*/
    }

NEW UPDATE: 新更新:

To Put Both Boxes in the Center of the screen Add " margin:0 auto; " property in both " #calender " and " #meetingDetails " 将两个框都放置在屏幕中央将“ margin:0 auto; ”属性添加到“ #calender ”和“ #meetingDetails ”中

Here is the Code: 这是代码:

#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*/
}

Note: Updated the fiddle as per new request! 注意:根据新要求更新了小提琴!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM