简体   繁体   English

<fieldset>没有边界</fieldset>

[英]<fieldset> has no border

I'm trying to use a <fieldset> to group some controls.我正在尝试使用<fieldset>对一些控件进行分组。 No matter what I do I can't get the border to display.无论我做什么,我都无法显示边框。 My understanding is it should display by default.我的理解是它应该默认显示。 In the <style> I've tried setting border-width:1px which does nothing and border:solid draws a border outside of everything including the <legend> .<style>中,我尝试设置border-width:1px什么都不做, border:solid在包括<legend>在内的所有内容之外绘制边框。 I've tested in both Firefox and Chrome and no difference.我已经在 Firefox 和 Chrome 中进行了测试,没有区别。 What am I missing?我错过了什么? Here is an example of my code.这是我的代码示例。 I'm playing with different layouts so ignore the inconsistency.我正在玩不同的布局,所以请忽略不一致之处。

 <div class=" col-4 col-sm-4 col-med-4 col-lg-4 col-xl-4 e-primary" style="justify-content:space-around"> <fieldset> <legend>Project Basics</legend> <ul> <li> <label for="txtName">Name</label> <input type="text" id="txtName" /> </li> <li> <label for="txtDescription">Description</label> <textarea rows=3 cols=20 id="txtDescription"></textarea> </li> </ul> </fieldset> </div> <div class=" col-4 col-sm-4 col-med-4 col-lg-4 col-xl-4 e-primary" style="justify-content:space-around"> <fieldset> <legend>Cost Estimations</legend> <label for="txtEstTotalHrs">Estimated Total Hours</label> <input type="text" id="txtEstTotalHrs" /> <label for="txtEstLaborCost">Estimated Labor Costs</label> <input type="text" id="txtEstLaborCosts" /> </fieldset> </div>

And this is what I'm seeing, no borders.这就是我所看到的,没有边界。 在此处输入图像描述

Update to comments:评论更新:

  • Mushroomator, yes I am using bootstrap. Mushroomator,是的,我正在使用引导程序。 Are you saying to add the whole bootstrap css to the snippet?你是说将整个引导程序 css 添加到代码片段中吗? And I am the designer of the project.我是该项目的设计师。

  • Mike K., Agreed, I am not seeing whats in the plain snippet so something is being overwritten. Mike K.,同意,我没有看到普通代码片段中的内容,因此某些内容被覆盖了。 I wasn't very clear but I did look at the what styles are being applied and at the Fieldset level, if I change the Border setting to 1px it draws an outside box around the fieldset.我不是很清楚,但我确实查看了正在应用的 styles 以及在 Fieldset 级别,如果我将 Border 设置更改为 1px,它会在 fieldset 周围绘制一个外部框。 I added an image from the dev tools.我从开发工具中添加了一个图像。

*JonoJames, I tried adding styling to the tag like this <fieldset style="border-color:black;important: border-style:solid !important"> and I still see nothing. *JonoJames,我尝试像这样向标签添加样式<fieldset style="border-color:black;important: border-style:solid !important">但我仍然什么也没看到。 When I look at the dev tools, it shows those attributes set at the Element level but nothing changes on the front end.当我查看开发工具时,它显示了在元素级别设置的那些属性,但前端没有任何变化。

This should be a simple problem.这应该是一个简单的问题。

Testing Update : I found the references to the bootstrap css in the _Layout.cshtml file so I started commenting them out, one at a time.测试更新:我在 _Layout.cshtml 文件中找到了对 bootstrap css 的引用,所以我开始将它们注释掉,一次一个。 The offender seems to be <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> The only reference to fieldset, other than fieldset:disabled, is in this line.罪犯似乎是<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />除了 fieldset:disabled 之外,唯一对 fieldset 的引用是在这一行中。

fieldset{min-width:0;padding:10rem;margin:10rem;border:10rem}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}

I've tried setting all properties to something other than zero but no effect.我试过将所有属性设置为非零但没有效果。 settings like "10px" or "25rem".设置如“10px”或“25rem”。 Anytime I do get a border, its always an "outside" border like this:任何时候我得到一个边界,它总是一个像这样的“外部”边界: 在此处输入图像描述

You could add a custom border with CSS您可以使用 CSS 添加自定义边框

 .fieldsetColored{ border-color: #F00; border-style: solid; }
 <fieldset class="fieldsetColored"> <legend>box</legend> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <label for="txtEstTotalHrs">Estimated Total Hours</label></br> <input type="text" id="txtEstTotalHrs" /></br> <label for="txtEstLaborCost">Estimated Labor Costs</label></br> <input type="text" id="txtEstLaborCosts" /></br> </tr> </table> </fieldset>

You probably have a conflicting style sheet somewhere that turns the border off If its bootstrap use the !important CSS override style attribute您可能在某个地方有一个冲突的样式表,它关闭了边框如果它的引导程序使用 !important CSS 覆盖样式属性

!important !重要的

looking at the class list <div class=" col-4 col-sm-4 col-med-4 col-lg-4 col-xl-4 e-primary" style="justify-content:space-around">查看 class 列表<div class=" col-4 col-sm-4 col-med-4 col-lg-4 col-xl-4 e-primary" style="justify-content:space-around">

This looks like bootstrap这看起来像引导程序

Finally figured it out.终于想通了。 According to this discussion Fieldset legend does not work everything is turned off for fieldset borders in Bootstrap 5. To get the original alignment of the Legend (inline with the border) you have to set the Legend float:none;根据这个讨论, Fieldset legend does not work一切都在 Bootstrap 5 中关闭了 fieldset borders。要获得 Legend 的原始 alignment(与边框内联),您必须设置 Legend float:none; and width:auto;width:auto;

My final CSS looks like this:我的最终 CSS 看起来像这样:

fieldset {
    margin-bottom: 1em !important;
    border: 1px solid #666 !important;
    padding:1px !important;
}

legend {
    padding: 1px 10px !important;
    float:none;
    width:auto;
}

Thanks for all your input.感谢您的输入。 Reading through your replies a couple times helped me with my troubleshooting.多次阅读您的回复帮助我解决了问题。

This should work!这应该工作!

<fieldset class="border rounded-3 p-3">
   <legend class="float-none w-auto px-3">
      Your Title
   </legend>
   <p>Your content</p>
</fieldset>

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

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