I'm trying to create slider backgrounds. Basically create a container and put couple images inside of this container, each image is a responsive background for the whole page. In result we can have multiple backgrounds and a slider to change them. Well if I put all measurement in px than everything is work.but as soon I put in percentage since it suppose to be a responsive design. It get me instead of horizontal scroll a vertical one.
Something like that:
<div class="slider-wrap">
<div class="slide" id="slide-0">
</div>
<div class="slide" id="slide-1">
</div>
</div>
css:
* {
box-sizing: border-box;
font-family: sans-serif;
font-size: 10px;
color: white;
margin: 0;
padding: 0;
outline: none;
text-decoration: none; /*clear href decoration*/
}
body {
margin: 0px auto;
min-height: 100vh;
}
.slider-wrap {
width:100%;
height:100vh;
min-height: 100vh;
overflow-x: scroll;
}
.slide {
display: inline-block;
width: 100%;
min-height: 100vh;
float:left;
}
#slide-1 {
background-image: url(img/m_m.jpg);
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
}
#slide-0 {
background-image: url(img/b_m.jpg);
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
}
So how to make a multiple background images with horizontal scroll
Related
Is there anyway to make my body background image to be responsive in any mobile view? Especially when the height is 412x980? I know how to use some proper background cover
body {
background: url(../../something.jpg);
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
}
But I wanted to not use fixed because I need to stay all elements on that background image.
EDIT:
After using #VIKESIR provided code, I still getting whitespace after trying to resizing every mobile views, I got the mobile view sizes here. Something like this
#media screen and (max-width: 479px) {
* {
margin: 0;
padding: 0;
}
html,body {
width: 100%;
height: 100%;
box-sizing: border-box;
}
body {
background: url(https://www.psdstack.com/wp-content/uploads/2019/08/copyright-free-images-750x420.jpg) no-repeat center cover;
width: 100%;
min-height: 100vh;
}
}
<body></body>
and this is what I meant still getting a whitespace after using the provided code.
By default body height is nothing, so we need to define height.
Here is some css except body tag in last one, that you can configure in every style.css when you create new stylesheet.
* {
margin: 0;
padding: 0;
}
html,body {
width: 100%;
height: 100%;
box-sizing: border-box;
}
body {
background-color: #fa0;
}
.title {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.title h1 {
color: #000;
text-shadow: 1px 1px 0px #fff;
text-align: center;
}
#media (max-width: 479px) {
body {
background: url(https://www.psdstack.com/wp-content/uploads/2019/08/copyright-free-images-750x420.jpg) no-repeat center / cover;
width: 100%;
min-height: 100vh;
}
}
<body>
<div class="title">
<h1>TESTING<br>TESTING TESTING</h1>
</div>
</body>
I have two div's above one another. The top div has a background .svg at the bottom with the same color as the background of the bottom div. These should align perfectly, however, they do not. There is an ever so slight amount of transparent space between them. This space disappears when zooming in and reappears when zooming in even further (see screenshots).
.top {
width: 100%;
height: 100vh;
background-color: #3772ff;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%25%22%20height%3D%22100%25%22%20viewBox%3D%220%200%20378%20378%22%3E%3Cpath%20d%3D%22M0%2C378l378%2C-0l-0%2C-47.25l-378%2C47.25Z%22%20style%3D%22fill%3A%2301161e%3B%22%2F%3E%3C%2Fsvg%3E");
background-repeat: no-repeat;
background-position: left bottom;
background-attachment: scroll;
background-size: 100%;
margin: 0;
}
.bottom {
background-color: #01161e;
padding: 128px 20%;
}
<div class="top"></div>
<div class="bottom"></div>
Screenshots:
100% zoom:
A bit zoomed in:
Zooming in even further:
There may be a more elegant solution to be had, but simply pulling the lower element up a fraction of a pixel overcomes the sub-pixel rounding issue.
.top {
width: 100%;
height: 100vh;
background-color: #3772ff;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%25%22%20height%3D%22100%25%22%20viewBox%3D%220%200%20378%20378%22%3E%3Cpath%20d%3D%22M0%2C378l378%2C-0l-0%2C-47.25l-378%2C47.25Z%22%20style%3D%22fill%3A%2301161e%3B%22%2F%3E%3C%2Fsvg%3E");
background-repeat: no-repeat;
background-position: left bottom;
background-attachment: scroll;
background-size: 100%;
margin: 0;
}
.bottom {
background-color: #01161e;
padding: 128px 20%;
margin-top: -.5px;
/* transform: translateY(-.5px); alternative approach */
}
<div class="top"></div>
<div class="bottom"></div>
Of course, you could just set the body background (or that of a container element) to hide it as well:
.container {
background-color: #01161e;
}
.top {
width: 100%;
height: 100vh;
background-color: #3772ff;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%25%22%20height%3D%22100%25%22%20viewBox%3D%220%200%20378%20378%22%3E%3Cpath%20d%3D%22M0%2C378l378%2C-0l-0%2C-47.25l-378%2C47.25Z%22%20style%3D%22fill%3A%2301161e%3B%22%2F%3E%3C%2Fsvg%3E");
background-repeat: no-repeat;
background-position: left bottom;
background-attachment: scroll;
background-size: 100%;
margin: 0;
}
.bottom {
background-color: #01161e;
padding: 128px 20%;
}
<div class="container">
<div class="top"></div>
<div class="bottom"></div>
</div>
The background image doesn't fits to the browser window's screen. The background image covers only a portion of the screen maintaining its aspect ratio.I want the background image to cover the entire screen on which it runs.Please help!
html
<div class="container">
<h1> GAME</h1>
<div class="color-overlay"></div>
</div>
css
.container {
background-size: cover;
background: #000 url(images/group11.jpg);
color: #fff;
background-repeat:no-repeat;
background-position:center;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.color-overlay {
width: 100%;
height: 100%;
background: blue;
opacity: .6;
position: absolute;
}
The problem is that you first set background-size:cover then you set background .
Setting background ( which includes repeat,size,position,image etc. ) after the background-size will overwrite cover with the default setting.
You either set background-size:cover after the background either you set all background declarations that you need ( color,repeat,image etc ) separately, either you declare all in one line using just background
See below
.container {
background: #000 url(http://via.placeholder.com/350x150);
/* bg size after */
background-size: cover;
color: #fff;
background-repeat: no-repeat;
background-position: center;
display: flex;
justify-content: center;
align-items: center;
position: relative;
height:100vh;
/* OR set all separately
background-image: url(http://via.placeholder.com/350x150);
background-color: #000;
background-size:cover;
background-repeat:no-repeat;
background-position:center;
*/
/* OR set all in one line
background: url(http://via.placeholder.com/350x150) no-repeat scroll center center / cover #000;
*/
}
.color-overlay {
width: 100%;
height: 100%;
background: blue;
opacity: .6;
position: absolute;
}
<div class="container">
<h1> GAME</h1>
<div class="color-overlay"></div>
</div>
I am using this code to use an image as background inside <body> tag
body {
margin: 0; auto;
font-family: Arial, Helvetica, sans-serif;
background-image: url('image-blur.png');
background-repeat: no-repeat;
display: table-cell;
vertical-align: middle;
opacity:1;
}
But the image overlays the white background of the page. I would like the image to overlay only on the left side and right side of the html page. In the center of the page data exists. I need to maintain the white color background on data area but at the same time use as a fixed background the image. How can i achieve this? Any help appreciated.
Here is a possible implementation of that layout:
Note: All the colors, dimensions and images are just for demonstrations purposes. Tweak them to your needs.
https://codepen.io/nakata/pen/LQddvz
<div class="main">
<div class="image"></div>
<div class="content">Stuff</div>
</div>
body {
margin: 0;
}
.main {
height: 100vh;
width: 100vw;
background: red;
display: flex;
justify-content: center;
align-items:center;
z-index: 2;
position: relative;
}
.image {
background-image: url('https://placekitten.com/200/200?image=1');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height: 500px;
width: 1500px;
position: absolute;
z-index: -1;
}
.content {
background: #fff;
height: 500px;
width: 800px;
}
You can simply use multiple background:
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background:
linear-gradient(to right,transparent 20%, white 20%, white 80%,transparent 0)
,url('https://lorempixel.com/1000/1000/');
min-height:100vh;
}
I'm trying to make my background from website so if I'll go to mobile it will stretch it by height in center.
Something from that: large screen to that small screen
my code is:
body{
background-image: url("Tie_logo_shaders.jpg");
background-color: black;
background-size: 100% 100%;
background-size: cover;
background-repeat: no-repeat;
}
Try this code
.bg-img{
background: url("https://s-media-cache-ak0.pinimg.com/originals/27/3e/43/273e43a71854d8359186ecc348370f8d.jpg") no-repeat center center;
min-height: 100%;
position: relative;
}
html,body{
margin: 0;
padding: 0;
height: 100%;
}
<body>
<div class="bg-img">
</div>
</body>