#media (max-width: 992px) {
.menu__list {
display: none;
}
.btn__menu {
display: block;
}
}
.btn__menu div {
height: 5px;
background-color: #000;
margin-bottom: 5px;
}
.btn__menu {
width: 40px;
display: none;
}
The code above writes me that I have an error in display: block;. I need the burger menu to pop up when the screen is less than 992px wide but I have nothing. Where did I go wrong?
Swap the order - your general rules will overwrite the media query rules the way it's now, since they follow * after* them. So just move the media queries to the end.
Related
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">
I'm working on making my website responsive, but I encountered a problem.
I'm trying to hide a section to make it only phone visible, but as I try to set my display:none for my section and to enable it in my media query, it is overwritten by my non-media query code.
The 2 sections that I want to hide from PC users are .phone-services and .avis-phone. The problem is that, as I said if I state them as display:none, they will overwrite my media query.
Here is a part of my #media CSS:
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
.services {
display:none !important;
}
.avis {
display:none !important;
}
.phone-services {
background:#02000A;
}
.avis-phone {
background:#02000A;
color:white;
}
}
Here is a part of the other CSS that overwrites it:
#import url('https://fonts.googleapis.com/css2?family=Shippori+Antique+B1&display=swap');
* {
margin:0; padding:0;
box-sizing: border-box;
text-decoration: none;
outline: none; border:none;
font-family: "Shippori Antique B1" , sans-serif;
transition: .2s linear;
}
html{scroll-behavior:smooth !important}
a:visited{
visibility:hidden;
}
.phone-services {
display:none; /*Overwrites my media query*/
}
.avis-phone {
display:none; /*Overwrites my media query*/
}
HTML:
<section class="phone-services">
Section need to be shown only for mobile
</section>
<section class="avis-phone">
Section need to be shown only for mobile
</section>
Thanks for your help!
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait)
min-device-width and max-device-width are only for actual devices. If you try to simulate that on a desktop, it won't work for you. You should use min-width and max-width instead.
Secondly, -webkit-min-device-pixel-ratio: 2 is to check device resolution, but we have various devices which we cannot simply cover with a particular resolution. I'd suggest removing it.
Another problem is from here
.phone-services {
background:#02000A;
}
.avis-phone {
background:#02000A;
color:white;
}
You set display: none, but you don't set display: block (or any other visible display values)
Another point I'd like to note down that the style priority is TOP to BOTTOM when they have the same selectors. Your display style in media-query is above display: none like below, that will cause display problem too
#media {
.phone-services {
display: block; /*NOT WORKING*/
}
}
.phone-services {
display:none;
}
Full possible change can be
#import url('https://fonts.googleapis.com/css2?family=Shippori+Antique+B1&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
text-decoration: none;
outline: none;
border: none;
font-family: "Shippori Antique B1", sans-serif;
transition: 0.2s linear;
}
html {
scroll-behavior: smooth !important;
}
a:visited {
visibility: hidden;
}
.phone-services {
display: none;
}
.avis-phone {
display: none;
}
#media only screen and (min-width: 320px) and (max-width: 480px) and (orientation: portrait) {
.services {
display: none !important;
}
.avis {
display: none !important;
}
.phone-services {
background: #02000A;
display: block;
}
.avis-phone {
background: #02000A;
color: white;
display: block;
}
}
<section class="phone-services">
Code in here
</section>
<section class="avis-phone">
Code in here
</section>
You always have to define display if you are hiding / showing them depending on #media, both in #media part and non-#media part.
Try adding it to the rules:
#media screen and ...
{
.phone-services {
background:#02000A;
display: block; // can be block, inline-block, flex...
}
.avis-phone {
background:#02000A;
color:white;
display: block; // can be block, inline-block, flex...
}
}
Note that if you have #media part loaded before the normal one, you have to make sure to load #media part after, so it does not get overridden, or you can use !important with the rule (not recommended).
I have a text block on my website:
Specialtyreagents
<h1>Specialtyreagents</h1>
Can I somehow add a - symbol to this block within CSS, so it should looks like this:
Specialty-reagents
I can use only CSS in my case!
Thank you for your help.
Use a pseudoelement with the word you want on mobile, and use font-size to hide or show it.
example
codepen
h1:after {
content: 'Specialty-reagents';
font-size: 0;
}
#media screen and (max-width: 500px) {
h1 {
font-size: 0;
}
h1:after {
font-size: 32px;
}
}
<h1>Specialtyreagents</h1>
With just CSS you can't include that - but if you need to use it in a specific case you can write again the text like this with a pseudo-element:
h1 {
font-size: 0;
}
h1:before {
content: "Specialty-reagents";
display: block;
font-size: 1.5rem;
}
<h2>Specialtyreagents</h2>
<h1>Specialtyreagents</h1>
On the long ride you can have two html elements, one for mobile and one for desktop:
<h1 class="desktop">Specialtyreagents</h1>
and
<h1 class="mobile" >Specialty-reagents</h1>
Then, you should have some css code for handling it:
.desktop {
display: block;
}
.mobile {
display: none;
}
#media (max-width: 720px) {
.desktop {
display: none;
}
.mobile {
display: block;
}
}
With media query:
#media only screen and (max-width: 500px) {
h1 > span:after {
content: "-";
}
}
<h1>Specialty<span></span>reagents</h1>
As others have said, you can use a pseudo element to achieve this.
The best way to go is to just add a new pseudo element when viewing on a small viewport (ie. a mobile phone). Here is some extra info on pseudo elements and how they can be used.
Example...
#media screen and (max-width: 768px) {
h1 {
font-size: 0px;
}
h1::after {
font-size: 30px;
display: block;
content: "Specialty-reagents";
}
}
<h1>Specialtyreagents</h1>
The only thing you may need to change if the max-width for the media query and the font size of the heading.
Try this code for the solution please:
#media only screen and (max-width: 500px) {
h1 > span:after {
content: "-";
}
}
I'm doing some different styling for different screen sizes, based on the bootstrap grid system sizes. For some reason some of the styling is working and some isn't. Here is the css:
#media only screen
and (max-width: 767px) {
div.bm {
display: none;
}
div.br {
height: 40%;
}
div.main-row {
height: 60%;
}
#main-text{
font-size: 3rem;
font-weight: 300;
}
}
#media only screen
and (max-width:991px)
and (min-width:767px) {
div.sm {
display: none;
}
div.main-row {
height: 100%;
}
#main-text{
font-size: 4.5rem;
font-weight: 300;
}
}
#media only screen
and (min-width:991px)
and (max-width:1999px) {
div.sm {
display: none;
}
div.main-row {
height: 100%;
}
#main-text {
font-size: 5.5rem;
font-weight: 300;
}
}
#media only screen
and (min-width: 1200px) {
div.sm {
display: none;
}
div.main-row {
height: 100%;
}
#main-text {
font-size: 6.5rem;
font-weight: 300;
}
}
It is mainly the display:none that are not taking effect, but it seems like the #main-text is getting resized correctly. I have a feeling there is a syntax error around the line:
#media only screen
and (min-width:991px)
and (max-width:1999px) {
Because I'm using the css preprocessor stylus, and it's causing this error around that line of code:
ParseError: stylus/monster.styl:40:8
36| font-weight: 300;
37| }
38| }
39|
40| #media only screen
--------------^
41| and (min-width:991px)
42| and (max-width:1999px) {
43|
expected "indent", got "media"
What is wrong with the code?
One problem is this:
The first:
#media only screen
and (min-width:991px)
and (max-width:1999px)
The segment of pixel-widths here is [991; 1999];
The second:
#media only screen
and (min-width: 1200px)
The segment of pixel-widths here is [1200; +infinite]
If you take a look at those two arrays of pixel-widths: there are some elements that are included in both media queries: [1200; 1999];
That will result in an error, becase they can't both run, when the condition is true for both of them.
Check for other problems like this.
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.