麻烦使一排图像响应迅速

发布于 2025-02-01 11:57:29 字数 696 浏览 2 评论 0原文

我只想制作一排响应迅速的图像。首先,我想将图像的大小减少20%。无论出于何种原因,我都无法正常工作。我正在使用Bundler Vite BTW,必须将图像源存储在CSS中,例如代码中的此处。

<div class="business">
<img class="firstb" alt="firstb">
<img class="secondb" alt="secondb">
<img class="thirdb" alt="thirdb">
<img class="fourthb" alt="fourthb">
<img class="fifthb" alt="fifthb">
</div>

.business {
  margin: 0 7em;
  display: flex;
}
.firstb {
  content:url(./img/business/firstb.png);
}
.secondb {
  content:url(./img/business/secondb.png);
}
.thirdb {
  content:url(./img/business/thirdb.png);
}
.fourthb {
  content:url(./img/business/fourthb.png);
}
.fifthb {
  content:url(./img/business/fifthb.png);
}

I just want to make a row of images that are responsive. To begin with though I want to reduce the size of the images by 20%. For whatever reason I can't get this to work. I am using the bundler Vite btw and have to store the source of the image in the css like here in the code.

<div class="business">
<img class="firstb" alt="firstb">
<img class="secondb" alt="secondb">
<img class="thirdb" alt="thirdb">
<img class="fourthb" alt="fourthb">
<img class="fifthb" alt="fifthb">
</div>

.business {
  margin: 0 7em;
  display: flex;
}
.firstb {
  content:url(./img/business/firstb.png);
}
.secondb {
  content:url(./img/business/secondb.png);
}
.thirdb {
  content:url(./img/business/thirdb.png);
}
.fourthb {
  content:url(./img/business/fourthb.png);
}
.fifthb {
  content:url(./img/business/fifthb.png);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2025-02-08 11:57:29

您应该给Flexbox的子元素一个宽度:

.business {
    margin: 0 7em;
    display: flex;
    flex-flow: row wrap;
}

.business img {
    flex: 0 0 20%;
    width: 20%; //fallback
    height: auto;
}
<div class="business">
    <img alt="firstb" src="http://via.placeholder.com/400">
    <img alt="secondb" src="http://via.placeholder.com/400">
    <img alt="thirdb" src="http://via.placeholder.com/400">
    <img alt="fourthb" src="http://via.placeholder.com/400">
    <img alt="fifthb" src="http://via.placeholder.com/400">
</div>

You should give the child elements of a flexbox a width:

.business {
    margin: 0 7em;
    display: flex;
    flex-flow: row wrap;
}

.business img {
    flex: 0 0 20%;
    width: 20%; //fallback
    height: auto;
}
<div class="business">
    <img alt="firstb" src="http://via.placeholder.com/400">
    <img alt="secondb" src="http://via.placeholder.com/400">
    <img alt="thirdb" src="http://via.placeholder.com/400">
    <img alt="fourthb" src="http://via.placeholder.com/400">
    <img alt="fifthb" src="http://via.placeholder.com/400">
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文