Display on mobile hide on Desktop Button/link - html

I am trying to create a click-to-call link in my webpage i have the following
<a class="mobile-only" href="tel:+534306464456"><p class="">Click Here to call us</p></a>
I want it to only display on mobile devices phones specifically
in my css i tried
#media (max-width: 991px) {
.mobile-only {
display:block !important;
}
}
.mobile-only{
display:none !important;
}
but it does not work is there a way to accomplish this?

.mobile-only {
display: none;
}
#media only screen and (max-width: 767px){
.mobile-only {
display: block;
}
}

This should work.
.mobile-only {
display: block;
}
#media screen and (min-width: 768px){
.mobile-only {
display: none;
}
}

Only move .mobile-only class to above to your media query, remenber that is cascading style sheet, this mean that media query will be place at the end of the file, or instead you can place .mobile-only inside of a media query that only affect desktop resolutions. By the way avoid using !important statement in your css.
.mobile-only{
display: none;
}
#media only screen and (max-width: 991px) {
.mobile-only {
display: block;
}
}
Other approach will be:
#media only screen and (max-width: 991px) {
.mobile-only {
display:block;
}
}
#media only screen and (min-width: 991px) {
.mobile-only{
display: none;
}
}

Related

Not displaying input tag on certain devices

I'm trying to not display different input tags for different devices.
I have three input tags <input class="desktop"/> <input class='tablet'><input class= 'mobile'>
I'm not displaying desktop and mobile input tags by adding the css like this:
.desktop {
#media(max-width: 767px){
display: none
}}
.mobile {
#media (min-width: 768px) {
display: none;
}}
I'm having difficulty restricting it for tablet though. My tablet dimensions are between 768px and 1024 px
I've tried doing this but it doesn't work:
#media (max-width:768px) and (min-width:1024px) {
display: none;
}
Any ideas on how I can control the input tag to only show between these dimensions?
It's just a syntax error. You need to put the class selector inside the media query like this:
#media (max-width: 767px) {
.desktop {
display: none;
}
}
See this example on w3schools
edited The media query just has the max-width and min-width the wrong way round. See below
/* apply at widths below 768px */
#media (max-width:768px) {
body {
background-color: lightskyblue;
}
.tablet, .desktop {
display: none;
}
}
/* apply from widths between 768px and 1024px */
#media (min-width:768px) and (max-width:1024px) {
body {
background-color: goldenrod;
}
.mobile, .desktop {
display: none;
}
}
/* apply from widths above 1024px */
#media (min-width:1024px) {
body {
background-color: lightseagreen;
}
.mobile, .tablet {
display: none;
}
}
<input class='mobile' placeholder="mobile">
<input class='tablet' placeholder="tablet">
<input class='desktop' placeholder="desktop">

How can I remove an element of my website using media queries

I want to be able to remove this:
<div id="mail1">
<li>
<i class="glyphicon glyphicon-envelope" aria-hidden="true"></i>
support#mywebsite.com.au
</li>
</div>
When a device is smaller than 600px.
I would suggest using a class instead of assigning the property to an id. This will help you use this class to multiple components which you want to hide on a screen having width less than 600px.
#media only screen and (max-width: 600px) {
.desktop-only {
display: none;
}
}
<div id="mail1" class="desktop-only"><li><i class="glyphicon glyphicon-envelope" aria-hidden="true"></i>support#mywebsite.com.au</li></div>
Use media query and then use display none.
#media only screen and (max-width: 600px) {
#mail1 {
display: none;
}
}
I see most answers on here using max-width: 600px but if you truly want to hide it under 600px, you should use 599px like this:
Desktop-First CSS
#media only screen and (max-width: 599px) {
#mail1 {
display: none;
}
}
If you want to use mobile-first CSS, you can code it like this instead:
Mobile-First CSS
#mail1 {
display: none;
}
#media only screen and (min-width: 600px) {
#mail1 {
display: block;
}
}
also can use this:
#media only screen and (max-width:600px){
#mail1 {
display: none;
}
}

How to hide custom-background on desktop (over 992px width)

Why is custom background showing? Here is the css i have added that should work.
#media (min-width: 992px) {
body.custom-background {
background-image: none !important;
display: none; }
}
Link to the website: http://goo.gl/RgG2Ct (scroll down and you will se this strip that is only suppose to be on the mobile version)
You can try with
#media screen and (min-width: 992px)
try this code:
#media (min-width: 992px)
{
body
{
background-image: none !important;
}
}
thanks.
You need to clean things up a bit... try it like this:
#media screen and (min-width: 480px) {
body.custom-background {
background-image: none !important;
display: none;
}}
It seems you have an extra set of () and one misplaced }

