gpt4 book ai didi

html - Accordion 背景图像的大小

转载 作者:行者123 更新时间:2023-11-28 02:55:26 24 4
gpt4 key购买 nike

我制作了带有背景图像的水平 Accordion ,但与 Accordion 的宽度相比,图像相当大。我想让 Accordion 缩小背景图像,现在我只看到每个背景图像的中心。

这是我的代码:(示例)

.accordion {
width: 100%;
max-width: 1080px;
height: 400px;
overflow: hidden;
margin: 50px auto;
}
.accordion ul {
width: 100%;
display: table;
table-layout: fixed;
margin: 0;
padding: 0;
}
.accordion ul li {
display: table-cell;
vertical-align: bottom;
position: relative;
width: 16.666%;
height: 400px;
background-repeat: no-repeat;
background-position: center center;
transition: all 500ms ease;
}
.accordion ul li:nth-child(1) {
background-image: url("https://images.unsplash.com/photo-1460500063983-994d4c27756c?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=27c2758e7f3aa5b8b3a4a1d1f1812310");
}
.accordion ul li:nth-child(2) {
background-image: url("https://images.unsplash.com/photo-1460378150801-e2c95cb65a50?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=1b5934b990c027763ff67c4115b6f32c");
}
.accordion ul li:nth-child(3) {
background-image: url("https://images.unsplash.com/photo-1458400411386-5ae465c4e57e?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=47756f965e991bf72aa756b410929b04");
}
.accordion ul li:nth-child(4) {
background-image: url("https://images.unsplash.com/photo-1452827073306-6e6e661baf57?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=c28fd5ea58ed2262a83557fea10a6e87");
}
.accordion ul li:nth-child(5) {
background-image: url("https://images.unsplash.com/photo-1452215199360-c16ba37005fe?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=408c70a6e88b50949c51e26424ff64f3");
}
.accordion ul li:nth-child(6) {
background-image: url("https://images.unsplash.com/photo-1442551382982-e59a4efb3c86?format=auto&auto=compress&dpr=1&crop=entropy&fit=crop&w=1920&h=1280&q=80");
}
.accordion ul:hover li {
width: 8%;
}
.accordion ul:hover li:hover {
width: 100%;
}
.accordion ul:hover li:hover a {
background: rgba(0, 0, 0, 0.4);
}
.accordion ul:hover li:hover a * {
opacity: 1;
-webkit-transform: translateX(0);
transform: translateX(0);
}
@media screen and (max-width: 200px) {
body {
margin: 0;
}
.accordion {
height: auto;
}
.accordion ul li,
.accordion ul li:hover,
.accordion ul:hover li,
.accordion ul:hover li:hover {
position: relative;
display: table;
table-layout: fixed;
width: 100%;
-webkit-transition: none;
transition: none;
}
}
.about {
text-align: center;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
color: #666;
}
.about a {
color: blue;
text-decoration: none;
}
.about a:hover {
text-decoration: underline;
}
<body>

<div class="accordion">
<ul>
<li>
<div>
<a href="#">
</a>
</div>
</li>
<li>
<div>
<a href="#">
</a>
</div>
</li>
<li>
<div>
<a href="#">
</a>
</div>
</li>
<li>
<div>
<a href="#">
</a>
</div>
</li>
<li>
<div>
<a href="#">
</a>
</div>
</li>
<li>
<div>
<a href="#">
</a>
</div>
</li>
</ul>
</div>

<body>

最佳答案

尝试为您的图片设置一个固定宽度以查看完整图片,而不仅仅是图片的中心。

参见 fiddle 。

如果你将使用大图像,我会更好地使用background-size:cover 代替。

关于html - Accordion 背景图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37298167/

24 4 0
文章推荐: c++ - 通过引用调用类对象的二维数组
文章推荐: javascript - 如何使用 angularJS 从 Controller 更改