基于html和css写一个第一行五个图像,第二行四个图像,第三行三个图像呈现倒梯形排版,有导航栏,并且鼠标悬停在导航栏时能显示下拉菜单的照片墙网页
时间: 2024-03-01 17:52:08 浏览: 119
好的,下面是基于HTML和CSS实现倒梯形排版的代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>照片墙</title>
<style type="text/css">
/* 导航栏样式 */
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f1f1f1;
}
.show {
display: block;
}
/* 图片墙样式 */
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
margin-top: 20px;
margin-bottom: 20px;
transform: skewY(-7deg);
}
.container img {
width: calc(20% - 10px);
margin-bottom: 20px;
transition: all 0.3s ease-in-out;
transform: skewY(7deg);
}
/* 响应式样式 */
@media only screen and (max-width: 768px) {
.container img {
width: calc(25% - 10px);
}
}
@media only screen and (max-width: 480px) {
.container img {
width: calc(50% - 10px);
}
}
</style>
</head>
<body>
<!-- 导航栏 -->
<ul>
<li><a href="#">Home</a></li>
<li class="dropdown">
<a href="#" class="dropbtn">Dropdown</a>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</li>
</ul>
<!-- 图片墙 -->
<div class="container">
<!-- 第一行五个图像 -->
<img src="img/1.jpg">
<img src="img/2.jpg">
<img src="img/3.jpg">
<img src="img/4.jpg">
<img src="img/5.jpg">
<!-- 第二行四个图像 -->
<img src="img/6.jpg">
<img src="img/7.jpg">
<img src="img/8.jpg">
<img src="img/9.jpg">
<!-- 第三行三个图像 -->
<img src="img/10.jpg">
<img src="img/11.jpg">
<img src="img/12.jpg">
</div>
<script type="text/javascript">
// 鼠标悬停时显示下拉菜单
var dropdown = document.getElementsByClassName("dropdown");
for (var i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("mouseover", function() {
this.getElementsByClassName("dropdown-content")[0].classList.add("show");
});
dropdown[i].addEventListener("mouseout", function() {
this.getElementsByClassName("dropdown-content")[0].classList.remove("show");
});
}
</script>
</body>
</html>
```
和之前的例子相比,主要的区别在于对图片墙的样式进行了调整,使用了`transform: skewY()`属性来实现倒梯形排版的效果。同时也对图片宽度进行了调整,以适应不同的屏幕大小。
阅读全文