html - 将图像 url 从变量传递到 css
问题描述
我正在从我的数据库中调用产品图片 url,在前端页面中,我有一些 CSS 来设置页面上的图片样式。但是,我需要将产品图像的 url 传递到指定图像 url 的 css 中......
我的CSS:
.product-image .bg{
background-image: url('https://images.unsplash.com/photo-1521572163474-6864f9cf17ab?ixid=MXwxMjA3fDB8MHxzZWFyY2h8Mnx8dHNoaXJ0fGVufDB8fDB8&ixlib=rb-1.2.1&auto=format&fit=crop&w=900&q=60 ');
background-size: cover;
background-position: center top;
width: 100%;
min-height: 450px;
}
显示背景图片的产品页面
<div class="product group">
<div class="col-1-2 product-image">
product-image 放在 div 中的地方,它会渲染产品图像。我怎样才能将这个 url 传递<%= data[I].IMAGE_URL %>
到 css 中?所以而不是 ->
background-image: url('https://images.unsplash.com/photo-1521572163474-6864f9cf17ab?ixid=MXwxMjA3fDB8MHxzZWFyY2h8Mnx8dHNoaXJ0fGVufDB8fDB8&ixlib=rb-1.2.1&auto=format&fit=crop&w=900&q=60');
->
我会background-image: url('<%= data[I].IMAGE_URL');
这可能吗?
解决方案
这是可以做到的。只要你把它放在一个.aspx 或服务器上呈现的任何其他页面上,你就会很好。只需将其更改为使用双引号而不是单引号即可。
product-image .bg {
background-image: url("<%=someImageURL%>");
background-size: cover;
background-position: center top;
width: 100%;
min-height: 450px;
}
推荐阅读
- visual-c++ - 带有 MSVC 和 CLION 的 Makefile
- php - 我应该在 laravel 中的哪里存储私有证书文件?
- vue.js - 不能在 nuxt.js 中使用 vue-start-rating?
- c - 指针和结构类型的大小看似不一致的原因是什么?
- latex - 使用带有 \onslide\visible\only 的 Tikz 定位在投影仪内
- java - Microsoft Graph Java SDK - 无法读取共享点上的共享文件
- javascript - 在 Javascript 中重置倒数计时器
- reactjs - 进度条直接到100%
- flutter - Flutter StompClient 报错 初始化器中只能访问静态成员
- reactjs - 更改后未重新渲染反应状态