在Span内,如何更改文本的颜色

时间:2018-02-20 05:16:04

标签: html css html5 css3

我讨厌按下我的运气寻求帮助,但无论如何我都去了 -

我从w3schools.com获得了这段代码,但无法弄清楚如何在HTML代码中将OPEN这个词变成另一种颜色。它目前是黑色的,我希望它是白色的。我改变了其他颜色,因为我的实际页面有黑色背景。对不起,代码太长了,我觉得太好了太多了。这是我目前的代码:

HTML

<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>

<p>Click on the element below to open the menu</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; open</span>

<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}

function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>

CSS

body {
font-family: "Lato", sans-serif;
}

.sidenav {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: #DD0;
    overflow-x: hidden;
    transition: 0.5s;
    padding-top: 60px;
}

.sidenav a {
    padding: 8px 8px 8px 32px;
    text-decoration: none;
    font-size: 25px;
    color: #2707AB;
    display: block;
    transition: 0.3s;
}

.sidenav a:hover {
    color: #818181;
}

.sidenav .closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}

@media screen and (max-height: 450px) {
  .sidenav {padding-top: 15px;}
  .sidenav a {font-size: 18px;}
}

感谢您的帮助!

3 个答案:

答案 0 :(得分:0)

试试这个

&#13;
&#13;
body {
font-family: "Lato", sans-serif;
}

.sidenav {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: #DD0;
    overflow-x: hidden;
    transition: 0.5s;
    padding-top: 60px;
}

.sidenav a {
    padding: 8px 8px 8px 32px;
    text-decoration: none;
    font-size: 25px;
    color: #2707AB;
    display: block;
    transition: 0.3s;
}

.sidenav a:hover {
    color: #818181;
}

.sidenav .closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}

@media screen and (max-height: 450px) {
  .sidenav {padding-top: 15px;}
  .sidenav a {font-size: 18px;}
}
.opencolor
{
  color:tan;
}
&#13;
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>

<p>Click on the element below to open the menu</p>
<span style="font-size:30px;cursor:pointer;">&#9776; </span><span style="font-size:30px;cursor:pointer;" class="opencolor" onclick="openNav()">open</span>

<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}

function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

如果你正在寻找开放颜色的changin试试这个。

    <p>Click on the element below to open the menu</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; <font color="red">open</font></span>

 <p>Click on the element below to open the menu</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; <span style="color:blue;">open</span></span>

答案 2 :(得分:0)

在里面拿一个课,为那个班写css。

<span class="foo" onclick="openNav()">&#9776; open</span>

CSS

.foo{
        font-size:30px;
        cursor:pointer;
        color:#fff;
    }

如果您只想更改该条形颜色,请使用该hss

<div  onclick="openNav()"><span class="bar">&#9776;</span> open</div>