I want to create full screen background image within a bootstrap-grid so that it can be responsive.
I created a row and made it to 100% height so that it can fit the entire screen.
Added a 1024*768px resolution image , it perfectly appeared in background but with scroll bars.
I just want to get rid of the scroll bars so that it fit in screen. Here is my html
html,body,.container-fluid{
height:100%;
}
.row{
height:100%;
}
img {
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
width: 100vw;
height: 100vh;
}
<div class="container-fluid">
<div class="row" >
<img src="retail.jpg">
<div class="col-md-12">
</div>
</div>
</div>
Can someone help me ?
Here is something.
The picture is full screen, and the content is on bottom.
If you remove the content, the scrollbar wont appears.
Bootply: http://www.bootply.com/sFNwejI4ow
CSS:
html,body,.container-fluid{
height:100%;
}
.full{
height:100%;
}
img {
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
}
HTML:
<div class="container-fluid">
<div class="row full">
<img src="//placehold.it/640x480">
</div>
<div class="row">
<div class="col-md-12">
Custom content
</div>
</div>
</div>
This should by default remove both horizontal and vertical scrollbars:
<style type="text/css">
body {
overflow:hidden;
}
</style>
Sadly, this will also disable scrolling on page.
Alternatively, you can implement Fancy Scrolling. The scrollbar is thinner, looks better on page and has smooth scrolling.
Try this:
Here's the script: Link
Implementation:
First call the plugin on a container.
<script>
$(function() {
$( "#demo" ).customScroll();
});
</script>
Here's the CSS:
.phancy-scrollbar {
width: 5px;
border-radius: 4px;
top: 0;
position: absolute;
background: #ccc;
-moz-transition: opacity .2s;
-webkit-transition: opacity .2s;
-o-transition: opacity .2s;
-ms-transition: opacity .2s;
transition: opacity .2s;
-webkit-transition-delay: 1s;
opacity: 0;
}
.phancy-scroller .phancy-scrollbar:active, .phancy-scroller:hover .phancy-scrollbar {
opacity: 1;
-webkit-transition-delay: 0s;
}
.phancy-scrollbarbutton {
width: 100%;
border-radius: 4px;
top: 0;
position: absolute;
background-color: #999;
}
Hope this helps. Cheers!!
/* attributes overflow, background-size modified */
html,body,.container-fluid{
height:100%;
overflow: hidden; // -> newly added
}
.row{
height:100%;
}
img {
background-position: center center;
background-repeat: no-repeat;
background-size: contain cover; // modified here
width: 100vw;
height: 100vh;
}
plunker demo
Related
The image below is what I am intending to do:
Here is my situation right now:
My problem is I am not quite sure what to do with the z-index in order to have the image go inside the background but still over it.
Classes:
<img class="background" src="">
<img class="bubble_img" src="">
CSS:
.background {
width: 100%;
height: 100%;
position: relative;
z-index: 2;
display: block;
}
.bubble_img {
bottom: 0;
max-height: 110%;
position: absolute;
right: 0;
transition: all 1s;
z-index: 1;
}
If I switch the z-index around (2 and 1) the image of the person just goes on the and it goes over the background borders:
Would appreciate any help, thank you.
Instead of using the yellow background as an image, you can make it as a div element with a border-radius. Then add a overflow: hidden to partly hide the image:
div {
width: 300px;
height: 300px;
border-radius: 20% 45% 45% 5%;
background: #f5e511;
overflow: hidden;
}
div img {
max-width: 100%;
max-height: 100%;
}
<div>
<img src="https://www.pngkey.com/png/full/889-8891004_calling-girl-png-call-center-girl-png.png" />
</div>
That can be done with the CSS mask, as in the example below (the mask image here is base64 encoded because of CORS issues when using i.stack.imgur.com):
.background {
width: 100vw;
height: 100vh;
background: url(https://i.stack.imgur.com/WI6mO.png) #FE0 no-repeat;
mask: var(--mask);
-webkit-mask: var(--mask);
--mask: no-repeat url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQsAAAEhCAYAAABoYoUCAAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9bpVIrInYQcchQnSyIiuimVShChVArtOpg8tI/aNKQpLg4Cq4FB38Wqw4uzro6uAqC4A+Io5OToouUeF9SaBHjg8v7OO+dw333Af56malmxxigapaRSsSFTHZVCL4ihD6qGXRLzNTnRDEJz/V1Dx/f72I8y/ven6tHyZkM8AnEs0w3LOIN4qlNS+e8TxxhRUkhPiceNahB4keuyy6/cS447OeZESOdmieOEAuFNpbbmBUNlXiSOKqoGuX7My4rnLc4q+Uqa/bJXxjOaSvLXKcaQgKLWIIIATKqKKEMCzHaNVJMpOg87uEfdPwiuWRylcD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ygIqMziieJ/09mCygklCkTyxAKMQChEIsIFqDQadxoRALKFj/YCYs3HqaNfF7czUErB0mCxAKsYAo9PazVoTCGgKmCZMFlKV/1L5QmCzANGGygCL1DoatDoXJAkwTJguY1h+vh98KhckCTnXQz8N7d34TCbEAK4dYgEjEGYs8mw1Z3vcsIhItMPUTtb+xnHsaSUnvIA9La84krCFwaiSGYWnthUiIBVg1ol5DrCLE6M1eFt7/4plImCzg3/qHIVy5bYqIerIwXVCX33c69z788un3nomEYiEYVDI9HIVwZdX0kHwsBIOiHQ7mwuVbm+LQxFiEEMKbxzfzmexPzy4TOzq5EBY/3xCFtsXin1788FH34oXh+tvnPdltczyc//vPl24+FgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAuP0F5/sPjvUqUvgAAAAASUVORK5CYII=);
}
<div class="background"></div>
I have a DIV with "width: 100%", and after some time it moves to a different width (for example "width: 50%") with a nice transition. I want that the part which is going to decrease to get a different color. How do I do it?
.container {
width: 80%;
height: 50px;
}
.bar {
background-color: red;
width: 100%;
height: 100%;
transition-duration: 1s;
}
<div class="container">
<div class="bar"></div>
</div>
You can simply put another bar exactly behind this bar. Set it's z-index to 1. And your current bar's z-index to a higher number.
The bar that is in the back, has a black color like you wanted.
Now when the red bar decrease it's width, the one in the back becomes visible.
Here you go, the most basic working example.
(Try hovering the bar and see it moving)
By simply overlaying a pseudo-element over the static .bar element, with position:absolute, it is places above the bar and has dynamic width which you should change.
.container {
width: 80%;
height: 50px;
}
/* static background bar */
.bar {
--progress: 80%; /* css variable */
position: relative;
background-color: salmon;
width: 100%;
height: 100%;
}
/* This is the part which moves: */
.bar::before{
content: '';
background-color: darkred;
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
width: var(--progress);
transition: 1s;
}
.bar:hover {
--progress: 20%;
}
<div class="container">
<div class="bar"></div>
</div>
This solution uses a linear-gradient where I animate the background-size. I placed a fully black gradient on the .container, and a red one on the .bar, where I put a transition: background-size 1s on the black .container.
By using javascript to change a CSS variable, I can get the bar to animate.
Added a range to show-case the result.
Do note that it's always better to specify what attribute to animate with transiation, because otherwise the browser loops through all animatable properies, which can create janky animations.
let rangeInput = document.querySelector('input[type="range"');
let containerDiv = document.getElementById("container");
if (rangeInput) {
rangeInput.addEventListener('change', (event) => {
let newValue = event.target.value;
containerDiv.style.setProperty('--bar-width', `${newValue}%`);
});
}
input[type="range"] {
width: 80%;
margin-top: 1rem;
}
#container {
--bar-width: 100%;
width: 80%;
height: 50px;
background: linear-gradient(black, black);
transition: background-size 1s;
}
/* added "div" to obtain a higher specificity, to override the default background properties. */
div#container,
div.bar
{
background-repeat: no-repeat;
background-size: var(--bar-width);
}
.bar {
background: linear-gradient(red, red);
width: 100%;
height: 100%;
}
<div id="container">
<div class="bar"></div>
</div>
<input type="range" value="100" />
I have a parent and child div the child div has a background image. On hover the image scales and there is a transition on the transform. This is working correctly in all browsers except Safari, it seems on hover the border radius is being removed and then added again. Can anyone suggest a fix for this.
HTML:
<div class="image-box">
<div class="image"></div>
</div>
CSS:
.image-box {
width: 300px;
overflow: hidden;
border-radius: 20px;
}
.image {
width: 300px;
height: 200px;
background: url("http://via.placeholder.com/340x282");
background-position: center;
transition: transform 1s ease;
}
.image:hover {
transform: scale(1.5);
}
https://codepen.io/liannaryan/pen/ZxbZZa
For anyone having the same issue the solution is.
.image-box {
width: 300px;
overflow: hidden;
border-radius: 20px;
-webkit-border-radius: $border-radius;
-webkit-mask-image: -webkit-radial-gradient(circle, white, white);
}
So I'm learning CSS transitions and transforms and am trying to make a simple slider in CodePen. The basic idea is that I have one div on top of another and I want the first one to slide off the second when hovered on. It works fine without any overflow property, but once I added overflow: hidden to the underlying square, it pushes the overlying square down. Why is this?
http://codepen.io/johnnycopes/pen/BKReOq
--- HTML ---
<div class="container">
<div class="shape">
<div class="shape-cover">
</div>
</div>
</div>
--- CSS ---
body {
font-family: Verdana;
background: #fff0a5;
}
.container {
margin: 0 auto
}
.shape {
margin: 50px auto 0;
width: 200px;
height: 200px;
overflow: hidden;
background: #ffb03b;
}
.shape-cover {
margin: 50px auto 0;
height: 200px;
width: 200px;
background: #468966;
transform: translateX(0%);
transition: transform .5s ease-in-out;
}
.shape-cover:hover {
transform: translateX(100%);
}
It is because you are using a margin on the "overlaying square".
shape-cover is inside the shape, so the margin of the shape-cover will me relative to its parent.
So try removing the margin on the shape-cover div.
I have bottom line, on the right side there are grey div, I want on hover to show up full that div. At the beginning grey div is hidden. How could I solve this problem? Thanks!
There is fiddle link
<body>
<div id="wrap">
</div>
<div id="footer">
<div class="container">
<div id="footer_right_wrapper"></div>
</div>
</div>
html, body {
height: 100%;
/* The html and body elements cannot have any padding or margin. */}
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto !important;
height: 100%;
/* Negative indent footer by its height */
margin: 0 auto -61px;
/* Pad bottom by footer height */
padding: 0 0 60px;
}
#footer {
height: 61px;
background-color: red;
color: black;
}
.container {
height: 61px;
overflow: hidden;
}
#footer_right_wrapper {
width: 100px;
height: 217px;
background-color: grey;
float: right;
}
Use :hover selector attribute:
show/hide grey element:
Fiddle: http://jsfiddle.net/or2y2fzg/
#footer_right_wrapper {
display: none;
}
#footer:hover #footer_right_wrapper {
display: block;
}
If I understood you correctly, you want to show the grey div once you hover your cursor over the #footer?
.
Expand grey element:
If you want to expand grey element to fill #footer element: http://jsfiddle.net/r30nxzxk/
#footer_right_wrapper {
width: 100px;
-webkit-transition: all 200ms ease-out;
-moz-transition: all 200ms ease-out;
-ms-transition: all 200ms ease-out;
-o-transition: all 200ms ease-out;
transition: all 200ms ease-out;
}
#footer_right_wrapper:hover {
width: 100%;
}
Note that I added CSS transition to have a smooth UX.