Я пытаюсь скрыть и показать некоторые строки моей таблицы HTML с помощью переключателя. Мне нужно отобразить кнопку переключения после таблицы, я могу отобразить кнопку только перед своей таблицей. Как я могу настроить это? Тай
/*Use CSS to hide the rows of the table that is next to check box that is next to an element with a class of tableToggle*/
.tableToggle + input[type = "checkbox"]:checked + table>tbody>tr:nth-child(n+2) {
display: none;
}
/*Hide the checkbox*/
.tableToggle + input[type = "checkbox"] {display:none;}
/*Button Styling only -- noting important here*/
.tableToggle{
background-color:#44c767;
-moz-border-radius:28px;
-webkit-border-radius:28px;
border-radius:28px;
border:1px solid #18ab29;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:Arial;
padding:5px;
text-decoration:none;
text-shadow:0px 1px 0px #2f6627;
}
<label class = "tableToggle" for = "cb1">Toggle Rows</label><input id = "cb1" type = "checkbox" checked = "checked">
<table>
<thead>
<tr>
<th>Head 1</th>
<th>Head 2</th>
<th>Head 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>R1 C1</td>
<td>R1 C2</td>
<td>R1 C3</td>
</tr>
<tr>
<td>R2 C1</td>
<td>R2 C2</td>
<td>R2 C3</td>
</tr>
<tr>
<td>R3 C1</td>
<td>R3 C2</td>
<td>R3 C3</td>
</tr>
</tbody>
</table>
Я хочу получить таблицу и кнопку внизу, я хочу сохранить логику с кнопкой-переключателем, но если кнопка находится под таблицей, логика переключения не работает. Работает только если кнопка над столом
просто вырежьте первую строку и вставьте ее после тега таблицы.
правильный HTML-код:
<table>
<thead>
<tr>
<th>Head 1</th>
<th>Head 2</th>
<th>Head 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>R1 C1</td>
<td>R1 C2</td>
<td>R1 C3</td>
</tr>
<tr>
<td>R2 C1</td>
<td>R2 C2</td>
<td>R2 C3</td>
</tr>
<tr>
<td>R3 C1</td>
<td>R3 C2</td>
<td>R3 C3</td>
</tr>
</tbody>
</table>
<label class = "tableToggle" for = "cb1">Toggle Rows</label><input id = "cb1" type = "checkbox" checked = "checked">
объясните проблему правильно, пожалуйста.
Не работает, моя логика переключения отображает/не отображает, работает только если кнопка над столом
Добро пожаловать!
.container {
display: flex;
flex-direction: column-reverse;
}
table {
display: block;
}
/*Use CSS to hide the rows of the table that is next to check box that is next to an element with a class of tableToggle*/
.tableToggle+input[type = "checkbox"]:checked+table>tbody>tr:nth-child(n+2) {
display: none;
}
/*Hide the checkbox*/
.tableToggle+input[type = "checkbox"] {
display: none;
}
/*Button Styling only -- noting important here*/
.tableToggle {
background-color: #44c767;
-moz-border-radius: 28px;
-webkit-border-radius: 28px;
border-radius: 28px;
border: 1px solid #18ab29;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
padding: 5px;
text-decoration: none;
text-shadow: 0px 1px 0px #2f6627;
}
<div class = "container">
<label class = "tableToggle" for = "cb1">Toggle Rows</label><input id = "cb1" type = "checkbox" checked = "checked">
<table>
<thead>
<tr>
<th>Head 1</th>
<th>Head 2</th>
<th>Head 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>R1 C1</td>
<td>R1 C2</td>
<td>R1 C3</td>
</tr>
<tr>
<td>R2 C1</td>
<td>R2 C2</td>
<td>R2 C3</td>
</tr>
<tr>
<td>R3 C1</td>
<td>R3 C2</td>
<td>R3 C3</td>
</tr>
</tbody>
</table>
</div>
Что ты имеешь в виду? Что именно вы хотите получить?