you can open it using browser, but I cannot display the background image in these code. what problem it is?
There two things you need to do:
In the updated example below I have added a 500x500 dimension to the div
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div style="background-image:url('https://www.marsha.com.hk/libs/img/Massage-landing 1906x810_R1-03.jpg');
width:100%;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
position: relative; width: 500px; height: 500px" class="item2" data-aos="fade-up">
</div>
</body>
</html>
You'll need to set a height for the <div>
with the background image.
Edit: Sorry, did not notice the space in the url. Also make sure that when there is a space in the URL path to the image to enclose the url with quotes.
In this case, since the styling is inlined with double quotes "
, wrap the url in single quotes '
.
You could try:
<div style="background-image:url('https://www.marsha.com.hk/libs/img/Massage-landing 1906x810_R1-03.jpg');
width:100%;
height: 100vh;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
position: relative" class="item2" data-aos="fade-up">
In the above, you didn't close the double quotes and also assign some height to the div and check and remove the space provided in the URL link which you have given
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div style="background-image:url(https://www.marsha.com.hk/libs/img/Massage-landing%201906x810_R1-03.jpg);
width:100vw;
height:100vh;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
position: relative"
class="item2" data-aos="fade-up">;
</div>
You need to replace the space with %20
and set the height of the div
<div style="background-image:url(https://www.marsha.com.hk/libs/img/Massage-landing%201906x810_R1-03.jpg);
width:100%;
height: 300px;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
position: relative" class="item2" data-aos="fade-up">
space
in your image url to %20
(for more info see this)%
values do not work for width
and height
because there is no other parent div width for it to be assigned to (think as: 100% of what?). So we assign our own (non-percentage) width
and height
properties to it:<div style="background-image:url(https://www.marsha.com.hk/libs/img/Massage-landing%201906x810_R1-03.jpg);
width:100vw;
height:100vh;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
position: relative"
class="item2" data-aos="fade-up">
</div>
try this
<div style="background-image:url('https://www.marsha.com.hk/libs/img/Massage-landing 1906x810_R1-03.jpg');
width:100%;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
position: relative" class="item2" data-aos="fade-up">