I'm currently having some problems displaying divs with 100% height in IE, it works fine in every other browser, it's just IE that is giving me some trouble and I'm not sure how to resolve it.
Here's some of my code:
HTML:
<div id="content">
<div id="box-01" class="slide" style="color: #F26964; background-color: #003218;">
<div class="text-content">
TEXT GOES HERE
</div>
</div>
<div id="box-02" class="slide" style="color: #F2F1EF; background-color: #70858E;">
<div class="text-content">
TEXT GOES HERE
</div>
</div>
<div id="box-03" class="slide" style="color: #F2F1EF; background-color: #003218">
<div class="text-content">
TEXT GOES HERE
</div>
</div>
</div>
CSS:
html, body {
margin:0;
padding:0;
height:100%;
border:none
}
#content {
width: 100%;
height: 100%;
margin: 0;
position: absolute;
top: 0px;
left: 0px;
}
.slide {
width: 100%;
height: 100%;
margin: 0 auto;
text-align: center;
position: relative;
display: table;
vertical-align: middle;
background: no-repeat 50% 50%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.text-content {
text-align: center;
display: table-cell;
vertical-align: middle;
text-transform: uppercase;
}
So I have a set of relatively positioned divs, each one fitting to the browser window size, like I say this all works fine in every browser except IE, in particular the 100% height style attribute not being recognised.
After doing a little bit of research I found that this may have something to do with the text being in a table (which is necessary as I want to centre the text horizontally and vertically) but I've not got a clue how this issue can be resolved, any suggestions would be greatly appreciated!
There are a number of strategies discussed here:
http://blog.themeforest.net/tutorials/vertical-centering-with-css/
This appears to work in IE FF & Chrome:
http://codepen.io/anon/pen/asqpL
Related
I am trying to achieve this composite image from a combination of images:
I have tried div tags with relative positioning and z-indices, but to no avail. Complicating things is that I need the composite image to be able to resize automatically, with all sub-images resizing appropriately yet staying aligned.
The solution needs to be html and css only. No javascript. And not nested svgs (I need this to also be appropriate for bitmap images).
Here is my feeble attempt:
https://jsfiddle.net/kb0sgd7h/1/
<div style="width:100%;position:relative; z-index:0; text-align: center; display: block;">
<div style="positive:absolute; width: 100%; height: 100%; left:10; top:0; z-index:1;text-align: center;display: block;">
<img src="https://raw.githubusercontent.com/lnjustin/svgtest/master/circles.svg"/>
</div>
<div style="positive:absolute; width: 80%; height: 80%; left:10; top:0; z-index:0;text-align: center;display: block;">
<img src="https://raw.githubusercontent.com/lnjustin/svgtest/master/justin.svg"/>
</div>
<div style="positive:absolute; width: 80px; height: 80px; left:0; top:0; margin-top:-100px; z-index:2;text-align: center;display: block;">
<img src="https://raw.githubusercontent.com/lnjustin/svgtest/master/stay-home.svg"/>
</div>
<div style="positive:absolute; width: 80px; height: 80px; left:0; top:-100; margin-top:-100px; z-index:2;text-align: center;display: block;">
<img src="https://raw.githubusercontent.com/lnjustin/svgtest/master/employee.svg"/>
</div>
</div>
How do I do this??
One approach you can use is to have multiple background-images (each with their own background-position and background-size). I've included a demo with a stock image and two blue circles composited on top. Everything should scale together as you resize the page.
body {
margin: 0;
}
div {
width: 100%;
padding-top: 100%;
background-repeat: no-repeat;
background-position: bottom 10% left 10%, bottom 10% right 10%, center;
background-size: 20%, 20%, cover;
background-image: url('https://www.freepngimg.com/thumb/shape/29779-8-circle-file.png'), url('https://www.freepngimg.com/thumb/shape/29779-8-circle-file.png'), url('https://www.b3multimedia.ie/wp-content/uploads/2017/06/free-stock-images-websites.jpg');
}
<div></div>
The Problem
I have a user image, which I want to scale up and down with the window so that the height is always 100% and the image stays centered.
Example 1
This example scales as the window is resized, but the height doesn't stay at 100% and therefore gets cut off at the bottom.
.user {
width: 100%;
height: 100%;
object-fit: cover;
object-position: 50% 0%;
}
CodePen Example 1
Example 2
This example works perfectly, apart from when the width of the browser window is smaller than the width of the image, the right-hand side is cut off.
I do want the image to be cropped, but I want the right and left sides to be cropped equally.
.user {
object-position: center;
display: block;
height: 100%;
margin-left: auto;
margin-right: auto;
}
CodePen Example 2
Visual Example
Here is an example of how I want the images to appear when the browser is scaled horizontally/vertically.
An idea is to use multiple background like this:
I used multiple div to illustrate with different sizes
body,
html {
height: 100vh;
margin: 0;
}
.bg-shine {
background-position: center;
background-repeat: no-repeat;
background-size: auto 100%, cover;
background-image: url("https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png"), url("https://t.motionelements.com/stock-video/design-elements/me1656952-blue-sunrise-background-hd-a0120-poster.jpg");
}
<div style="display: inline-block;">
<div class="bg-shine" style="height:100px;width:400px;">
</div>
<div class="bg-shine" style="height:100px;width:200px;">
</div>
</div>
<div style="display: inline-block;">
<div class="bg-shine" style="height:200px;width:100px;">
</div>
</div>
Update
To avoid using the image within CSS you can consider the inline style and a separate div for the user image so that you have almost the same markup as using an image tag:
body,
html {
height: 100vh;
margin: 0;
}
.bg-shine {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-image: url("https://t.motionelements.com/stock-video/design-elements/me1656952-blue-sunrise-background-hd-a0120-poster.jpg");
}
.bg-shine>div {
background-size: auto 100%;
background-position: center;
background-repeat: no-repeat;
height:100%;
}
<div style="display: inline-block;">
<div class="bg-shine" style="height:100px;width:400px;">
<div style="background-image:url('https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png')"></div>
</div>
<div class="bg-shine" style="height:100px;width:200px;">
<div style="background-image:url('https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png')"></div>
</div>
</div>
<div style="display: inline-block;">
<div class="bg-shine" style="height:200px;width:100px;">
<div style="background-image:url('https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png')"></div>
</div>
</div>
I like your question! I approached it from a different angle, and tried to use background rather than img element. Please see the results here:
https://codepen.io/Varin/pen/xYqXQe
body, html {
height: 100vh;
margin: 0;
}
.bg-shine {
height: 100vh;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-image: url("http://t.motionelements.com/stock-video/design-elements/me1656952-blue-sunrise-background-hd-a0120-poster.jpg");
position: relative;
}
.image {
padding:0;
margin:0;
width: 100%;
height:100%;
position:absolute;
top:50%;
left:50%;
transform: translate(-50%, -50%);
background-image:url('http://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png');
background-repeat: no-repeat;
background-position: center center;
background-size: auto 100%;
}
<div class="bg-shine">
<div class="image">
</div>
</div>
I'm trying to make background image not moving on scroll with background-attachment: fixed. But this only works in Chrome and IE11. Id does not work in Firefox and Edge. Could someone tell me what I'm doing wrong because this should be pretty basic thing to work. Also i have tried to put another div inside the .header-homepage with position: fixed and full width and height but that is also not working in Firefox or edge and it also breaks everything in chrome for some reasons. Same thing for pseudo element on .header-homepage.
css
html {
min-height: 100%;
height: 100%;
}
body {
margin: 0;
padding: 0;
min-height: 100%;
height: 100%;
background: #000;
}
.header-homepage {
background-image: url("https://images.unsplash.com/16/unsplash_5263605581e32_1.JPG");
background-repeat: no-repeat;
background-position: bottom;
background-attachment: fixed;
width: 100%;
height: 100%;
background-size: cover;
position: relative;
overflow: hidden;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
html
<!--header-->
<header class="header-homepage">
<!--intro-->
<div class="header-homepage__intro">
<h1>
Text
</h1>
<div class="header-homepage__intro__description">
Text text text
</div>
</div>
<!--end intro-->
</header>
<!--end header-->
Demo: http://codepen.io/riogrande/pen/LxeVbR
I'm trying to put a responsive form inside a div with a background image that takes the full width off the screen. After searching around a while it seemed the best option to make the background image div the full size of the image was to work with a padding-bottom the size of the image.
The problem now is, when I watch it on smaller screens the background image div is to small to fit the content of the form. I tried using min-width:100% but that didn't help.
html:
<div class="background-image-div">
<div class="centerer-div">
<form id="form">
"some form stuff"
</form>
</div>
</div>
css:
.background-image-div{
background-image: url(background.png)
background-repeat: no-repeat;
background-position-x: center;
background-position-y: top;
width: 100%;
background-size: contain;
position: relative;
padding-bottom: 25%;
}
.centerer-div{
position: absolute;
top: 0;
bottom: 0;
margin: auto;
height: auto;
display: table;
width: 100%;
}
#form{
text-align: center;
}
Maybe it's because you're not closing the form tag?
<div class="background-image-div">
<div class="centerer-div">
<form id="form">
"some form stuff"
</form>
</div>
</div>
I saw quite a few similar questions but could not find a fix.
Open this sample and resize the browser to make its height shorter
than the main div height, ~400 pixels.
When scrolling down, the background image attached to the body is cut off:
The code:
html { height: 100%; color: white; }
body { height:100%; padding: 0; margin: 0; background:url(bg.jpg) repeat-x; background-position: bottom; background-size: contain; }
/*#pageWrap { background:url(bg.jpg) repeat-x;}*/
#page { height:100%; }
#divHeader { width:100%; height:115px; }
#divMain { width:600px; height:400px; border: solid 1px brown; }
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="pageWrap">
<div id="page">
<div id="divHeader">Header</div>
<div id="divMain">Main</div>
<div id="divFooter"><p>All Rights Reserved. Blabla® 2015</p></div>
</div>
</div>
</body>
</html>
I tried to move the background image to the pageWrap div as someone suggested.
It solves the vertical scroll problem, but creates a similar problem horizontally:
when the window is too narrow and you scroll left, the image is cut off on the right.
Any real solution?
You've got repeat-x value defined, then the background only repeats in the X axis (horizontally).
To solve this you've got two different solutions for two different purposes.
You can put repeat value to repeat in X and Y axis, but this have a problem because your background is a gradient, and if you repeat it in Y axis the visual effect will be bad.
The other solution (in my opinion the best solution) is to define that background covers the whole element. This can be achieved with the property background-size: cover.
The change will be that:
body {
background:url(bg.jpg) repeat-x;
background-size: cover;
}
Tell me if this solves your problem.
Exists another solution with the background-attachment property. It can be defined as fixed value and the scroll doesn't move the background.
body {
background:url(bg.jpg) repeat-x;
background-attachment: fixed;
}
Try these background styles:
background: url(bg.jpg);
background-position: 100% 100%;
background-size: cover;
Since repeating a gradient doesn't look that good, I guess you just want that background alwas cover your whole viewport and not scroll with it? That would be done with no-repeat and cover, like this:
body {
height:100%;
padding: 0;
margin: 0;
background:url(bg.jpg) no-repeat fixed;
background-position: bottom;
background-size: cover;
}
Use background-attachment: fixed on the body, like so:
html {
height: 100%;
color: white;
}
body {
height: 100%;
padding: 0;
margin: 0;
background: url(https://glaring-inferno-4496.firebaseapp.com/bg.jpg) repeat-x;
background-position: bottom;
background-size: contain;
}
/*#pageWrap { background:url(bg.jpg) repeat-x;}*/
#page {
height: 100%;
}
#divHeader {
width: 100%;
height: 115px;
}
#divMain {
width: 600px;
height: 400px;
border: solid 1px brown;
}
/*new code from here:*/
body {
background-attachment: fixed;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="pageWrap">
<div id="page">
<div id="divHeader">Header</div>
<div id="divMain">Main</div>
<div id="divFooter">
<p>All Rights Reserved. Blabla® 2015</p>
</div>
</div>
</div>
</body>
</html>
You can use un a CSS property called overflow-y:auto and asign to the father component, of this way is puts a scroll bar when the viewport height reduce him size and your background image don´t cuts anymore.
Try something like this:
.father {
height: 100vh;
background-image: url(https://static.vecteezy.com/system/resources/previews/001/331/268/original/happy-halloween-from-the-spooky-castle-free-vector.jpg);
background-size: 100% 100vh;
background-position: center;
background-repeat: repeat;
overflow-y: auto;
}
.child {
height: 1500px;
}
<div class="father">
<div class="child">
<h1 style="color: white">¡Hello World!</h1>
</div>
</div>