Lots of websites now have a fullscreen background photo (or even video, such as http://www.paypal.fr).
How to add a fullscreen background photo to a Bootstrap page like this demo:
http://getbootstrap.com/examples/cover/
I tried
<div class="site-wrapper">
<img src="photo.jpg">
but the photo was bad positioned.
There are many ways to do this. You could do it via css:
body {
background: url('photo.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
}
Use background-size: cover; This will give you the aspect ratio you are looking for
Se DEMO
body{
background: url("http://upload.wikimedia.org/wikipedia/en/b/b2/Brad_Pitt_boxing.jpg") no-repeat 0 0;
background-size:cover;
}
Actually you can add a css rule to body in order to display a picture as a background.
body
{
background-image: url('photo.jpg');
}
In addition to this, if you want background image to cover whole screen, you may add background-size property.
body
{
background-image: url('photo.jpg');
background-size: cover;
}
If you do not want to resize image on narrower screens to keep aspect ratio, you may write conditional rule like the following. Remember to prepare photos differently resized for some screen sizes.
/*for screens larger than 959px */
#media (min-width: 960px) {
body {
background-image: url('photo-xl.jpg');
background-size: cover;
}
}
/*for screens larger than 767px */
#media (min-width: 768px) {
body {
background-image: url('photo-lg.jpg');
background-size: cover;
}
}
/*for screens larger than 479px */
#media (min-width: 480px) {
body {
background-image: url('photo-xs.jpg');
background-size: cover;
}
}
Related
I have a background image setup in my css and everything seems to display fine on the desktop but when I try viewing on my ipad or iphone 6 plus I don't get the image at all (not even an off-center image).
How can I be sure my images resize, center and appear on mobile?
.landpage-img {
background: url('../img/bg-neon-01-2000x1333.jpg') center center no-repeat fixed !important;
height: 1333px;
background-size: cover;
}
#media only screen and (max-width: 1024px) {
.landpage-img {
background: url('../img/bg-neon-01-1024x671.jpg') 50% 0 no-repeat center center fixed !important;
height: 671px;
background-size: cover;
}
}
#media only screen and (max-width: 991px) {
.landpage-img {
background: url('../img/bg-neon-01--991x649.jpg') 50% 80% center center no-repeat fixed;
height: 649px;
background-size: cover;
}
}
#media only screen and (min-width: 0px) and (max-width: 767px) {
.landpage-img {
background: url('../img/bg-neon-01--767x502.jpg') 50% 80% no-repeat fixed !important;
height: 767px;
background-size: cover;
}
}
I am not sure what image you are working with but this should fix the problem (no media queries needed).
body {
background-image: url(/example/example.jpg);
background-repeat: no-repeat;
background-size: cover;
}
Also, see https://www.w3schools.com/css/css_background.asp
I am trying to make header responsive. Currently header is fixed and when you view it from different screen resoultions it is not lookin good.
#tie-wrapper #theme-header {
background-image: url(http://example.com/header-image.jpg);
background-repeat: no-repeat;
}
I wish to have same image on different resolutions. It should decrease with website. Also logo is centered so the image should be.
I really don't know how to add this image for different resolutions.
Thanks
You can use different images at different screen widths using css:
#media only screen and (max-width: 1023px) {
#tie-wrapper #theme-header {
background: url('http://example.com/header-image_FULLWIDTH.jpg') center center/cover no-repeat;
min-height: 500px;
width: 100%;
}
}
#media only screen and (max-width: 767px) {
#tie-wrapper #theme-header {
background: url('http://example.com/header-image_LARGE.jpg') center center/cover no-repeat;
min-height: 400px;
}
}
#media only screen and (max-width: 480px) {
#tie-wrapper #theme-header {
background: url('http://example.com/header-image_MEDIUM.jpg') center center/cover no-repeat;
min-height: 300px;
}
}
I will normally add this code into my template file and using wp_get_attachement(), load up different sizes of images. Or you can hard code it in your styles.css. Either way.
First of all, I am unable to provide any URL details as I am developing on localhost - for now. However, hopefully, with my clear description below, you may be able to provide a suggestion. :-)
I've been trying to positioning an image in the .header-wrap #header of my Wordpress site using Uplift theme. The code below has worked correctly, but the image goes below the header due to the aspect ratio which means that its height is clearly more than 160px. I have also tried background sizing and background-position - none of these provide the correct outcome.
I am aware that I need to introduce media queries, but I need to first of all get this curved image working on large screens.
I'm needing the image to sit directly under the header logo and to be positioned in the site header template so that it is scalable for all devices but adopts the sticky header so the body scrolls underneath the image.
I've provided two screenshots: first screenshot using the below code, which currently falls below the header area, and the other screenshot displays what it should look like on all screens.
The below code would work if the image wasn't so customised to a particular shape.
So, I need the image to stay fixed, so when a user scrolls up or down, the content of the page should scroll under the image.
.header-wrap #header {
background-image: url(http://localhost/lps/wp-
content/uploads/2017/08/LiquidS_FLD_cover0817-45-1-1.png) ;
background-color: #fff;
background-repeat: no-repeat;
background-size: cover; /*this does not produce the outcome required*/
background-position: 0 100px;
-webkit-background-size: 100% 100%; /* Safari */
-khtml-background-size: 100% 100%; /* Konqueror */
-moz-background-size: 100% 100%; /* Firefox */
}
preferred layout
The image as it currently stands using code insert
Hi you need media queries to make responsive you image background may be you have to generate different size...
.header-wrap #header {
min-width:100%;
min-height:100%;
height:100%;
width:100%;
position:fixed;
top:0px;
background-image: url(http://localhost/lps/wp-content/uploads/2017/08/LiquidS_FLD_cover0817-45-1-1.png) ;
background-color: #fff;
background-repeat: no-repeat;
background-size: cover; /*this does not produce the outcome required*/
background-position: 0 100px;
-webkit-background-size: 100% 100%; /* Safari */
-khtml-background-size: 100% 100%; /* Konqueror */
-moz-background-size: 100% 100%; /* Firefox */
#media all and (max-width: 1080px) {
.header-wrap #header{ left:-600px;}
}
#media all and (max-width: 980px) {
.header-wrap #header{ left:-300px;}
}
#media all and (max-width: 800px) {
.header-wrap #header{ left:-300px;}
}
#media all and (max-width: 768px) {
.header-wrap #header{ left:-300px;}
}
#media all and (max-width: 750px) {
.header-wrap #header{ left:-380px;}
}
#media all and (max-width: 640px) {
.header-wrap #header{ left:-280px;}
}
#media all and (max-width: 360px) {
.header-wrap #header{ left:-180px;}
}
#media all and (max-width: 320px) {
.header-wrap #header{ left:-160px;}
}
Now you need to adapt media queries position here for exemple but you have to adapt to the different device here a lot of them...
How do I make my background-image show up without using min-height: 200px;? If I remove this line the background-image will not appear. I do not want to use min-height: 200px, as I am trying to make my site responsive the min-height thing will affect the different devices used, I wish to set the height to auto but it's not working.
header
{
background-image:
url(page_home/section_header.jpg),
url(page_home/section_header_bg.jpg);
background-repeat: no-repeat, repeat-x;
background-position: center, left;
min-height:200px;
}
As far as I know - you must set height or min-height so the element will be shown, but if you want a responsive site you can use different heights for different resolutions:
header
{
background-image:
url(page_home/section_header.jpg),
url(page_home/section_header_bg.jpg);
background-repeat: no-repeat, repeat-x;
background-position: center, left;
height:200px;
}
/* #### Mobile Phones Portrait #### */
#media screen and (max-device-width: 480px) and (orientation: portrait){
header
{
height:400px;
}
}
/* #### Mobile Phones Landscape #### */
#media screen and (max-device-width: 640px) and (orientation: landscape){
header
{
height:250px;
}
}
/* #### Mobile Phones Portrait or Landscape #### */
#media screen and (max-device-width: 640px){
header
{
height:100px;
}
}
More about max-device-width:
http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml
Also you may want to read about bootstrap - a JS framework for developing responsive sites for web and mobile: http://getbootstrap.com/
CSS3 has a property background-size.
header {
background: url(page_home/section_header.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
You still have to give it a height or min-height, I don't think there is an alternative
I've been working with a temp page at http://www.flywavez.com but I can't get the image to resize and be the same in all screen resolutions. On the iPhone it cuts the girl off before the waist, and it fits perfectly when viewed on my 19" laptop screen with the res at 1366 x 768, and even when I fed the video to my 55" TV via VGA from my laptop. However when I view at larger monitors with greater resolution, there is a big space and obvious view where the image size ends. I thought I had resizing CSS with
/* Tablet Landscape */
#media screen and (max-width: 1060px) {
#wrapper { width:67%; }
}
/* Tabled Portrait */
#media screen and (max-width: 768px) {
#wrapper { width:100%; }
}
/* Tabled Portrait */
#media screen and (max-width: 768px) {
#wrapper { width:100%; }
}
/* iphone */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
img { max-width: 100%; }
}
/* ipad */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
img { max-width: 100%; }
}
I want this image to display on all resolutions as it does when seen on the 1366 x 768.
Thanks for any help.
I think it is fundamentally impossible to achieve what you are trying to do without losing image ratio, which is probably undesirable. Have you considered using the 'background-size' property? The css below achieves a pretty good look:
body {
background: url('images/example.jpg') no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
You can see it here: http://jsfiddle.net/DTN54/
cover This keyword specifies that the background image should be scaled to be as small as possible while ensuring both its dimensions are greater than or equal to the corresponding dimensions of the background positioning area.
contain This keyword specifies that the background image should be scaled to be as large as possible while ensuring both its dimensions are less than or equal to the corresponding dimensions of the background positioning area. So try using contain instead of cover
100% This will scale 100% to both of height and width without any cropping.
body {
background: url('images/example.jpg') no-repeat fixed;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
}
Basically, this is all you need:
body {
background: url(http://www.bhmpics.com/thumbs/dambo_the_bottle_funny_situation-t3.jpg) no-repeat center;
}