html - 无法在字段集顶部留出 <legend>

标签 html css

我有一个 fieldset 工作 - 这是代码:

                            <fieldset>
                            <legend>Signed In Users (220)</legend>
                            <div>
                                <div class="new_user"><span>Welcome to the new user:&nbsp;<strong>Name_name</strong></span></div>
                                <div class="logusers">Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin, Admin</div>
                                <div class="ranks">
                                    Admins | Admins | Admins | Admins | Admins | Admins | Admins | Admins | Admins | Admins | Admins | Admins 
                                </div>
                            </div>
                        </fieldset>   

在 CSS 中:

fieldset {
display: table-cell;
width: 100;
border: 1px solid gray !important;
border-radius: 5px;
border-top-right-radius: 0 !important;
background-color: #d3e1e5 }
legend {
    width: inherit !important;
    padding: 0 5px !important;
    background-color: #d3e1e5;
    border-style: none none !important;
    text-align: right !important;
    border-left: 1px solid gray !important;
    border-right: 1px solid gray !important;
    border-top: 1px solid gray !important;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    margin-right: -1px !important;
    margin-top: -9px !important;
}

我让它在 firefox 中工作,这就是它的外观以及我希望它在所有浏览器中的外观 - Firefox 这就是它在不同浏览器中的外观,例如。 Chrome 。 Chrome

我真的很感激任何帮助:) 非常感谢大家!

  • 非常感谢大家。我知道我应该使用 position: absolute。非常感谢您的帮助:>

最佳答案

试试这个 CSS。我已经删除了 !important 的使用,因为它不是必需的,并且如果您稍后尝试覆盖 .css 文件中的任何 css 可能会给您带来问题。

我还将常用样式组合在一起并使用“position:absolute;”就像其他答案所建议的那样。

fieldset, legend{
    border: 1px solid gray;
    background-color: #d3e1e5;
    border-radius: 5px;
    margin: 0px;
}
fieldset {
    border-top-right-radius: 0;
    margin-top: 20px; /*put a margin above the fieldset to leave space for the legend*/
    position:relative; 
}
legend {
    padding: 0 5px;
    text-align: right;
    border-bottom: none;
    border-bottom-left-radius: 0px;
    border-bottom-right-radius: 0px;
    position:absolute; /*absolutely position the legend*/
    right:-1px; /*position the legend 1px to the right so that it overlaps the border*/
    top:-19px; /*position the legend 1px down from the top that it overlaps the border*/
}

关于html - 无法在字段集顶部留出 <legend>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26020531/

相关文章:

css - 2个div,一个最左,一个最右,调整窗口大小时,需要第二个div跳到下一行,但出现在最左边

jquery - 如何通过单击html中另一个页面中的链接使类在另一个页面上处于事件状态

html - 网格系统使页脚过度到页面顶部

javascript - 如何添加base64编码图像的路径

html - 如何制作一个具有两个屏幕大小的 div 的可滚动 flexbox?

html - 悬停链接未覆盖导航栏的整个高度

javascript - 悬停展开导航,而不是点击触发器?

html - Chrome DevTools 尺寸与标尺或设备尺寸不匹配

javascript - 如何制作所有条形以相同速度增长的条形图动画?

CSS 悬停更改所有类