将 Fieldset Legend 与 bootstrap 结合使用 [英] Use Fieldset Legend with bootstrap

查看:59
本文介绍了将 Fieldset Legend 与 bootstrap 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 JSP 页面使用 Bootstrap.

我想将

用于我的表单.这是我的代码.

<legend class="scheduler-border">开始时间</legend><div class="control-group"><label class="control-label input-label" for="startTime">开始:</label><div class="controls bootstrap-timepicker"><input type="text" class="datetime" id="startTime" name="startTime" placeholder="开始时间"/><i class="icon-time"></i>

</fieldset>

CSS 是

fieldset.scheduler-border {边框:1px 凹槽 #ddd !important;填充:0 1.4em 1.4em 1.4em !重要;边距:0 0 1.5em 0 !重要;-webkit-box-shadow: 0px 0px 0px 0px #000;框阴影:0px 0px 0px 0px #000;}Legend.scheduler-border {字体大小:1.2em !重要;字体粗细:粗体!重要;文本对齐:左!重要;}

我得到这样的输出

我想以下面的方式输出

我尝试添加

border:none;宽度:100px;

legend.scheduler-border 在 CSS 中.我得到了预期的输出.但问题是我想为另一个字段添加另一个

.那个时候图例中文本的宽度是一个问题,因为它比 100px 长.

那么我该怎么做才能获得我提到的输出?(不打图例文字)

解决方案

那是因为 Bootstrap 默认将 legend 元素的宽度设置为 100%.您可以通过将 legend.scheduler-border 更改为也使用来解决此问题:

legend.scheduler-border {宽度:继承;/* 或自动 */填充:0 10px;/* 在左侧和右侧提供一点填充 */边框底部:无;}

JSFiddle 示例.

您还需要确保在 Bootstrap 之后添加自定义样式表,以防止 Bootstrap 覆盖您的样式 - 尽管此处的样式应该具有更高的特异性.

您可能还想向其中添加 margin-bottom:0; 以减少图例和分隔线之间的差距.

I'm using Bootstrap for my JSP page.

I want to use <fieldset> and <legend> for my form. This is my code.

<fieldset class="scheduler-border">
    <legend class="scheduler-border">Start Time</legend>
    <div class="control-group">
        <label class="control-label input-label" for="startTime">Start :</label>
        <div class="controls bootstrap-timepicker">
            <input type="text" class="datetime" id="startTime" name="startTime" placeholder="Start Time" />
            <i class="icon-time"></i>
        </div>
    </div>
</fieldset>

CSS is

fieldset.scheduler-border {
    border: 1px groove #ddd !important;
    padding: 0 1.4em 1.4em 1.4em !important;
    margin: 0 0 1.5em 0 !important;
    -webkit-box-shadow:  0px 0px 0px 0px #000;
            box-shadow:  0px 0px 0px 0px #000;
}

legend.scheduler-border {
    font-size: 1.2em !important;
    font-weight: bold !important;
    text-align: left !important;
}

I am getting output like this

I want output in the following way

I tried adding

border:none;
width:100px;

to legend.scheduler-border in CSS. And I'm getting the expected output. But the problem is I would like to add another <fieldset> for another fields. That time the width of text in legend is a problem as it is lengthier than than 100px.

So what shall I do to get output like I have mentioned? (Without striking the legend text)

解决方案

That's because Bootstrap by default sets the width of the legend element to 100%. You can fix this by changing your legend.scheduler-border to also use:

legend.scheduler-border {
    width:inherit; /* Or auto */
    padding:0 10px; /* To give a bit of padding on the left and right */
    border-bottom:none;
}

JSFiddle example.

You'll also need to ensure your custom stylesheet is being added after Bootstrap to prevent Bootstrap overriding your styling - although your styles here should have higher specificity.

You may also want to add margin-bottom:0; to it as well to reduce the gap between the legend and the divider.

这篇关于将 Fieldset Legend 与 bootstrap 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