Why In the code below if I change
(height from vh to %) following change occur:
.banner {
width: 100%;
height: 100vh;
background-image: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)), url(background.jpg);
background-size: cover;
background-position: center;
}
.banner {
width: 100%;
height: 100%;
background-image: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)), url(background.jpg);
background-size: cover;
background-position: center;
}
At banners height 100vh
before
At banners height 100%
At 100%
Why there is difference, as the 100% means the 100 percent of container. And here container is div(class banner) And it occupy the full page.
Is it possible to make same webpage with 100% height of banner?
VH gives height as screen size
100% returns the height of the found parent element.
.banner {
width: 100%;
height: 100vh;
background-image: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)), url('https://images.pexels.com/photos/15286/pexels-photo.jpg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1');
background-size: cover;
background-position: center;
margin-bottom:1rem;
}
header{
height:100px;
}
.banner2 {
width: 100%;
height: 100%;
background-image: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)), url('https://images.pexels.com/photos/15286/pexels-photo.jpg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1');
background-size: cover;
background-position: center;
}
<div class="banner"></div>
<header>
<div class="banner2"></div>
</header>
Difference between % and vh :-
height: 100vh;
Example: If your device's viewport size is 1366 x 786px, the element considers the height as "786px" which means it occupies the full viewport height of the screen.
height: 100%;
Example: This depends on the parent element. It occupies the full height of the parent element.
Hope this helps. #AmirSaudagar
Related
I am facing an issue with making the header in the main page layout split into two images from bottom left to top right. All the resources that I found are split them into two colors. However, when I want to add pictures, I could not see any result.
See the code that I did and I do not know how to remove the space between them
class-image-1 {
background-image: url(/img/imag-1-bg.png);
height: 100vh;
-webkit-clip-path: polygon(1px 100vh,100% 1px,311px -1px,0px 0px);
background-repeat: no-repeat;
position: relative;
background-position: center;
background-size: cover;
background-attachment: fixed;
margin: 0 auto;
}
class-image-2{
background-image: url(/img/bg.jpg);
height: 100vh;
-webkit-clip-path: polygon(0px 100vh,100% 100vh,100% 1px);
position: relative;
background-position: center;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
margin: 0 auto;
}
I did the same code above but I got space between the images I want them in one page. Just to clearly see this image it might give you an idea.
Your code is almost good, you are simply doing wrong with positions. You should make them absolute position inside a container, they should behave like layers (one above the other). I also replaced the values in the clip-path with 0 and 100% so it's more generic :
body {
margin: 0;
padding: 0;
min-height: 600px;
}
.banner {
height: 100vh;
position: relative;
}
.class-image {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-attachment: fixed;
}
.class-image-1 {
background-image: url(https://lorempixel.com/800/800/);
-webkit-clip-path: polygon(0 100%, 100% 0, 100% 0px, 0 0);
}
.class-image-2 {
background-image: url(https://lorempixel.com/800/700/);
-webkit-clip-path: polygon(0 100%, 100% 100%, 100% 0);
}
<div class="banner">
<div class="class-image class-image-2">
</div>
<div class="class-image class-image-1">
</div>
</div>
I have an image which covers an entire element using something like #myDiv {background-image: url("../images/background.jpg "); background-repeat: no-repeat; background-size: cover; background-position: center;}
Next, I would like to gray out the left side of the image similar to that shown below.
How can this be accomplished? It doesn't need to look exactly the same, but only similar.
You may use linear-gradients since you use background-image
html {
min-height: 100%;
background:
linear-gradient(to right, rgba(0, 0, 0, 0.75) 60px, transparent 60px), /* the gray, reset opacity to your needs : here 0.75 */
linear-gradient(to right, transparent 60px, red 60px, red 64px, transparent 64px), /* a red line ? */
url(http://lorempixel.com/200/200/fashion) /* and finally, image laying underneath gradients */;
background-size:
auto,
auto,
auto 100%;
}
you could play with a pseudoelement and a RGBA background, e.g.
#mydiv {
background: url(http://www.psdgraphics.com/file/cherry-wood.jpg);
width: 250px;
height: 400px;
position: relative;
}
#mydiv:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 30%;
background: rgba(255,255,255, .3);
}
Codepen: http://codepen.io/anon/pen/OyVYwe
Or you could simply add a transparent left border to the element, e.g.
box-sizing: border-box;
background-origin: border-box;
border-left: 50px rgba(255,255,255, .3) solid;
Codepen: http://codepen.io/anon/pen/ZbGNqL
Or you could use an inset box-shadow
box-shadow: 80px 0 0 0px rgba(255, 255, 255, .2) inset;
Codepen: http://codepen.io/anon/pen/avOrXE
Please do not vote for this answer as it was user3791372's comment (yet not yet an answer) and not mine. If you think it is the right approach, please provide a comment why you think so.
http://codepen.io/anon/pen/MaaWMB
<div id="mydiv">
<div id="sidebar"></div>
</div>
#mydiv {
background: url(http://www.psdgraphics.com/file/cherry-wood.jpg) bottom;
width: 230px;
height: 400px;
}
#sidebar {
background-color: white;
opacity: 0.2;
filter: alpha(opacity=20);
width: 50px;
height: 100%;
}
I'm working with Angular and trying to bind an image to a div background.
The background need to be darker from the original image so text can be include later :
The problem Is - The image does not show properly inside the boundaries of the div; some parts of the image are missing.
.PictureCover {
background-size: cover;
margin: 10px;
width: 70px;
height: 100px;
float: left;
}
<div class="PictureCover" style="background-image:
linear-gradient(
rgba(0, 0, 0, 0.5),
rgba(0, 0, 0, 0.5)
),
url(http://a57.foxnews.com/global.fncstatic.com/static/managed/img/Entertainment/0/0/tom-cruise-playboy-interview-660.jpg);"></div>
The url to the image from the example is temporary and will be replaced with a binding to a image from object in angular so inculding 'background-image' inside the PictureCover css class is not an option.
Thanks.
In .PictureCover, you could add:
background-position: center center;
.PictureCover {
background-size: cover;
margin: 10px;
width: 70px;
height: 100px;
float: left;
background-position: center center;
}
<div class="PictureCover" style="background-image:
linear-gradient(
rgba(0, 0, 0, 0.5),
rgba(0, 0, 0, 0.5)
),
url(http://a57.foxnews.com/global.fncstatic.com/static/managed/img/Entertainment/0/0/tom-cruise-playboy-interview-660.jpg);"></div>
#page-background {
position: fixed;
background-image: url(/images/background-1600.jpg);
display: table;
top:0px;
left:0px;
width: 100%;
height: 100%;
margin-bottom: 0rem;
text-align:center;
background-size: cover;
background-position: 25% 50%;
}
#header {
position:fixed;
margin-bottom: 0rem;
text-align: center;
left:0px;
top:0px;
height: $header-height;
width:100%;
#include background-image(linear-gradient(to top, rgba(0, 8, 39, 0.15) 0%,rgba(0, 8, 39, 0.65) 10%, rgba(0, 8, 39, 0.85) 40%, rgba(0, 8, 39, 0.95) 95%));
z-index: 9999;
}
#footer {
position:fixed;
margin-bottom: 0rem;
text-align: center;
div {
vertical-align: middle;
}
left:0px;
bottom:0px;
height:5rem;
width:100%;
#include background-image(linear-gradient(to bottom, rgba(0, 8, 39, 0.15) 0%,rgba(0, 8, 39, 0.65) 10%, rgba(0, 8, 39, 0.85) 40%, rgba(0, 8, 39, 0.95) 95%));
z-index: 9999;
}
In the HTML the very first thing that is placed is the #page-background and it appears that if instead it is placed elsewhere it no longer takes up the whole page. Is there a way to avoid this? By that I mean, add a background image somewhere deeper in the DOM but which -- via absolute or fixed positioning -- is able to command the entire screen?
The positioning of an element is always relative to its containing block.
If you use position: absolute, the containing block is the padding-edge of the next parent element with position: relative|absolute|fixed.
If you use position: fixed, the containing block is independent of the element's position in the DOM because the containing block is always the viewport.
I created a simple JSFiddle: http://jsfiddle.net/n6s9gx61/1/
I have a logo image that is refusing to display in Safari 4/5. Can anyone shed any light on this?
This is the CSS / (uncompiled less) -
background: url("../img/logos%20and%20icons/logoLrg.png") no-repeat scroll 0 0 / contain rgba(0, 0, 0, 0);
#media(max-width:400px){
background: url("../img/logos%20and%20icons/logoSML.png") no-repeat scroll 0 right / contain rgba(0, 0, 0, 0);
}
display: block;
height: 50px;
margin-top: 29px;
width: 205px;
z-index: 255;
try without spaces
background: url("../img/logos and icons/logoLrg.png") no-repeat scroll 0 0 / contain rgba(0, 0, 0, 0);
#media(max-width:400px){
background: url("../img/logos and icons/logoSML.png") no-repeat scroll 0 right / contain rgba(0, 0, 0, 0);
}
display: block;
height: 50px;
margin-top: 29px;
width: 205px;
z-index: 255;
You don't have to use url encoding to set a path for a background image in a style sheet. It seems to me that if you replace %20 by a + sign you probably solve that issue. I'll come back with more information about it though.