[英]how can I add a background image to my html inside a Div without adding more classes?
I'm working on my project which involves working with a map and adding locations inside pop-ups.我正在处理我的项目,该项目涉及使用 map 并在弹出窗口中添加位置。 In those locations, I added the name of the location, an image, and the address.在这些位置中,我添加了位置名称、图像和地址。 Unfortunately, the image doesn't appear.不幸的是,图像没有出现。 I've tried several source links but it either doesn't show or it shows a very small image that appears to have been cut.我已经尝试了几个源链接,但它要么不显示,要么显示一个似乎已被剪切的非常小的图像。 Here's what I've done so far:这是我到目前为止所做的:
//javascript (This is just one of the locations but I have a lot more) //javascript(这只是其中一个位置,但我还有更多)
var restaurantMarkers = [
{
coords: { lat: 59.9178541, lng: 10.7339675 },
content:
'<div class="marker"><h6>Den Glade Gris</h6><img src="../images/restaurant1.jpg" alt="1" /><br><p>St. Olavs Gate 33</p></div>',
},
//CSS (if I add backgroung-image to the css the image appears, but that means I would have to create several classes to add a background image to my locations and I have around 60 of them. //CSS(如果我将背景图像添加到 css 中,图像就会出现,但这意味着我必须创建几个类来为我的位置添加背景图像,并且我有大约 60 个。
.marker{
width: 120px;
height: 110px;
}
The routing in separate JS files start from the location where the JS files was "included" from.单独 JS 文件中的路由从 JS 文件“包含”的位置开始。 So if your file structure looks like:因此,如果您的文件结构如下所示:
root/
├── index.html
└── assets/
└── images/
└── restaurant1.jpg
└── js/
└── googlemaps.js
And you're javascript file is linked in index.html
, you need to start your routing from there (eg, background-image: url(assets/images/restaurant1.jpg)
).而你的 javascript 文件链接在index.html
中,你需要从那里开始你的路由(例如background-image: url(assets/images/restaurant1.jpg)
)。
Or if you're file structure looks like:或者,如果您的文件结构如下所示:
root/
├── index.html
└── views/
└── map.html
└── assets/
└── images/
└── images.jpg
└── js/
└── googlemaps.js
And you're javascript file is linked in view/map.html
, you need to start your routing from there (eg, background-image: url(../assets/images/restaurant1.jpg)
).而你的 javascript 文件链接在view/map.html
中,你需要从那里开始你的路由(例如, background-image: url(../assets/images/restaurant1.jpg)
)。
Keep in mind, these are examples, your file structure is probably different.请记住,这些只是示例,您的文件结构可能不同。
ok so this is what I did好的,这就是我所做的
background-image: url(assets/images/restaurant1.jpg);
with this the image appears, the problem now is that it's repeating so I tried this:有了这个图像出现了,现在的问题是它正在重复,所以我尝试了这个:
background-image: url(assets/images/restaurant1.jpg) no-repeat;
but when I add "no-repeat" the image is gone again但是当我添加“不重复”时,图像又消失了
I managed to figure it out!我设法弄清楚了! Thanks everyone!感谢大家!
here's what I did:这就是我所做的:
<div class="marker" style="background: url(assets/images/restaurant1.jpg) no-repeat center">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.