我有一个标准的复选框模板,它可以在一个简单的html页面上工作:
但是,在我的网页上,由于其他css样式的干扰,它没有呈现为复选框。
只有文本可见,没有复选框图标。无法在此处强制执行复选框行为。这可能是因为在我的css文件中,我已经检查了标签和输入的样式。但是,我想强制此标记的默认行为。
*, *:before, *:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 120vh;
}
body {
font: 14px/1 'Open Sans', sans-serif;
color: #555;
background: #eee;
}
h1 {
padding: 20px 0;
font-weight: 100;
text-align: center;
}
p {
margin: 0 0 20px;
line-height: 1.5;
}
main {
min-width: 520px;
/*max-width: 800px;*/
padding: 50px;
margin: 0 auto;
background: #fff;
}
section {
display: none;
padding: 20px 0 0;
border-top: 1px solid #ddd;
}
input {
display: none;
}
label {
display: inline-block;
margin: 0 0 -1px;
padding: 15px 25px;
font-weight: 600;
text-align: center;
color: #bbb;
border: 1px solid transparent;
}
label:before {
font-family: fontawesome;
font-weight: normal;
margin-right: 10px;
}
label[for*='1']:before { content: '\f1cb'; }
label[for*='2']:before { content: '\f17d'; }
label[for*='3']:before { content: '\f16b'; }
label[for*='4']:before { content: '\f1a9'; }
label:hover {
color: #888;
cursor: pointer;
}
input:checked + label {
color: #555;
border: 1px solid #ddd;
border-top: 2px solid orange;
border-bottom: 1px solid #fff;
}
#tab1:checked ~ #content1,
#tab2:checked ~ #content4,
#tab3:checked ~ #content2,
#tab4:checked ~ #content3 {
display: block;
}
@media screen and (max-width: 650px) {
label {
font-size: 0;
}
label:before {
margin: 0;
font-size: 18px;
}
}
@media screen and (max-width: 600px) {
label {
padding: 15px;
}
}
/*Table */
.table-wrapper {
-webkit-overflow-scrolling: touch;
overflow-x: auto;
}
table {
margin: 0 0 2rem 0;
width: 100%;
}
table tbody tr {
border: solid 1px;
border-left: 0;
border-right: 0;
}
table td {
padding: 0.75rem 0.75rem;
}
table th {
font-size: 0.9rem;
font-weight: 700;
padding: 0 0.75rem 0.75rem 0.75rem;
text-align: left;
}
table thead {
border-bottom: solid 2px;
}
table tfoot {
border-top: solid 2px;
}
table.alt {
border-collapse: separate;
}
table.alt tbody tr td {
border: solid 1px;
border-left-width: 0;
border-top-width: 0;
}
table.alt tbody tr td:first-child {
border-left-width: 1px;
}
table.alt tbody tr:first-child td {
border-top-width: 1px;
}
table.alt thead {
border-bottom: 0;
}
table.alt tfoot {
border-top: 0;
}
table tbody tr {
border-color: rgba(144, 144, 144, 0.25);
}
table tbody tr:nth-child(2n + 1) {
background-color: rgba(144, 144, 144, 0.075);
}
table th {
color: #555;
}
table thead {
border-bottom-color: rgba(144, 144, 144, 0.25);
}
table tfoot {
border-top-color: rgba(144, 144, 144, 0.25);
}
table.alt tbody tr td {
border-color: rgba(144, 144, 144, 0.25);
}
<form>
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>
<input type="submit" value="Submit">
</form>
请建议。
如果有助于:
最佳答案
覆盖(或删除(如果可能的话)
input {
display: none;
}
*, *:before, *:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 120vh;
}
body {
font: 14px/1 'Open Sans', sans-serif;
color: #555;
background: #eee;
}
h1 {
padding: 20px 0;
font-weight: 100;
text-align: center;
}
p {
margin: 0 0 20px;
line-height: 1.5;
}
main {
min-width: 520px;
/*max-width: 800px;*/
padding: 50px;
margin: 0 auto;
background: #fff;
}
section {
display: none;
padding: 20px 0 0;
border-top: 1px solid #ddd;
}
input {
display: none;
}
label {
display: inline-block;
margin: 0 0 -1px;
padding: 15px 25px;
font-weight: 600;
text-align: center;
color: #bbb;
border: 1px solid transparent;
}
label:before {
font-family: fontawesome;
font-weight: normal;
margin-right: 10px;
}
label[for*='1']:before { content: '\f1cb'; }
label[for*='2']:before { content: '\f17d'; }
label[for*='3']:before { content: '\f16b'; }
label[for*='4']:before { content: '\f1a9'; }
label:hover {
color: #888;
cursor: pointer;
}
input:checked + label {
color: #555;
border: 1px solid #ddd;
border-top: 2px solid orange;
border-bottom: 1px solid #fff;
}
#tab1:checked ~ #content1,
#tab2:checked ~ #content4,
#tab3:checked ~ #content2,
#tab4:checked ~ #content3 {
display: block;
}
@media screen and (max-width: 650px) {
label {
font-size: 0;
}
label:before {
margin: 0;
font-size: 18px;
}
}
@media screen and (max-width: 600px) {
label {
padding: 15px;
}
}
/*Table */
.table-wrapper {
-webkit-overflow-scrolling: touch;
overflow-x: auto;
}
table {
margin: 0 0 2rem 0;
width: 100%;
}
table tbody tr {
border: solid 1px;
border-left: 0;
border-right: 0;
}
table td {
padding: 0.75rem 0.75rem;
}
table th {
font-size: 0.9rem;
font-weight: 700;
padding: 0 0.75rem 0.75rem 0.75rem;
text-align: left;
}
table thead {
border-bottom: solid 2px;
}
table tfoot {
border-top: solid 2px;
}
table.alt {
border-collapse: separate;
}
table.alt tbody tr td {
border: solid 1px;
border-left-width: 0;
border-top-width: 0;
}
table.alt tbody tr td:first-child {
border-left-width: 1px;
}
table.alt tbody tr:first-child td {
border-top-width: 1px;
}
table.alt thead {
border-bottom: 0;
}
table.alt tfoot {
border-top: 0;
}
table tbody tr {
border-color: rgba(144, 144, 144, 0.25);
}
table tbody tr:nth-child(2n + 1) {
background-color: rgba(144, 144, 144, 0.075);
}
table th {
color: #555;
}
table thead {
border-bottom-color: rgba(144, 144, 144, 0.25);
}
table tfoot {
border-top-color: rgba(144, 144, 144, 0.25);
}
table.alt tbody tr td {
border-color: rgba(144, 144, 144, 0.25);
}
/* ADD THIS */
input {
display: block!important;
}
<form>
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>
<input type="submit" value="Submit">
</form>
关于javascript - 如何强制元素的默认CSS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51354947/