Add image behind CSS mask - html

How do can I get the background image look like it's being shown on the phone? So I have the iPhone masked and I want to put an image on the screen of the phone. How do I do this? I tried playing with z-index but it doesn't work. Here's what I'm trying to achieve
div{
width: 302px;
height: 605px;
background-image: url(https://www.apple.com/v/iphone-xs/d/images/overview/hardware_display_iphonexsmax_gold_portrait_large_2x.jpg);
background-size: 302px 605px;
background-repeat: no-repeat;
-webkit-mask-size: 302px 605px;
-webkit-mask-image: url(https://www.apple.com/v/iphone-xs/d/images/overview/hardware_display_iphonexsmax_gold_portrait_mask_large.svg);
-webkit-mask-repeat: no-repeat;
position: relative;
z-index: 2;
}
.background{
position: absolute;
top: 0;
left: 0;
z-index: 1;
width: 265px;
height: 571px;
background-image: url(https://www.apple.com/v/iphone-xr/d/images/overview/screen_display_iphonexr_large_2x.jpg);
background-size: 265px 571px;
}
<div>
</div>
<div class="background"></div>

The problem you were having is that the div styles you applied to the phone were also being applied to the .background. By giving the phone it's own separate class you can style them individually.
I've updated your example below.
.phone {
width: 302px;
height: 605px;
background-color: white;
background-image: url(https://www.apple.com/v/iphone-xs/d/images/overview/hardware_display_iphonexsmax_gold_portrait_large_2x.jpg);
background-size: 302px 605px;
background-repeat: no-repeat;
-webkit-mask-size: 302px 605px;
-webkit-mask-image: url(https://www.apple.com/v/iphone-xs/d/images/overview/hardware_display_iphonexsmax_gold_portrait_mask_large.svg);
-webkit-mask-repeat: no-repeat;
position: absolute;
z-index: 2;
}
.background {
position: absolute;
top: 20px;
left: 20px;
z-index: 1;
width: 280px;
height: 580px;
border-radius: 10px;
background-image: url(https://www.apple.com/v/iphone-xr/d/images/overview/screen_display_iphonexr_large_2x.jpg);
background-size: cover;
}
<div class="phone"></div>
<div class="background"></div>

Related

CSS frosted glass positioned incorrectly

I'm trying to achive frosted glass effect with CSS like here: https://codepen.io/GreggOD/full/xLbboZ
But I think, I'm missing something, because it shows me the full image, but smaller size
I have set background-size: cover; background-attachment: fixed;, yet this doesn't fix the problem
#second_wrapper {
background-image: url("https://images.pexels.com/photos/2466644/pexels-photo-2466644.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
background-attachment: fixed;
background-size: cover;
background-position: center;
height: 250px;
width: 500px;
}
#test_image {
background: inherit;
position: relative;
left: 50%;
top: 50%;
overflow: hidden;
height: 200px;
width: 400px;
transform: translate(-50%, -50%);
}
#blur {
position: absolute;
height: 100%;
width: 100%;
background: inherit;
filter: blur(5px);
}
<div id='second_wrapper'>
<div id='test_image'>
<div id='blur'>
</div>
</div>
</div>
Is this what u wanted?
I added new css rules to #test_image:after
background: inherit;
position: relative;
left: 10%;
top: 10%;
height: 200px;
width: 400px;
/*transform: translate(-50%, -50%);*/
Note that you cannot use transform in this case , because, when you transform, the inherited background image also moves with the div.
Try uncommenting transform and change the values of translate in devtools
#second_wrapper {
background-image: url("https://images.pexels.com/photos/2466644/pexels-photo-2466644.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
background-attachment: fixed;
background-size: cover;
background-position: center;
height: 250px;
width: 500px;
}
#test_image {
background: inherit;
position: relative;
left: 10%;
top: 10%;
height: 200px;
width: 400px;
/*transform: translate(-50%, -50%);*/
}
#test_image:after {
content: "";
background: inherit;
filter: blur(10px);
width: 400px;
height: 200px;
display: block;
}
<div id='second_wrapper'>
<div id='test_image'>
<div id=''>
T
</div>
</div>
</div>

Image not showing on specific mobile phone

On some mobile devices the image on the top of the page is nog showing. The logo, on the other hand, is showing. The difference is an image and background-image. The one not showing up is the background-image.
The div has a height and width and a background color. So if the background-image isn't working, the color should be visible but it isn't.
The image is not showing on this specific phone with settings:
Nokia 8.1
Chrome 74.0.3729.157
Android 9
Here you can find print-screens
Nokia, so no picture:
Iphone, with picture:
I've changed the position of the class .background to relative instead of static. And deleter mix-blend-mode: multiply;
But nothing is working. The height of the image show, but it is just an empty space.
<div class="header">
<a class="logo" href="/">
<img src="/images/logo.png" alt="">
</a>
<div class="background">
<div class="mas"></div>
</div>
</div>
.header{
position: relative;
.logo{
color: black;
text-transform: uppercase;
font-weight: bold;
font-size: 3.5em;
letter-spacing: 5px;
text-decoration: none;
position: relative;
z-index: 100;
img{
width: 120px;
margin-bottom: 10px;
margin-left: -22px;
}
}
.background{
position: relative;
width: 100%;
height: 300px;
margin-top: 0;
background: $baseColor;
z-index: 50;
.mas{
width: 100%;
height: 300px;
margin-top: 40px;
bottom: 0;
top: auto;
position: absolute;
right: 0;
background-image: url(/images/antwerpse_fluisteraar.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
opacity: 0.8;
}
}
}
Try this I hope it will help you
.background{
position: absolute;
width: 100%;
height: 300px;
margin-top: 0;
background: $baseColor;
.mas{
width: 100%;
height: 300px;
margin-top: 40px;
position: relative;
background-image: url(/images/antwerpse_fluisteraar.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
opacity: 0.8;
}
}

parallax scrolling pages arranged oddly

I want the about div to show up BELOW the
full screen home card
I'm having troubles getting it to show like it should.
my html code has both divs in the "right" order and when i look it up online, i couldn't find any solutions.
<body>
<div class="homeCard">
<div class="homeCardTitle">
<h1>Robin Riezebos</h1>
</div>
</div>
<div class="aboutCard">
<div class="aboutCardText">
<h2>About</h2>
</div>
</div>
</body>
my css is either missing something or I did something completely wrong but I can't seem to find out what it is so please help...
index.css
.homeCard {
background-image: url("images/helicopter-in-sky-2.jpg");
height: 100%;
width: 100%;
position: fixed;
float: left;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 0;
}
.homeCardTitle {
position: fixed;
width: 100%;
height: 320px;
top: 50%;
margin-top: -160px;
color: white;
text-shadow: 0 0 10px black;
}
.aboutCard {
background-color: #1F1F1F;
color: white;
height: 500px;
}
Please change your css like below, i think the problem was with position fixed, if you want to get your background image rendered fully please respective pixels of height.
.homeCard {
background-image: url("images/helicopter-in-sky-2.jpg");
width: 100%;
position: relative;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 0;
}
.homeCardTitle {
color: white;
text-shadow: 0 0 10px black;
}
.aboutCard {
background-color: #1F1F1F;
color: white;
height: 500px;
}
I have found a solution by bugging around in my css.
Turns out in stead of position: fixed; I should have used background-attachment: fixed; and remove position all-together.
this is my own fixed code:
.homeCard {
background-image: url("images/helicopter-in-sky-2.jpg");
height: 100%;
width: 100%;
background-attachment: fixed;
float: left;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 0;
}
.homeCardTitle {
position: relative;
width: 100%;
height: 0px;
top: 50%;
margin-top: -90px;
color: white;
text-shadow: 0 0 10px black;
}
.aboutCard {
width: 100%;
background-color: #1F1F1F;
color: white;
height: 320px;
float: left;
text-align: center;
}

Complementing image to the right

I want to create a background image that has two images, but I can’t complement the second image to the right.
I can’t manage to make it look like one whole picture, but in one place.
* {
margin: 0;
padding: 0;
overflow: hidden;
}
.home-wrapper {
height: 100%;
width: 100%;
overflow: hidden;
}
.left-content {
background: url(../img/leftwing.png);
background-repeat: no-repeat;
background-size: cover;
height: 100%;
width: 100%;
float: left;
position: absolute;
border-right: 1px solid black;
left: 0;
}
.right-content {
background: url(../img/rightwing.png);
background-repeat: no-repeat;
background-size: cover;
height: 100%;
width: 50%;
float: right;
position: absolute;
border-right: 1px solid black;
right: 0;
}
<div class="home-wrapper">
<div class="left-content">
a
</div>
<div class="right-content">
a
</div>
</div>
The reason I didn’t make it a whole background is these two have a different function when you hover over them.
This is what I want it to look like:
This is what I have instead:
You can achieve the desired result by adding background position in your css. Try this code.
.left-content{
background: url(../img/leftwing.png);
background-position: left center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
width: 50%;
float: left;
position: absolute;
border-right: 1px solid black;
left: 0;
}
.right-content{
background: url(../img/rightwing.png);
background-position: right center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
width: 50%;
float: right;
position: absolute;
border-right: 1px solid black;
right: 0;
}
Add background-position to both .right-content and .left-content
.right-content {
background-position: left center;
width: 50%; /* << this was 100%, typo? */
}
.left-content {
background-position: right center;
}

I am trying to encircle a part of back ground image with a div

I am trying to encircle a part of back ground image with a div, but when window resizes it all becomes messed up, and I need it to display the same way on different screen sizes.
I am using google chrome
thank you for any ideas..
EXAMPLES
HTML
<div class="stage1">
<div class="theRoom">
<div class="table items"></div>
<div class="picture items"></div>
<div class="bookstore items"></div>
<div class="door items"></div>
<div class="makeup items"></div>
</div>
</div>
CSS
html, body {
width: 100%;
height: 100%;
overflow: hidden;
}
.items {
border: 2px solid red
}
.items:hover {
-webkit-filter: drop-shadow(3px 3px 6px red);
/* background-size: contain;*/
}
.stage1 {
width: 1960px;
}
.theRoom {
background-image: url("../img/room/room.jpg");
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
position: absolute;
left: 0px;
top: 0px;
z-index: 1;
}
.table {
background-image: url("../img/room/room_0000_table.png");
background-repeat: no-repeat;
background-size: contain;
position: absolute;
left: 78.7%;
top: 54%;
width: 296px;
height: 424px;
z-index: 6;
}
.bookstore {
background-image: url("../img/room/room_0001_bookstore.png");
background-repeat: no-repeat;
background-size: contain;
position: absolute;
left: 64.6%;
top: 33.3%;
width: 243px;
height: 462px;
z-index: 3;
}
.door {
background-image: url("../img/room/room_0002_door.png");
background-repeat: no-repeat;
background-size: contain;
position: absolute;
left: 46%;
top: 30%;
width: 217px;
height: 421px;
z-index: 3;
}
.makeup {
background-image: url("../img/room/room_0003_makeup.png");
background-repeat: no-repeat;
position: relative;
background-size:contain;
left: 30.7%;
top: 46.3%;
width: 9.7%;
height: 299px;
z-index: 3;
}
.picture {
background-image: url("../img/room/room_0004_picture.png");
background-repeat: no-repeat;
background-size: contain;
position: absolute;
left: 9%;
top: 39%;
max-width: 123px;
max-height: 217px;
z-index: 2;
}
html, body {
width: 100%;
height: 100%;
overflow: hidden;
}
.items {
border: 2px solid red
}
.items:hover {
-webkit-filter: drop-shadow(3px 3px 6px red);
/* background-size: contain;*/
}
.stage1 {
width: 1960px;
}
.theRoom {
background-image: url("../img/room/room.jpg");
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
position: absolute;
left: 0px;
top: 0px;
z-index: 1;
}
.table {
background-image: url("../img/room/room_0000_table.png");
background-repeat: no-repeat;
background-size: contain;
position: absolute;
left: 78.7%;
top: 54%;
width: 296px;
height: 424px;
z-index: 6;
}
.bookstore {
background-image: url("../img/room/room_0001_bookstore.png");
background-repeat: no-repeat;
background-size: contain;
position: absolute;
left: 64.6%;
top: 33.3%;
width: 243px;
height: 462px;
z-index: 3;
}
.door {
background-image: url("../img/room/room_0002_door.png");
background-repeat: no-repeat;
background-size: contain;
position: absolute;
left: 46%;
top: 30%;
width: 217px;
height: 421px;
z-index: 3;
}
.makeup {
background-image: url("../img/room/room_0003_makeup.png");
background-repeat: no-repeat;
position: relative;
background-size:contain;
left: 30.7%;
top: 46.3%;
width: 9.7%;
height: 299px;
z-index: 3;
}
.picture {
background-image: url("../img/room/room_0004_picture.png");
background-repeat: no-repeat;
background-size: contain;
position: absolute;
left: 9%;
top: 39%;
width: 123px;
height: 217px;
z-index: 2;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>THE ROOM</title>
<link rel="stylesheet" href="css/style.css">
<script src="script/jquery-3.1.0.min.js"></script>
<script src="script/jquery-ui-1.12.0.custom/jquery-ui-1.12.0.custom/jquery-ui.min.js"></script>
</head>
<body>
<!-- <img src="img/The-master-bedroom.jpg" alt="" class="room">-->
<div class="stage1">
<div class="theRoom">
<div class="table items"></div>
<div class="picture items"></div>
<div class="bookstore items"></div>
<div class="door items"></div>
<div class="makeup items"></div>
</div>
</div>
<script src="script/main.js"></script>
</body>
</html>