简体   繁体   English

带有CSS3和HTML的有效颜色

[英]Active color with CSS3 & HTML

I'm suffering to active color on my template, I have used this template http://codepen.io/suez/pen/XJGOyL 我的模板上出现了活动色彩,我已经使用了此模板http://codepen.io/suez/pen/XJGOyL

How can I active menu, like when I clicked another menu not active. 如何激活菜单,例如单击其他未激活的菜单时。 how to do this? 这个怎么做?

This is my code: 这是我的代码:

//HTML
<div class="demo__content">
<h2 class="demo__heading">What do you need help with?</h2>
<div class="demo__elems">

    <div class="demo__elem demo__elem-1">With advertising online</div>
    <div class="demo__elem demo__elem-2">With a website</div>
    <div class="demo__elem demo__elem-3">I need help with both</div>

    <span class="demo__hover demo__hover-1"></span>
    <span class="demo__hover demo__hover-2"></span>
    <span class="demo__hover demo__hover-3"></span>

    <div class="demo__highlighter">
        <div class="demo__elems">
            <div class="demo__elem">With advertising online</div>
            <div class="demo__elem">With a website</div>
            <div class="demo__elem">I need help with both</div>
        </div>
    </div>

</div>

//CSS
 .demo__hover-2 {
      top: 7rem;
    }
    .demo__hover-2:hover ~ .demo__highlighter {
      -webkit-transform: translateY(7rem);
      transform: translateY(7rem);
    }
    .demo__hover-2:hover ~ .demo__highlighter .demo__elems {
      -webkit-transform: translateY(-7rem);
      transform: translateY(-7rem);
    }
    .demo__hover-3 {
      top: 14rem;
    }
    .demo__hover-3:hover ~ .demo__highlighter {
      -webkit-transform: translateY(14rem);
      transform: translateY(14rem);
    }
    .demo__hover-3:hover ~ .demo__highlighter .demo__elems {
      -webkit-transform: translateY(-14rem);
      transform: translateY(-14rem);
    }
    .demo__elem a:active, a:hover, a:focus {
      text-decoration: none;
      outline: none;
    }

If you are able to use jQuery in you code you can do it by adding "active" class to selected element of your menu. 如果您能够在代码中使用jQuery,则可以通过向菜单的选定元素中添加“活动”类来实现。

For instance 例如

$(".demo__elem").click(function() {
  $(".demo__elem").removeClass("active"); // remove active from all
  $(this).addClass("active"); // add active to this
});

and you "active" css should be styled as well. 并且您的“活动” css也应设置样式。

If you're wanting to click a link, go to that page, and have that link retain the active state once you're on that page, you'll need to do one of three things. 如果要单击链接,请转到该页面,并让该链接在进入该页面后保持活动状态,则需要执行以下三项操作之一。

  1. Using HTML and CSS only, every page can be built completely and individually. 仅使用HTML和CSS,每个页面都可以完全独立地构建。 This is called a static website. 这称为静态网站。 The menu will live on each page, and the link for the page you're on will need a unique ID (usually class="active" ) in order to set it apart as the active link. 菜单将显示在每个页面上,并且您所在页面的链接将需要唯一的ID(通常为class="active" ),以便将其设置为活动链接。 Using CSS, you can style to appear how you want. 使用CSS,您可以样式显示所需的样式。

  2. You can use javascript to dynamically detect the page you're on, usually by reading your URL, and apply the active state to the appropriate link. 您通常可以通过阅读URL来使用javascript动态检测您所在的页面,并将活动状态应用于相应的链接。

  3. You can use a server side codding language such as PHP , ASP, RUBY, etc., and set your menus to dynamically detect which page you're on based on internal/server side code and apply the active state to the menu. 您可以使用服务器端编码语言(例如PHP ,ASP,RUBY等),并设置菜单以基于内部/服务器端代码动态检测您所在的页面,并将活动状态应用于菜单。 This is a very clean, and once you get the hang of the language you choose, it's a very easy and effective method. 这是一种非常干净的方法,一旦掌握了所选择的语言,这是一种非常简单有效的方法。 This is the most popular choice by developers and is called a dynamic website. 这是开发人员最受欢迎的选择,被称为动态网站。

In each case, you'll still use CSS the exact same way to style the active link. 在每种情况下,您仍将以完全相同的方式使用CSS设置活动链接的样式。

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

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