Home > Web Front-end > HTML Tutorial > How CSS implements hyperlink background switching_html/css_WEB-ITnose

How CSS implements hyperlink background switching_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:39:04
Original
1870 people have browsed it

How to implement hyperlink background switching with CSS:

A considerable number of websites have such an effect on the navigation bar: when the mouse is placed on the navigation bar, the background The image will change, and the original background image will be restored after being moved. Here is a brief introduction on how to achieve this effect. The code example is as follows:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="author" content="http://www.51texiao.cn/" /><title>蚂蚁部落</title><style type="text/css">div{  height:28px;  width:300px;  border-bottom:3px solid #E10001;}ul{  list-style:none;  margin:0px;  padding:0px;}ul li{  float:left;  width:87px;  height:28px;  margin-left:2px;  display:inline;}ul li a{  width:87px;  height:28px;  display:block;  font-size:14px;  text-align:center;  line-height:28px;  text-decoration:none;  color:#333;  background:url(mytest/demo/bg1.gif) no-repeat;}ul li a:hover{  background:url(mytest/demo/bg2.gif) no-repeat;}</style></head><body><div>  <ul>    <li><a href="#">CSS专区</a></li>    <li><a href="#">JS专区</a></li>    <li><a href="#">HTML专区</a></li>  </ul></div></body></html>
Copy after login

The above code implements our requirements. The implementation process is very simple:

The first step is to set a background image in the default state of the hyperlink.

The second part is to set another background image when the mouse is placed on the hyperlink.

Note: The a element must be converted into a block-level element, otherwise the height and width cannot be set.

The original address is: http://www.51texiao.cn/div_cssjiaocheng/2015/0508/938.html

The most original address is: http://www.softwhy.com/ forum.php?mod=viewthread&tid=4683

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template