html - 标签、输入 - 共享空间(类/分区)

标签 html css class shared

我有很简单的事情要做,但我找不到出路。

假设我有表格,我想在另一个下面添加输入,但是其中一个旁边会有标签(仅在其中一个旁边)。

我想做到这一点,因此所有类的大小都相等(但要使其具有响应性)。但是,我想在输入旁边加上标签,以便与标签共享空间,因此如果用户在小屏幕中打开它,它将彼此相邻,而不是一个在另一个下面。

希望你们明白我的意思。 :P

谢谢!

编辑

<div class="mainbox-form">
    <form>
        <div class="mainbox-input">
            <input type="text" name="store-name" placeholder="Name"><br>
        </div>

        <div class="mainbox-input">
            <input type="text" name="store-subdomain" placeholder="Subdomain">
            <label name="store-subdomain">.label.here</label><br>
        </div>

        <div class="mainbox-input">
            <input type="email" name="store-email" placeholder="Email"><br>
        </div>

        <div class="mainbox-input">
            <input type="password" name="store-password" placeholder="Password"><br>
        </div>

    </form>
</div>


.mainbox-form
{
    text-align: center;
    max-width: 50%;
    min-width: 350px;
    margin: 0 auto 0 auto;
}

.mainbox-input label
{
    font-weight: bold;
    color: #606060;
}

.mainbox-input
{
    max-height: 57px;
}

.mainbox-input input 
{
    background: #f3f3f3;
    width: 80%;
    border: none;
    color: #606060;
    margin: 3px auto 3px auto;
    padding: 15px 40px;
    font-size: 18px;
}


.mainbox-input input[name=store-subdomain]
{
    max-width: 59%;
}

.mainbox-input input:focus
{
    outline: none;
}

.mainbox-input input:active
{
    outline: none;
}

http://jsfiddle.net/twjw113w/

这是我目前获得的代码。我遇到的问题是,带标签的输入没有粘在左边,而且表现不同。我敢打赌,您自己会比我解释的更清楚。

最佳答案

您需要将 display: inline-block 和 width 添加到您希望在同一行的标签和输入元素。

    .mainbox-input label
{
    font-weight: bold;
    color: #606060;
    display:inline-block;
    width:35%;
}
.mainbox-input input[name=store-subdomain]
{
    max-width: 40%;
    display:inline-block;
}

这是您想要的吗? jsfiddle

关于html - 标签、输入 - 共享空间(类/分区),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28378814/

相关文章:

javascript - Jquery/CSS3 转换链接只能部分工作

html - 面板中固定位置的位置按钮

html - 悬停时按钮背景不变

javascript - 使用javascript显示在列表项点击时显示下拉内容的div

c# - JSON 到 XML 类转换

javascript - 为什么我的选择字段事件处理程序在 Chrome/Android 中不起作用?

css - sass 将导入转换为导入 url

javascript - 将鼠标悬停在元素上但不出现在鼠标指针上时,如何显示 div?

java - 为 jar 和类设置类路径

class - scala 类中的两组构造函数参数