Applying mask to parent element in CSS, yet with no result - css

I am new to masks and can find very little help online... I've set a mask by making a grayscale JPG and applying it to the parent container. I want everything in that container to be masked according to my JPG's white/black pixels, but after applying the mask, I get no change at all.
Here is the CSS:
.site-branding {
position: absolute;
height: 100vh;
width: 100%;
-webkit-mask-image: url('media/masks/catchphrase-mask.jpg');
mask-image: url('media/masks/catchphrase-mask.jpg');
-webkit-mask-size: contain;
mask-size: contain;
-webkit-mask-position: center;
mask-position: center;
}
Here is the page: https://satya-ame-art.com/index.php/qui-suis-je/
The idea is that the little character and the animated text should slide up from under the arc. So I need to mask them until they reach the upper half of the screen. Thank you!!!

Related

My background image is cut off at one side, how do I display the full image correctly? [duplicate]

I have a background image in the following div, but the image gets cut off:
<div style='text-align:center;background-image: url(/media/img_1_bg.jpg);background-repeat:no-repeat;width:450px;height:900px;' id="mainpage" align="center">
Is there a way to show the background image without cutting it off?
You can achieve this with the background-size property, which is now supported by most browsers.
To scale the background image to fit inside the div:
background-size: contain;
To scale the background image to cover the whole div:
background-size: cover;
JSFiddle example or runnable snippet:
#imagecontainer {
background: url("http://3.bp.blogspot.com/_EqZzf-l7OCg/TNmdtcyGBZI/AAAAAAAAAD8/KD5Y23c24go/s1600/homer-simpson-1280x1024.jpg") no-repeat;
width: 100px;
height: 200px;
border: 1px solid;
background-size: contain;
}
<div id="imagecontainer"></div>
There also exists a filter for IE 5.5+ support, as well as vendor prefixes for some older browsers.
If what you need is the image to have the same dimensions of the div, I think this is the most elegant solution:
background-size: 100% 100%;
If not, the answer by #grc is the most appropriated one.
Source:
http://www.w3schools.com/cssref/css3_pr_background-size.asp
You can use this attributes:
background-size: contain;
background-repeat: no-repeat;
and you code is then like this:
<div style="text-align:center;background-image: url(/media/img_1_bg.jpg); background-size: contain;
background-repeat: no-repeat;" id="mainpage">
background-position-x: center;
background-position-y: center;
you also use this:
background-size:contain;
height: 0;
width: 100%;
padding-top: 66,64%;
I don't know your div-values, but let's assume you've got those.
height: auto;
max-width: 600px;
Again, those are just random numbers.
It could quite hard to make the background-image (if you would want to) with a fixed width for the div, so better use max-width. And actually it isn't complicated to fill a div with an background-image, just make sure you style the parent element the right way, so the image has a place it can go into.
Chris
try any of the following,
background-size: contain;
background-size: cover;
background-size: 100%;
.container{
background-size: 100%;
}
The background-size property specifies the size of the background images.
There are different syntaxes you can use with this property: the keyword syntax ("auto", "cover" and "contain"), the one-value syntax (sets the width of the image (height becomes "auto"), the two-value syntax (first value: width of the image, second value: height).
percentage - Sets the width and height of the background image in percent of the parent element.
cover - Resize the background image to cover the entire container, even if it has to stretch the image or cut a little bit off one of the edges
contain - Resize the background image to make sure the image is fully visible
For more: https://www.w3schools.com/cssref/css3_pr_background-size.asp
Alternative:
background-size: auto 100%;
you can also try this, set background size as cover and to get it look nicer also set background position center like so :
background-size: cover;
background-position: center ;

Image on top of div-cover-background, resize proportionally

I was trying, and googling and searching, but can not solve very simple scenarion... I have:
<div class = "BG">
<div class = "image"></div>
</div>
The background should be centered, and image should be centered. On browser resize, both should resize proportionally to each other.
For the BG class, I have this:
background: url("../img/d_background.jpg");
width: 100%;
height: 2160px;
overflow: hidden;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: cover;
position: relative;
which makes BG working exactly as I need. But, as for the child image, it always incorrect size and position. Is there any way to make them work in-synch? I tried many different solution, but child image ends up either being cut-off, of being incorrect size.
you can attribute to your image the object-fit: cover; in your css
your image will take the dimension of his parent.

Set an origin point for resizing a background image in CSS

I want an image to be as responsive as can be, so they resize based on the device. But there is one image where I want to keep the center as the origin point of the resize.
For example, if the image is a small house with a nearby tree in the middle right of the image, I would like the image to resize around that house and nearby tree, rather than from the top left corner (which is the native resize point).
My image is currently set as the background-image of a div with background-size: cover.
Can this be done in CSS?
I've looked at background-origin, but I didn't see how it could answer my question.
Original image: https://i.ytimg.com/vi/pd9LAZk9V1c/maxresdefault.jpg
You can make use of the background-position:center property to align it to center.
You can also make use of background-size to adjust the image size with respect to the container.
.bg {
background: url("https://i.ytimg.com/vi/pd9LAZk9V1c/maxresdefault.jpg");
background-repeat: no-repeat;
width: 500px;
height: 500px;
background-position: center;
}
.bg2 {
background: url("https://i.ytimg.com/vi/pd9LAZk9V1c/maxresdefault.jpg");
background-repeat: no-repeat;
width: 500px;
height: 500px;
background-position: -20px 60px; /* Xvalue Yvalue */
}
<div class="bg"></div>
<br>
<br>
<div class="bg2"></div>

how to fit background image particular size without cut image size

I have a background image in the following div, but the image gets cut off
Is there a way to show the background image without cutting it off?
This is actually a pretty easy fix. Most of it comes down to using percents to specify the size of the image rather than pixels.
div {
background: url(img.jpg);
background-size: 100% 100%;
background-repeat: no-repeat;
}
You could use the background-size: cover; property to get the image centered, though what you are trying to achieve will be always impossible except in case the dimensions of the background image matches perfectly the dimensions of the container div; otherwise, it will always result in a distorted image. I guess background-size: cover; is the most approximate.
.contain_img {
width: 300px;
height: 200px;
background-image: url(https://unsplash.it/200/300?image=1082);
background-repeat: no-repeat;
background-size: cover;
background-position: 50%;
}
<div class="contain_img"></div>

What is the best way to crop an image with CSS?

I want to show a photo in my page, the DIV layer is 500 * 500px. I will replace the picture very often, the picture size is not sure, may be horizontal version may be vertical version, maybe 800*600px maybe 576*720px.
I don't want to get the photo deformation. How to set CSS or JS, make the photo show only the center 500 * 500 px, hide the around part.
Use a background image on a DIV with pre-defined dimensions, and set the image position to 50%, which essentially centers it. Whatever overflows the 500x500 will be cropped...
#yourImageDiv {
background: url(../img/image.jpg) no-repeat 50%;
height: 500px;
width: 500px;
}
One nice trick is to use a transparent PNG instead of a div and apply a background-image style to it. That way you get to use the image as you normally would (inline, etc.) but can crop at will.
#cropper {
width: 500px;
height: 500px;
background-image: url(myBackgroundImage.png);
background-repeat: no-repeat;
background-position: center center;
}
...
<img id="cropper" src="clear.png">

Resources