Background centered for image < than the page and left when image > than the page - css

Is it possible in CSS to handle the position of a background image depending of the dimension of the browser page, or should I use javascript to handle that?
When the image is bigger than the page it should be aligned to the left
When the image is smaller than the page it should be aligned to the center

Media queries - they change CSS styles dependent on browser size.
#img {
width: 1000px;
margin: 0 auto;
}
#media
screen and (max-device-width: 1000px),
screen and (max-width: 1000px) {
#img {
float: left;
margin: 0;
}
}

Related

responsive image, maintain original size, resize after stretch window css

I have an image of 320px x 320px and max-width:620px for the container div
My problem is that I want it to appear at firs,with the original size, then if resize the window, then decrease the proportions of the image.
div.container {
max-width: 620px;
background: yellow
}
img {
text-align: center;
display: block;
margin: 0 auto;
width: 100%;
height: auto;
}
<div class="containe">
some text
<img class="img" src="http://via.placeholder.com/320x320/33ff99/555555?text" /></div>
I can not use max-width:320px in the image, because, the image generates dinamically and It usually have some other size values
How can I do it?
You could use #media queries, you can read more about them here.
If you resize your window let's say smaller than 768px. You could change your image size. The css below will make the image take the full width of the container while keeping its aspect ratio.
#media screen and (max-width: 768px) {
#img {
max-width:100%;
height:auto;
}
}

How to use #media to change width of iframe or div between specific screen sizes(min-width & max-width)

For my site on cruiseguru.co.th, the search box on the left overlaps with page content when screen size is between width 1200px and 765px so I was hoping to change width of the search box only on between two resolution with a css like the one below but of course it doesn't work so it would be great if anyone can advise me the right css.
#media screen (max-width:1200px) and (min-width:765px) {
#IFRAME_2 {
max-width: 360px;
};
You're missing and between screen and (max-width:1200px)
#IFRAME_2 {
width: 600px;
}
#media screen and (max-width:1200px) and (min-width:765px) {
#IFRAME_2 {
width: 360px;
}
}
<iframe id="IFRAME_2"></iframe>

Centering a span tag in Wordpress?

I've set up a media query that should center an image when the screen is smaller than 600px. When bigger then 600px, the image correctly displays to the right of the site title. Chrome inspector assures me that the queries are working, but I think there might be an overarching rule that's keeping my margin: auto from applying. The 'globes' image in question is at the top of:
http://livinginbetween.org/temp/
I'd love any suggestions. Thanks in advance for your time.
Add display: block; to your media query to center the image.
#media only screen and (max-width: 599px) and (min-width: 0px) {
.globes {
display: block;
width: 159px;
margin: 0 auto 0 auto;
}
}

Twitter Bootstrap Nav bar

http://www.ontargettdesign.com
Hi,
I am having problem with the navigation bar and the logo when the webpage is resized to ipad size:
[IMG]http://i60.tinypic.com/4r95qo.png[/IMG]
How can I code it to be a narrower height, I feel I have tried everything!
Any help would be very much appreciated.
Thanks in advance
Your Media Queries are clipping the image. This is because the div you have is smaller than the background image being used. If you remove the "width" & height" the logo will display properly. To view this. Make you browser smaller to see the clipping occur (Because of #media). Right click on the logo and "inspect element". On the right or bottom it will show you the css that is applied to this image. You can toggle the css to see how the code effects your image.
either add background-size:contain; to both of the follow or remove the width and height.
#media (max-width: 979px) and (min-width: 769px)
.navbar-brand {
height: 32px;
width: 132px;
}
&
#media (max-width: 768px)
.navbar-brand {
height: 32px;
width: 132px;
}
To change make the navbar height the same across all media widths you will still have to mess with the media widths. Your standard height is "height: 76px;".
The first CSS is for the smallest possible screen
#media (max-width: 768px)
.navbar {
height: 76px; /* add this */
}
This is the second smallest screen (for tablets). You will not to get rid of the clear:both that is sending the navigation to the second line
#media (max-width: 979px) and (min-width: 769px)
.navbar-collapse {
float: none;
clear: both; /* DELETE THIS */
height: 100px; /* You can change this to 76px if you want to be consistent */
}

Having max-width without causing vertical scrollbar to appear

I have these CSS rules for my header
margin: 0 auto;
max-width: 1250px;
Having those (in comparison to not having them) causes the vertical scroll bar to appear when the browser window is < 1250px.
What CSS should I have to let users with big screens see the header att 1250px width, and the others with smaller width see the responsive header at their respective browser window size - without having the vertical scrollbar to appear?
Something like this should work:
#header {
width: 100%;
}
#media screen and (max-width: 1250px) {
#header {
width: 1250px;
}
}

Resources