作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 HTML 和 CSS 还很陌生。我正在尝试将悬停图像添加到我的网站。我已经做到了。但是,我希望我所有的图像都属于大小相同,也居中。如果有人知道如何更改图像自动使用会更好的按钮。
<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
body {
background-color: lightblue;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
img {
position: absolute;
margin: 5px;
border: 1px solid #ccc;
width: 180px;
}
img img {
width: 100%;
height: auto;
}
img:nth-of-type(1){
-webkit-animation: fadeInOut 10s linear 6s infinite;
}
img:nth-of-type(2){
-webkit-animation: fadeInOut 10s linear 4s infinite;
}
img:nth-of-type(3){
-webkit-animation: fadeInOut 10s linear 2s infinite;
}
img:nth-of-type(4){
-webkit-animation: fadeInOut 10s linear infinite;
}
/* Keyframes - WebKit only ------------------------------------------ */
@-webkit-keyframes fadeInOut{
0% { opacity:1; }
17% { opacity:1; }
25% { opacity:0; }
92% { opacity:0; }
100% { opacity:1; }
}
</style>
</head>
<title>Badass Burgers</title>
<body>
<ul>
<li><a class="active" href="info.php">About</a></li>
<li><a href="about.php">Team</a></li>
<li><a href="Menu.php">Menu</a></li>
<li><a href="contact.php">Contact Us</a></li>
</ul>
<img src='food1.jpg'>
<img src='Food2.jpg'align="middle">
<img src='Food3.jpg' align="middle">
<img src='food4.jpg'align="middle">
</body>
</html>
最佳答案
如果您希望所有图片的大小相同,则需要为每张图片设置固定的宽度和高度。
要使图像在给定容器内居中,您可以使用下面的 CSS。
<div class="image-wrapper">
<img class="image" src='http://lorempixel.com/400/200/' width="200" height="175" />
</div>
CSS
.image-wrapper {
position: relative;
height: 500px; // change to whatever works for you
}
.image {
position: absolute;
top: 50%;
border: 1px solid #ccc;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
参见 EXAMPLE
关于css - 对齐淡入淡出图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36385461/
我是一名优秀的程序员,十分优秀!