<body>
<div class="header">
<div class="left">
<a href=" #">按钮一</a>
<a href="#">按钮二</a>
<a href="#">按钮三</a>
<a href="#">按钮四</a>
</div>
<div class="right">
<img src="images/mario.png">
</div>
</div>
</body>
css代码
<style>
/* 背景 */
body {
width: 100%;
height: 100%;
background-color: #fff;
background-image: url('images//4.jpg');
background-repeat: no-repeat;
background-size: cover;
}
a {
color: #fff;
text-decoration: none;
background-color: transparent;
display: block;
/* 文字垂直居中 */
line-height: 100px;
text-align: center;
font: 700 60px FZCuYuan-M03S;
}
a:hover {
background: #fff url('images/cap.png')no-repeat;
color: gray;
/* 文字阴影 */
box-shadow: 10px 10px 10px -4px rgba(0, 0, 0, .3);
text-shadow: 5px 5px 2px rgba(0, 0, 0, .3);
}
.header {
width: 900px;
height: 200px;
/* 盒子水平居中 */
margin: 100px auto;
}
.left {
float: left;
width: 450px;
height: 100px;
/* 盒子水平居中 */
margin: auto;
margin-top: 200px;
}
.right {
float: right;
width: 450px;
height: 100px;
/* 盒子水平居中 */
margin: auto;
margin-top: 40px;
background: url('images/mario.png');
background-size: 100%;
}
.right img {
width: 100%;
}
</style>
你这个结构还真没办法用纯css实现出来。因为a:hover之后,想要改变的是父层兄弟节点的子节点内容,css目前不支持父选择器。
如果能改变结构,让a能与class="right"为兄弟节点,可以通过a:hover ~ .right > img.normal 控制图片的显隐(display: none | block)。如下图: