简体   繁体   English

如何仅删除字段集边界,而不删除字段集内元素的边界?

[英]How to remove fieldset border only but not the border of elements inside the fieldset?

Example below 下面的例子

I have a form with a fieldset and a button. 我有一个带有字段集和按钮的表单。 Both button and fieldset have borders around them. 按钮和字段集都带有边框。 I want the border gone only for the fieldset. 我希望边框仅适用于字段集。 How? 怎么样?

(The CSS in my example removes both borders - for fieldset and for button when I want button to remain untoched) (我的示例中的CSS删除了两个边框-当我希望按钮保持不弯曲时,用于字段集和按钮)

 #select_spec_form #submit_button { border: 0; } 
 <form id="select_spec_form"> <fieldset id="submit_button"> <input name="submit[submit]" id="submit_button" value="View" type="submit"> </fieldset> </form> 

Simply change the selector to only select the fieldset #select_spec_form fieldset . 只需将选择器更改为仅选择#select_spec_form fieldset Also don't use same ID with two different elements. 同样不要将相同的ID与两个不同的元素一起使用。

 /* Remove the ID from selector if you want to select all the fieldset in the same page and container */ #select_spec_form fieldset#another_ID { border: 0; } 
 <form id="select_spec_form"> <fieldset id="another_ID"> <input name="submit[submit]" id="submit_button" value="View" type="submit"> </fieldset> </form> 

First things first: you cannot use the same id for multiple elements. 首先,您不能对多个元素使用相同的ID。 if you need to do this for css use the class attribute instead. 如果您需要为CSS执行此操作,请改用class属性。

When it comes to the CSS you must refer to each object separately even though they both share the parent #select_spec_form. 当涉及CSS时,即使它们都共享父级#select_spec_form,也必须分别引用每个对象。

 #select_spec_form fieldset{ border:1px solid red; } #select_spec_form input{ border:1px solid black; } 
 <form id="select_spec_form"> <fieldset> <input name="submit[submit]" id="submit_button" value="View" type="submit"> </fieldset> </form> 

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

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