Change background image on mobile - html

I want the background image on my slider to change on mobile, when opened on mobile the part of the background that displays makes the slider text unreadable.
#media (#max-width: 450px){
.main_slider_item_bg {
background-image:url("/images/web_phone.png")
}
<div class="owl-item main_slider_item">
<div class="main_slider_item_bg " style="background-image:url(images/web.png)"></div>
I've tried this but it's not working.

Your solution is here:
#media (max-width: 450px){
.main_slider_item_bg {
background-image:url("/images/web_phone.png")
}
}
Inside parentheses remenber put the device's feature with the syntax you use when you declare a CSS property inside a rule.

Related

My media query is not taking effect

I'm having some trouble using a media query. It's quite a basic thing but for some reason is not working.
Basically, I have a border around a div tag:
<div class="container games mobile">
<div class="row">
<div class="col-lg-8 div border">
<!-- This div tags are closed at the end of the file -->
I'm using bootstrap and don't honestly know if that can be part of the problem but what I wanted to do was to remove that border whenever the user was in a mobile, and to do so, I added the following lines in my css file:
#media screen and (max-width: 600px) {
.border {
border: none;
}
}
Border on computer
Border on mobile even though I used the querie
(added a grey square on both prints because the content doesn't really need to be in here but a live preview can be found here)
Could the issue be parent>child related?
Thanks in advance!
It's not working because it's being overwritten by bootstrap code. Try this:
#media (max-width: 600px) {
.border {
border: none !important;
}
}
Use css specificity here instead using !important. why not !important?
#media screen and (max-width: 600px){
.games.mobile .border {
border: none;
}
}

How to set bootstrap menu a item visible on mobile

I have a website that my client needs to set the cart menu item visible beside the menu button when is on mobile device but I don't know what is the better way to do this. Does anyone of you have any tips ? I appreciate in advance. Bellow is an image of the item highlighted in yellow that I want to set visible :
Have a closer look at Bootstrap's Responsive Utilities documentation. You can use the hidden- or visible- classes.
To hide on desktops add the following classes to your element:
hidden-md hidden-lg
To hide on mobile use:
hidden-xs hidden-sm
Here's a jsFiddle demo.
By adding following class you can hide it in big screen and show in mobile.
col-visible-xs col-visible-sm col-hidden-md col-hidden-lg
For hidding in big screen use following class
col-hidden-md col-hidden-lg
Showing in small screen use following class
col-visible-xs col-visible-sm
You could search something for this in jquery and showing and hiding blocks. a very simple way would be to use media queries in CSS. It isn't the best solution but it is the easiest one.
#media screen and (min-width: 768px) {
.shopping-cart {
display: none;
}
}
#media screen and (max-width: 768px) {
.shopping-cart {
display: block
}
}

Using #media to display an image

Using the #media tag, how do I display a new image, for example I have a logo I want to use for my main site and a mobile logo for my mobile site, how to I display the smaller logo only on the mobile site using #media?
I've tied using "display:url('xxxx') but that hasn't seemed to work.
You'll have to put two logos on your HTML, like this:
<img src="" class="desktop-logo">
<img src="" class="mobile-logo">
Then, you'll have to hide the mobile-logo by default:
.mobile-logo {
display: none;
}
Then, on your media query, you'll have to hide the desktop-logo and show the mobile-logo:
#media screen and (max-width: 480px) {
.desktop-logo {
display: none;
}
.mobile-logo {
display: block;
}
}
What you'll want to do is create an element and set a background on it. You'll use #media control what the background image is based on the size of the window.
#media only screen and (min-width: 768px) {
.logo {
background: url('image.jpg');
}
}
#media only screen and (max-width: 767px) {
.logo {
background: url('imagesmall.jpg');
}
}
And this is what your element would look like.
<div class="logo"></div>
Create a tag with a class then use mediascreen to apply new styles to said class
create a div tag
css/
#media screen .... etc {
.image {background-image: url('wwww....');
}
So, when the exact pixels are reached at the screen it will apply a backround image to that image class I created above.

media queries with bootstrap not working

