CSS min-height is fighting background-position - background-position

For the problematic behavior, try resizing the window of this web app. Thought the header and boxes stop being resized after a minimum dimension, the background image continues to position itself at the center of the page, which looks really stupid.
Here's the relevant code for the background image:
body{
text-align: center;
min-width:1000px;
min-height: 600px;
background: url(../images/road_newtry_tile4.jpg) 50% 50% fixed;
}
Even though background-position isn't nixing the min-width and height (ie, the window will stop resizing after predetermined dimensions, it continues to center the background image.
Why is it doing this? How can I prevent the image from re-centering after certain a certain point?

it is doing it because the 50% is relative to the size of the browser window. A fix would be to instead have the background image on a wrapper div, which has the min-width and min-height set.

Related

how can i fit four background images into one div

Am trying to fit four different background image in one grid div but is leaving a big gap in between the four corners and cant cover the whole area
grid-item3{
background-image: url(./images/bg-section-top-desktop-1.svg),url(./images/bg-section-top-desktop-2.svg),url(./images/bg-section-bottom-desktop-1.svg),url(./images/bg-section-bottom-desktop-2.svg);
background-position:left top,right top, left bottom, right bottom;
background-size: contain,contain,contain,contain;
background-repeat: no-repeat, no-repeat,no-repeat,no-repeat;
}

Ionic 3: Gradient background

It is easy to change the background color of an Ionic App by setting $background-color in variables.scss, but it wont work with gradients or images. I was surprised that I could not find any official documentation on this, nor a lot of useful questions and answers.
If you set $background-color to a non-color you will currently get a Sass error from one of the many Ionic components that calculate their colors based on the background color.
So here is what I ended up doing, first in src/theme/variables.scss:
$app-background: linear-gradient(to bottom, color($colors, light) 0%, color($colors, dark) 100%);
$background-color: transparent;
$toolbar-background: transparent;
The normal background and toolbar must be transparent to show the gradient underneath. We apply the gradient in src/app/app.scss:
ion-content {
background: $app-background;
}
You may think that ion-content only takes up the space between your header/navbar and footer/tabs, but is actually styled by Ionic to fill the entire screen. So you got your gradient from top to bottom. Success.

How do you make a css tiled / repeated background stay sharp on a retina screen?

On the web page, I'm scaling all of my images by 50% with CSS to make them look sharp on retina screens but that doesn't work for tiled images, there seems to be no way to scale a tile background image so that it will be sharp and not doubled sized on the retina screens. Sorry if this question is confusing.
Setting background-size: 150px 150px; for a 300x300 background image seems to do the trick. Note that background-size: 50%; will not do what you might expect, as it sets the width and height to 50% of the parent container.
I haven't worked with Retina displays, but I would imagine it would be better to create an alternate background image with higher resolution for them.

Single/sub pixel misalignment of divs on ipad and iphone safari

I've got the following situation, and I need some help...
Two divs, same size, same location, one on top of the other
Everything works as expected on desktop browsers
On the iphone/ipad a faint line appears around the border of the divs
This faint line is not always on all four borders. It changes depending on the location of the divs. It looks to be happening as a result of the two divs not lining up properly, but according to their style settings, they are of identical size and location.
You can see the results here: http://www.thoughtartistry.com
Any ideas?
I had a similar problem in a recent project where I had background image masks with different background color to colorize the resulting icons in mobile Safari. The problem was that when the page was scaled down by Safari, there was a line of the background color showing around the image, even though it should have been masked. I never found a way to prevent that leaking of the background color when the page is scaled down. It's clearly an error in mobile Safari's algorithms that recalculate the background and mask. I did find a workaround: I put an outline on the element with the same color as the background of the element's parent. The outline is outside the element and therefore masks the part bleeding out. If your element's parent has a pattern background that's drastic, this won't work that well, but if it's a solid color, it'll do just fine.
A negative margin is the only way I found to prevent this.
For example, if you have a faint horizontal gap between 2 divs, adding a top margin of -1px to the second div will make it overlap slightly and the gap will not reappear as the page is scaled.
Some situations (like image sprites or repeat patterns) may need a little more tweaking, but the general idea is the same. For a sprite, make sure there is no big color change within 1 pixel of the cropping border. The bleed is never more than 1 pixel, so a 1 pixel adjustment is enough.
The problem is not only with divs matching together, but also with image sprites.
I followed the advise in this thread of setting initial viewport scale to 1.0. The sub-pixel bug was gone, but then I tested my website on other devices, like Android, and realized a full size page is annoying, since users have to re-scale every time it's loaded. So I preferred to disable the scale and wait until Apple fixes it. Then one day I was thinking how to solve the problem with the margins of the page, and I came to this simple solution in CSS:
html {
min-width: 1024px;
}
Devices capable of this resolution, such as iPad in horizontal position, will set the document scale to 1.0. In my case this is enough solution, since I can show the page is working just right, and the sub-pixel bug is in Safari/iOS, which will be solved in the future hopefully.
It totally depends on one's situation, but in our case we use negative margins as proposed by this thread or a box shadow since outline only applies to all borders and ie. outline-bottom does not exist.
/*
* Prevent faint lines between elements.
* #link http://stackoverflow.com/questions/5832869
*/
box-shadow: 0 1px 0 red;
I also solved the iOS sub pixel gap issue (on a full screen site) by using overflow-x: hidden; to stop side ways scrolling & viewpoint scale to stop pitch zooming. I also had holder divs set at width: 101%; and all the elements/image divs inside set to float: left;. This means the sub pixel gaps are all on the left hand site but pushed out of view by the holder div set at 101% width.
Remove "clear:both" (if there is) from div below the gap.
I also had to solve this. If you are using Div's to define sections only then.
//background.css
.background-color {
background-color: blue;
}
.background-color div {
background-color: inherit;
}
I'd try playing with meta/viewport options, specifically setting initial scale to 1.0 and disabling user zooming.
https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html

Round image as background for input type="submit"

In the page found in below link(bg-button.html), I have put round image as a background using styles. But I find a gray background outside the image area. How can I make the background transparent, Please let me know?
Round image as background
You can add the following style to the button:
background-color: transparent;
Alternatively, use #fff.
You must edit the image in a paint program (like GIMP), add a transparency layer, remove the part you don't like with the eraser and save it as GIF or PNG.
Note that IE 6 doesn't handle PNG transparency without some tricks.
Going off what the above poster said, you can generally get around this without thinking about it by just using shorthand, ala:
div#example { background: transparent url("imgurl.png") no-repeat top left; }