Changing body background color using only HTML5 and CSS3..?

南笙酒味 提交于 2019-12-21 23:42:08

问题


Is it possible to achieve the same effect found here: www.lutmedia.com simply using CSS3 and HTML5...and not jquery..? Where the body background color changes on hover over the list item links..?


回答1:


Yes, you could get an effect like that with pure CSS, but it won't be the body changing background, but a last list item in that menu which has position: fixed and covers the entire page.

QUICK DEMO

Relevant 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>

Relevant 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 */


来源:https://stackoverflow.com/questions/15179968/changing-body-background-color-using-only-html5-and-css3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!