I wanted to have large pictures be hidden for mobile devices. Looking at this site I put the following styles in my css:
//medium+ screen sizes
#media (min-width:992px) {
.desktop {
display:block !important;
}
}
//small screen sizes
#media (max-width:991px) {
.mobile {
display:block !important;
}
.desktop {
display:none !important;
}
}
Then I apply the class in my html like this:
<img class="desktop" src="img/test/test.jpg"
alt="jhkjhjk" height="600" width="900">
But when I shrink my browser window the image remains there. Have I missed something?
Since you are using Boostrap, you can do it even easier.
Append a class of
visible-md
to your image.
md is for >992 px.
Check out the easy classes you can use
http://getbootstrap.com/css/#responsive-utilities
EDIT: probably wanna do visible-md visible-lg if you're gonna do visibles. The chart explains all the combinations.

How to write different HTML for different screen sizes

I understood how I change CSS via media queries (such as media="screen and (max-width:640px)")
but let's say I want to write (just for example)
<div>
[if screen resolution is lower then 960 px]
<div>
some new text only for lower resolution
</div>
[end of condition]
</div>
What is the condition I need to write to get it right?
As far as i have experienced, you cannot do media queries inside HTML pages. You need to do it from within your CSS.
But if you want to show some special text only when it is below a certain resolution, why not only make it visible when the resolution is lower than 960px?
Creating responsive designs is very different from a regular design, because you have to think a lot more (which is haaard)
you can check it via using javascript screen object :
screen.width
or you can do this with css
<link rel="stylesheet" media="screen and (min-device-width: 800px)" href="800.css" />
http://css-tricks.com/6206-resolution-specific-stylesheets/
http://www.javascriptkit.com/howto/newtech3.shtml
I am actually going through the same situation and found that if you want to do this you could really add all the text in the HTML page, and then hide it on screen widths that you don't want it to show. For example:
<div>
[text that will be shown for screens less or equal to 960px in width]
<div class="smallScreen">
some new text only for lower resolution
</div>
[end of condition for small screens]
[text that will be shown for other screens that are greater in width]
<div class="largeScreen">
some new text only for higher resolution
</div>
</div>
And then you could add CSS:
/* On smaller resolutions, hide the text for Large screens */
#media only screen and (max-width: 960px) {
.largeScreen {display: none;}
}
/* On larger resolutions, hide the text for Small screens */
#media only screen and (min-width: 960px) {
.smallScreen {display: none;}
}
I hope this works out fine :)
You need to assign an id (or a class or any other way of finding your element from CSS) to the <div> and then you can set a media query definition like this:
<div id="mydiv">...</div>
<style type="text/css">
#media screen and (min-width: 961px) {
div#mydiv { display: none }
}
</style>
Or for better readability: Make it hidden on default and visible if max-width: 960px.
I could be wrong, but I think css selection by resolution would need a little help from javascript.
Here is a quick example of what that js could look like, embedded in jquery:
$(document).ready(function() {
if ((screen.width>=1024) && (screen.height>=768)) {
alert('Screen size: 1024x768 or larger');
$("link[rel=stylesheet]:not(:first)").attr({href : "detect1024.css"});
}
else {
alert('Screen size: less than 1024x768, 800x600 maybe?');
$("link[rel=stylesheet]:not(:first)").attr({href : "detect800.css"});
}
});
Hope that helps.
You can add jQuery function to change style dynamically as per scree resolution.
if(screen.width==1600)
{
jQuery('#hb-gotop').removeAttr("margin-left", "-0.9");
jQuery('#hb-gotop').attr('style', 'margin-left: -0.7%');
}
else if(screen.width==1280)
{
jQuery('#hb-gotop').removeAttr("margin-left", "-0.9");
jQuery('#hb-gotop').attr('style', 'margin-left: -0.9%');
}
else if(screen.width==1024)
{
jQuery('#hb-gotop').removeAttr("margin-left","-0.9");
jQuery('#hb-gotop').attr('style', 'margin-left: -1.1%');
}
else if(screen.width==800)
{
jQuery('#hb-gotop').removeAttr("margin-left","-0.9");
jQuery('#hb-gotop').attr('style', 'margin-left: -1.3%');
}
Answere was helpful from:
if screen resolution is less than x append css
You can do this entirely with CSS 3 using the #media command.
**#media (max-width:960px) { css... } //nothing with screen size bigger than 960px
#media (min-width:960px) { css... } //nothing with screen size smaller than 960px**
Jason Whitted makes a good point, this is CSS 3 only, so it won't work with older browsers (it should work with all modern browsers though).
You can as well do screen or device edit
#media screen { .nomobile { display: block; } } //desktops/laptops
#media handheld { .nomobile { display: none; } } //mobile devices
Or you could assume mobile devices will have a smaller width, and go on that.