【问题标题】:Changing body background color using only HTML5 and CSS3..?仅使用 HTML5 和 CSS3 更改正文背景颜色 ..?
【发布时间】:2013-02-17 06:24:05
【问题描述】:

是否可以实现与此处相同的效果:www.lutmedia.com 只需使用 CSS3 和 HTML5...而不是 jquery..?将鼠标悬停在列表项链接上时,正文背景颜色会发生变化..?

【问题讨论】:

    标签: html css colors transition


    【解决方案1】:

    是的,您可以使用纯 CSS 获得类似的效果,但它不会是主体更改背景,而是该菜单中的最后一个列表项,它具有 position: fixed 并覆盖整个页面。

    QUICK DEMO

    相关HTML

    <ul class='menu'>
      <li><a href='#'>contact</a></li>
      <li><a href='#'>blog</a></li>
      <!-- and so on, menu items -->
      <li class='bg'></li>
    </ul>
    

    相关CSS

    .menu li { display: inline-block; }
    .menu li:first-child a { color: orange; }
    .menu li:nth-child(2) a { color: lime; }
    /* and so on for the other menu items */
    .menu:hover li a { color: black; }
    .menu li a:hover { color: white; }
    .bg {
      position: fixed;
      z-index: -1;
      top: 0; right: 0; bottom: 0; left: 0;
      background: dimgrey;
      transition: .5s;
      pointer-events: none;
    }
    .menu li:first-child:hover ~ .bg { background: orange; }
    .menu li:nth-child(2):hover ~ .bg { background: lime; }
    /* and so on for the other menu items */
    

    【讨论】:

      猜你喜欢
      • 2012-11-18
      • 2015-05-23
      • 2014-05-04
      • 2018-12-25
      • 1970-01-01
      • 1970-01-01
      • 2011-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多