10

以下CSS:

#contactform {
    width: 400px;
    height: 215px;
}

.webform {
}

.webform input .name {
    width: 50px;
}

.webform input .email {
    width: 70px;
}

.webform input .comments {
    width: 200px;
}

当在 html 中用作

    <div id="contactform">
        <div class="webform">
            <input class="name" name="Name" type="text" id="senderName" placeholder="Enter your name here">
            <input class="email" name="Email" type="text" id="senderEmail" placeholder="Enter a valid email adress here">
            <br>
            <input class="comments" name="Comments" type="text" id="senderComments" placeholder="Comments...">
        </div>
    </div>

生成相同宽度的所有三个输入字段(50px = 即 的宽度webform input)。我不确定我做错了什么。帮助?

4

2 回答 2

9

您的课程在您input的 s 上,而不是在 s 的子元素上input。所以改变input .name,等等,input.name或者只是.name,对所有三个重复。:)

于 2012-06-23T18:51:01.647 回答
5

删除输入和类名之间的空格

.webform input.name {
    width: 50px;
}

.webform input.email {
    width: 70px;
}

.webform input.comments {
    width: 200px;
}

试试这个小提琴

于 2012-06-23T18:51:52.513 回答