Media Queries work when I re size the window but don't work when on other devices

Ive been looking all over and I cant find any solution to this. My media queries don't work on mobile devices but they work when I re size my screen.
YES I do have:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
In the head of my document.
Here are what my media queries look like:
#media only screen and (max-width: 1100px) {
.r-menu {
display:inline;
}
.m-menu {
display:none;
}
}
#media only screen and (max-width: 900px) {
.res-full {
width: 100%;
}
}
Thanks.
Here is the whole code: http://scratchpad.io/marvelous-holiday-5460
Replace only screen with all
#media all and (max-width: 1100px) {
.r-menu {
display:inline;
}
.m-menu {
display:none;
}
}
#media all and (max-width: 900px) {
.res-full {
width: 100%;
}
}
screen is used for computer screens whereas all is used for all media type devices
Do you really need to use "only"?
I found that the only keyword was intended to prevent non-media-query supporting browsers to not load the stylesheet or use the styles. Why don't you try removing it?
Found the mistake Use min-width not max-width
/*If screen is less than 900px don't show full menu*/
#media(max-width: 900px) {
.r-menu {
display:inline;
}
.m-menu {
display:none;
}
}
/*If screen is greater than 900px then show full menu*/
#media(min-width: 901px) {
.res-full {
width: 100%;
}
}
Use this css
#media screen and (max-width: 1100px) { .r-menu {
display:inline;
}
.m-menu {
display:none;
}}
#media screen and (max-width: 900px) {
.res-full {
width: 100%;
}}
working all devices & screens

How to make an image link to a phone number only on mobile using CSS and HTML?

Instead of just having text for example
If I do
1-800-123-4567 then it will be broken on desktops.
If I do (800) 123-4567 then it will display as the number on desktop but should automatically become a link on Android and iPhone
But if I want to make an image like this:
Is there a solution, possibly with media query or any other way. That I can make this image display on desktop and mobile but on mobile function as a button? This is for email so only HTML/CSS options.
Based on the answers I have this and it didn't work either:
#media screen and (min-width: 0px) and (max-width: 400px) {
#my-image { display: block; } /* show it on small screens */
#my-link { display: none; } /* hide it on small screens */
}
#media screen and (min-width: 401px) and (max-width: 1024px) {
#my-image { display: none; } /* hide for all below 401px*/
#my-link { display: block; } /* show for all above 401px*/
}
Along with:
<div id="my-image">
Call Now!
</div>
<div id="my-link">
Call 1-800-328-4766
</div>
And it still is not working, both links are showing up.
Deleted my old answer, because it was poor. Please try this http://jsfiddle.net/qDUqS/
The telephone number looks the same both in small screen and in big screen, but it acts like a link, only on smaller screen.
Html:
<span class="phone"><img src="http://goo.gl/PdeeU" />1-800-123-4567<p>1-800-123-4567</p></span>
CSS:
.phone
{
background-color: #152C48;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;
padding: 4px;
}
a
{
display: inline-block;
text-decoration: none;
color: #ffffff;
padding: 0px;
}
img
{
vertical-align: middle;
width: 24px;
height: 24px;
padding: 0px;
}
p
{
display: none;
color: #ffffff;
padding: 0px;
}
#media only screen and (min-width: 480px) and (max-width: 1920px)
{
a
{
display: none;
}
p
{
display: inline-block;
}
}
Hey I don't know if this is what you are asking for but it might help.
Do let me know.
http://www.wpbeginner.com/wp-tutorials/how-to-add-clickable-phone-numbers-for-smartphones-in-wordpress/
Sorry if this is not what you were looking for.
NOTE: Updated my code and all works as it should be now. set the max-width to 9999px.
Working JSFIDDLE
Make a div and put the image inside that div:
<div id="my-image"></div>
The css would look like this:
#media screen and (min-width: 0px) and (max-width: 400px) {
#my-image { display: block; } /* show it on small screens */
}
#media screen and (min-width: 401px) and (max-width: 9999px) {
#my-image { display: none; } /* hide for all below 401px*/
}
for your button/link you can do the same but then otherwise:
<div id="my-link"></div>
The css would look like this:
#media screen and (min-width: 0px) and (max-width: 400px) {
#my-link { display: none; } /* hide it on small screens */
}
#media screen and (min-width: 401px) and (max-width: 9999px) {
#my-link { display: block; } /* show for all above 401px*/
}
Hope it helps.
The answer is very simple, just ad opacity "transparrency" to the desktop code.and copy the code to mobile while setting the opacity to 1.