gpt4 book ai didi

php - 使用 CSS 更改文本名称

转载 作者:太空宇宙 更新时间:2023-11-04 14:28:32 25 4
gpt4 key购买 nike

当菜单打开时,我试图将文本从“菜单”更改为“关闭菜单”。我不知道该怎么做。

这是我的 HTML:

<input type="checkbox" id="responsive-nav">
<label for="responsive-nav" class="responsive-nav-label">
<span>&#9776;</span> Menu
</label>

<nav>
<ul>
<li><a href="download.php">Download Apps</a></li>
<li><a href="manual.php">Download Manuals</a></li>
</ul>
</nav>

这是我的 CSS:

/* MENU */

/* hide the checkbox and the label */
input#responsive-nav,
label.responsive-nav-label {
display: none;
font-size: 15pt;
}

/* declarations for the not-responsove-menu */
nav {
width: 220px; /* Darüber laesst sich die breite des Aufklappmenue steuern */
margin-left: -10px;
background: black
}

nav ul {
padding: 0px;
margin-left: -10px;
margin-top: 43px;
}

nav a {
display: block;
background: #FFF;
text-decoration: none;
color: white;
font-size: 15pt;
}

nav ul li {
position: relative;
float: left;
list-style: none;
color: #FFF;
transition: 0.5s;
}

/* Declarations for the responsive menu 1680px */
@media screen and (max-width: 15360px) {

* {
font-size: 15pt;
}

label.responsive-nav-label {
position: relative;
display: block;
padding: 0px;
background: black;
cursor: pointer;
color: #fff;
}

nav {
position: absolute;
top: -9999px;
padding: 0px;
}

input#responsive-nav[type=checkbox]:checked ~ nav {
position: relative;
top: 0;
}

nav a:after {
display: none;
}

nav li {
float: none !important;
width: 100% !important;
border-bottom: none !important;
}

nav li a {
margin-bottom: 10px !important;
padding: 10px 20px !important;
background: black;
}

nav ul li:hover {
background: none;
}

nav ul li a:hover {
background: black;
color: #11BEE0
}
}
/* END OF MENU */

最佳答案

最简单的方法是从实际的 html 中删除“菜单”一词,并向要在菜单之间切换的菜单添加两个数据属性

所以你的标签看起来像这样

<label for="responsive-nav" class="responsive-nav-label" data-closed=" Menu" data-open=" Close Menu"><span>&#9776;</span></label>

接下来,您将不得不根据您的复选框是否被选中来切换内容,这有 2 种样式

/* toggle the menu text */
input#responsive-nav[type=checkbox]:checked ~ label.responsive-nav-label:after{
content: attr(data-open);
}
input#responsive-nav[type=checkbox] ~ label.responsive-nav-label:after{
content: attr(data-closed);
}

这是您可以测试的完整代码

/* hide the checkbox and the label */

input#responsive-nav,
label.responsive-nav-label {
content: "Menu Hide";
display: none;
font-size: 15pt;
}

/* declarations for the not-responsove-menu */

nav {
width: 220px; /* Darüber laesst sich die breite des Aufklappmenue steuern */
margin-left: -10px;
background: black;
}

nav ul {
padding: 0px;
margin-left: -10px;
margin-top: 43px;
}

nav a {
display: block;
background: #FFF;
text-decoration: none;
color: white;
font-size: 15pt;
}

nav ul li {
position: relative;
float: left;
list-style: none;
color: #FFF;
transition: 0.5s;
}

/* Declarations for the responsive menu 1680px */
@media screen and (max-width: 15360px) {

* {
font-size: 15pt;
}


label.responsive-nav-label {
position: relative;
display: block;
padding: 0px;
background: black;
cursor: pointer;
color: #fff;

}

nav {
position: absolute;
top: -9999px;
padding: 0px;
}

input#responsive-nav[type=checkbox]:checked ~ nav {
position: relative;
top: 0;
}

/* toggle the menu text */
input#responsive-nav[type=checkbox]:checked ~ label.responsive-nav-label:after{
content: attr(data-open);
}
input#responsive-nav[type=checkbox] ~ label.responsive-nav-label:after{
content: attr(data-closed);
}

nav a:after {
display: none;
}

nav li {
float: none !important;
width: 100% !important;
border-bottom: none !important;
}

nav li a {
margin-bottom: 10px !important;
padding: 10px 20px !important;
background: black;
}

nav ul li:hover {
background: none;
}

nav ul li a:hover {
background: black;
color: #11BEE0
}

}
/* END OF MENU */
<input type="checkbox" id="responsive-nav">

<label for="responsive-nav" class="responsive-nav-label" data-closed=" Menu" data-open=" Close Menu"><span>&#9776;</span></label>

<nav>
<ul>
<li><a href="download.php">Download Apps</a></li>
<li><a href="manual.php">Download Manuals</a></li>
</ul>
</nav>

关于php - 使用 CSS 更改文本名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43154003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com