The image that I use for my background (which is fixed) displays at 100% in Web format, but when I emulate it on Ipad (1024x768), the image stops adapting to the width of the screen and it just fills about 70% of the screen height.
This is the CSS that I've used for the website format:
.body{
background-image: url("/img/bg.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% auto;
height: 5700px;
width: 100%;
}
This is the CSS that I've used for the Ipad style:
#media screen and (max-width: 1024px) {
.body{
background-image: url("/img/bg.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% auto;
height: 5700px;
min-width: 1024px;
}
}
I've tried min-width: 1024px; beacause I found a similar question with that suggestion, but it hasn't worked.
As stated here viewport units caniuse , using viewport units can ( and will ) cause problems in iOS because
iOS 7 Safari recalculates widths set in vh as vw, and heights set in vw as vh, when orientation changes.
iOS 7 Safari sets viewport unit values to 0 if the page has been left and is returned to after 60 seconds.
vh on iOS is reported to include the height of the bottom toolbar in the height calculation, and the width of the sidebar (bookmarks) in the vw width calculation.
So i suggest you use media queries and target different iOS resolution both for portrait and landscape. I know, it's a meticulous task but if you have a serious project for a serious customer , you have to deliver serious product
See here > iosres
For example
/* iPad with portrait orientation.*/
#media all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait){
.body{
height: 1024px;
}
}
/*iPad with landscape orientation.*/
#media all and (device-width: 768px) and (device-height: 1024px) and (orientation:landscape){
.body{
height: 768px;
}
}
/*iPhone 5 with aspect ratio*/
#media screen and (device-aspect-ratio: 40/71) {
.body {
height: 500px;
}
}
or you could use jQuery or javascript , for example
$(".body").height($(window).height())
this will equal body height to window height
Try using width: 100vw. vw means viewport width, so this should make the background take up the full width of the viewport.
Thanks to #Traver I've found the answer:
.body{
background-image: url("/img/bg.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 200vh;
height: 5700px;
width: 100%;
}
I just had to change the background-size units to vh and remove auto (but I've tested with it too and it's worked). Giving it a number of 200vh is enough to scale it full width and height.
EDIT: Mihai T's answer is the best one. Check it.
Related
Okay, so I was styling a blurred header for my company and one of our QA ran into a strange issue. Basically illustrated below.
HTML:
<!-- HTML FILE -->
<div class="bg-item"></div>
CSS:
/* Stylesheet */
.bg-item {
width: 200px;
height: 200px;
display: block;
filter: blur(40px);
background: url('../img/bg.jpg') 0 0 / cover no-repeat;
}
It works on all devices and browsers, except when I set Safari to be in 3x iPhone 6 Plus size (hehe) - then the css style shows that it is invalid...
Verified it on an actual iPhone 6 Plus as well and this holds true? Is it an Apple bug or am I doing something wrong?
Actually it IS a bug on Apple's end, at least it would appear that way considering they didn't openly declare they've dropped support for CSS Filters.
You can use their new backdrop filter to work around this though pretty easily, I've demo'd it below.
HTML:
<!-- HTML FILE -->
<div class="img-wrap">
<div class="bg-overlay"></div>
<div class="bg-item"></div>
</div>
CSS:
/* Stylesheet */
.img-wrap {
width: 200px;
height: 200px;
display: block;
}
.bg-overlay {
width: 100%;
height: 100%;
}
.bg-img {
width: 100%;
height: 100%;
filter: blur(60px);
background: url('../img/bg.jpg') 0 0 / cover no-repeat;
}
//Only show on 3x density devices
#media only screen and (-webkit-min-device-pixel-ratio: 3) {
.ios.bg-overlay {
-webkit-backdrop-filter: blur(60px); //Blurs bg behind it
}
}
In a nutshell, just set up a media query to only use the backdrop on 3x ratio devices on webkit - and as much as I hate to say it android chrome will NOT know what to do with this so you will want to make sure this only gets applied to SAFARI, IOS devices - and it should take care of it.
Hope that helps!
When using #media print highcharts seems to ignore with width and height in the screen section and instead use the values from the display section.
This is preventing me from printing my entire web page with the highcharts on it since the charts are not the right size when printed.
See jsfiddle example
#media screen
{
.cont
{
width: 50%;
height: 100%;
}
}
#media print
{
.no-Print{
display: none;
}
.cont
{
width: 5%;
height: 5%;
}
}
It doesn't ignore the styles. It just defines width in pixels for elements inside container. To see this, you can add set container's overflow to hidden:
.cont {
width: 5%;
height: 5%;
overflow: hidden;
border: 1px solid red;
}
(see: http://jsfiddle.net/6WxgG/15/embedded/result/)
AFAIK it's not possible to reasonably resize the chart using only CSS.
#media query is not working in case of iPhone 5 and iPad 4 OS. I have used following CSS for styling each OS and device for different screen.
I explicitly checked that my iPad and iPhone width and height and based on that only i have kept the media queries. This works fine on ANDROID OS.
/*#media print {*/
/* iPhone 5 (Portrait) */
#media screen and (max-device-height: 568px) and (orientation: portrait) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 290px;
height: 473px;
}
}
/* iPad 4 (Portrait) */
#media screen and (max-device-height: 1024px) and (orientation: portrait) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 735px;
height: 929px;
}
}
/* iPad 4 (Landscape) */
#media screen and (max-device-width: 1024px) and (orientation: landscape) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 990px;
height: 673px;
}
}
/* Samsung 10.1 inch (Portrait) */
#media screen and (max-device-height: 1280px) and (orientation: portrait) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 790px;
height: 1140px;
}
}
/* Samsung 10.1 inch (Landscape) */
#media screen and (max-device-width: 1280px) and (orientation: landscape) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 1230px;
height: 680px;
}
}
/* Samsung 7.0 inch (Portrait) */
#media screen and (max-device-height: 1024px) and (orientation: portrait) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 570px;
height: 875px;
}
}
/* Samsung 7.0 inch (Landscape) */
#media screen and (max-device-width: 1024px) and (orientation: landscape) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 990px;
height: 455px;
}
}
#media all and (orientation: landscape) {
html, body {
height: auto;
}
}
Each time i tested with various changes in above code, I am getting the LAST CSS being referred for applying the style.
I found one link, (which i have not yet tried but going to try soon as mac is available) but have question about that too (iphone/ipad media query issues). Can anyone explain the reason behind that Is pixel ratio matters in this case??
Excerpted from https://mislav.net/2010/04/targeted-css/
You should be aware that orientation media query, although supported on the iPad, doesn’t work on the iPhone (tested with v3.1.3). Fortunately, size queries like width and device-width work, so layout-switching is possible without JavaScript with some combination of those.
The reason is because the new Apple devices have a higher pixel ratio density. You should put this meta tag in the head of your document and your media queries will work everywhere:
<meta name="viewport" content="width=device-width">
By the way, the higher pixel ratio for the new apple products is called "retina display."
If you do have access the iPhone, ipad, etc... try viewing this website:
http://mattstow.com/viewport-size.html
on those devices to see the viewport size of the device. Then, add the meta tag, and you will see that the viewport size changes.
I'm trying to set up a manualy splash-image across devices. I'm doing so by checking for orientation (touch devices) or screen width vs. screen height (none touch) and set a url accordingly.
Then I add this CSS rule via Javascript:
document.styleSheets[3].insertRule('.initHandler:before {
background: url('+x+') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}', 0)
With x being the image to be loaded depending on orientation and screen size.
My problem is this works fine in landscape mode, but on my iPad in portrait mode, the correct image is loaded (differ depending on portrait/landscape), BUT it is not expanded to fullscreen size.
Question:
Can I not use CSS background-size on iOS in portrait-mode?
Thanks for help!
EDIT:
Just tried on my Android Smartphone. Works fine there. Makes no sense, why it doesn't work on iPad.
Ok. Here is how it's working (Thanks to #iMeMyself):
body {
background: url(...) no-repeat center center fixed;
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
So first set it to 100%, then to cover. This way all browser that cannot cover get the 100% value, while the ones that can get the 100% overwritten by cover.
While checking orientation please take note of these points from apple document -
Provide Launch Images :
iPhone-only applications may only have one launch image. It should be in PNG format and measure 320 x 480 pixels. Name your launch image
file Default.png.
iPad-only applications: Create a launch image for each supported orientation in the PNG format. Each launch image must be 1024 x 748
pixels (for landscape) or 768 x 1004 pixels (for portrait).
Universal applications: Include launch images for both iPhone and iPad.
Update Your Info.plist Settings Specify values for the UISupportedInterfaceOrientations and UIInterfaceOrientation
and
Not all browsers recognize the cover keyword for background-size, and as a result, simply ignore it.
So we can overcome that limitation by setting the background-size to 100% width or height, depending on the orientation. We can target the current orientation (as well as the iOS device, using device-width). With these two points I think you can use CSS background-size:cover on iOS in portrait-mode
Here are some other resources I also came across while looking for a solution: Flexible scalable background images, full scalable background images, perfect scalable background images, and this discussion.
According to Designing Websites for iPhone X iOS 11 introduces a new extension for the existing viewport meta tag called viewport-fit, which provides control over the insetting behavior. The default setting is auto, which will not cover the entire screen.
In order to disable the default inset behavior and cause the page to lay out to the full size of the screen, you can set viewport-fit to cover as shown here:
<meta name='viewport' content='initial-scale=1, viewport-fit=cover'>
Without this setting existing techniques used for splash screens and full-size hero images may not display as expected on the iPhone X or other conformant iOS devices.
Code here
It fixing background images for ipad
Just enter sizes according to your image dimentions
/* Page background-image landscape for iPad 3 */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2) {
.introduction-section {
-webkit-background-size: 2024px 768px !important;
background-size: 2024px 768px !important;
background: url('background-image.jpg') no-repeat center top #000 !important;
}
}
/* Page background-image portrait for iPad 3 */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 2) {
.introduction-section {
-webkit-background-size: 2024px 768px !important;
background-size: 2024px 768px !important;
background: url('background-image.jpg') no-repeat center top #000 !important;
}
}
/* Page background-image landscape for iPad 1/2 */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 1) {
.introduction-section {
background: url('background-image.jpg') no-repeat center top #000 !important;
-webkit-background-size: 2024px 768px !important;
background-size: 2024px 768px !important;
}
}
/* Page background-image portrait for iPad 1/2 */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 1) {
.introduction-section {
background: url('background-image.jpg') no-repeat center top #000 !important;
-webkit-background-size: 5024px 2024px !important;
background-size: 5024px 2024px !important;
}
}
As far as I'm aware, this method works on all IOS devices. Depending on your other page elements (header etc) you may need to adjust z-index for the &:before psuedo-element.
html {
height:100% !important;
}
body {
height:100%;
min-height:100%;
overflow-x:hidden;
overflow-y:auto;
// use your own class here //
&.body-class {
// #screen-xs-max is a Bootstrap3 variable name //
#media screen and (max-width:#screen-xs-max) {
min-height:100vh;
position:relative;
&:before {
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
display:block;
content:"";
z-index:-1;
background-image:url(background-image.jpg);
background-position:center;
background-size:cover;
// Add this unless you compile your LESS using a preprocessor which adds vendor prefixes //
-webkit-background-size:cover;
}
}
}
}
I am trying to add a single custom icon to jqm and I'm doing the following:
<style>
.ui-icon-myicon {
background-image: url('images/myicon.png') !important;
}
</style>
Then in the footer...
<li>
News
</li>
My problem is that nothing is showing up.
I'm I forgetting something here?
WARNING: If you're using jQuery 1.4+, then you need to define these somewhat differently (notice :after below)
.ui-icon-myicon:after {
background-image: url("images/myicon.png");
background-size: 18px 18px;
}
#media only screen and (-webkit-min-device-pixel-ratio: 2) {
.ui-icon-myicon:after {
background-image: url("images/myicon#2x.png");
background-size: 36px 36px;
}
...more HD icon rules go here...
}
Remove your class tag and use the identifiers built into JQM.
News
If you're wanting the icon to appear on a high pixel density device (i.e. an Apple Retina display) you need to include a second image twice the size. So in your CSS:
.ui-icon-myicon {
background-image: url("images/myicon.png");
}
#media only screen and (-webkit-min-device-pixel-ratio: 2) {
.ui-icon-myicon {
/*this image should be sized at 36 x 36 */
background-image: url("images/myicon#2x.png");
background-size: 18px 18px;
}
...more HD icon rules go here...
}
I have faced the same issue, I have checked the inspect element and found that URL of my background custom icon path was wrong.
I have my custom icon in images folder so in CSS I have given
.ui-icon-myicon:after{
background-image:url("images/facebook.png");
/* Make your icon fit */
background-size:18px 18px;
}
The URL pointed previously to:Myproject/css/images/facebbok.png
Then I changed my CSS as:
.ui-icon-myicon:after{
background-image:url("../images/facebook.png");
/* Make your icon fit */
background-size:18px 18px;
}
After doing that I am able to see image