I am trying to make the font on my app larger for small devices by overriding bootstrap media queries.
I am trying to do it like this, by setting the font size for h1's using bootstrap media queries
#media (min-width: #screen-sm-min) {
h1{font-size: 5rem}
}
only I get this Rails error message.
Invalid CSS after "...ia (min-width: ": expected expression (e.g. 1px, bold), was "#screen-sm-min) {"
I see in the below answer they are overriding by explicitly stating the width, which doesn't throw the error anymore for me, but I'm not sure why I can't use bootstraps variables. Do I have to set the value of #screen-sm-min somewhere in order to use it?
Rails 4 Bootstrap 3.3, media queries causing error
Looks like this number explains what was going on on the bootstrap migrating to bootstrap 4 website:
https://v4-alpha.getbootstrap.com/migration/
All #screen- variables have been removed in v4.0.0. Use the media-breakpoint-up(), media-breakpoint-down(), or media-breakpoint-only() Sass mixins or the $grid-breakpoints Sass map instead.
If you're using sass you can do something like this for small devices:
#include media-breakpoint-up(xs) {
strong {
font-size: 5rem;
}
}
But I ended up ultimately setting the values:
#media (min-width: 576px) {
strong {
font-size: 4rem;
}
}
The media query should say:
#media (min-width: $screen-sm-min) {
h1 {
font-size: 5rem;
}
}
variables in css start with a dollar sign. Assuming the variable is actually called screen-sm-min, you should be good. You also forgot the semi-colon after font-size: 5rem just FYI
Related
I am new to web development and I am facing a hard time dealing with media queries.
I am creating a dance website but my following media queries in "media-query.css" are not getting fired.
#media screen and (max-width:1800px) and (min-width: 399x) {
.our-services ul li {
font-size: 2rem;
padding: 2rem;
}
}
#media screen and (max-width: 400px) {
.our-services ul li{
font-size: 2rem;
padding-left: 0rem;
padding-top: 2rem;
padding-bottom: 2rem;
}
}
Project link: https://github.com/abhinav700/DanceMasti.com
Too lazy to go through all of those files so I'll list some common errors out here in case someone else finds this question and has a different cause:
Maybe you haven't linked the file. Add <link src="your-directory/media-query.css"></link> to your html file.
Your queries are being overridden by a file with a higher priority. Test this
by leaving !important after your lines, i.e width: 50px !important;. Note that
using important is considered bad code by some(I have no opinion on this,and
have no idea if it's true).
As posted by another user, your media query is a bit off, so you could be toeing
the line and using exactly 400px. I doubt it though. The lower query should be
taking precedence, so it still should look like a mobile view.
Check to make sure that you are using the selectors correctly. Your selectors
currently are looking for a <li> inside a <ul> inside any element with a
class of our-services(someone correct me if I'm wrong). The way I like to
check this is just to set a clause:
li{
position: none;
}
and see if this element disappears. If it does and nothing else pops up... I got nothing.
If this answer helped, please mark it as answer.
It says 399x instead of 401px. So it could be both a syntax issue and a overlap issue.
I am creating a chart that shows keyboard commands overlaid on top of an image of a keyboard. I would like the text to shrink to the size of the container if it is too long to fit inside a key, but remain the default size otherwise. How would I accomplish this in HTML? The solutions I've seen seem to always alter the text size, versus only when the container is too small. Thanks.
Here's an example of what the result might look like:
You can use something like word-wrap or overflow-wrap or adding a variable with css(i.e: a font-size that fits your needs) and only change it when a media queries (that you established) returns true;
Media Queries explanation:
Let's say I established this variable
:root {
--font-size: 16px;
/* this is your regular font size that you will use in your entire document */
}
So in a given screen size like so:
#media screen and (device-width: 320px) and (orientation: portrait) {
:root {
--font-size: 12px;
}
}
You just change the value of the variable and it will change where ever you used that specific variable
If you don't know how this works you can use this css variables like this
.someClass {
font-size: var(--font-size); */ and that's it :) */
/* You can also make calculations like this */
font-size: calc(var(--font-size) - 40%);
}
Reference:
overflow-wrap: https://css-tricks.com/almanac/properties/o/overflow-wrap/
word-wrap: https://css-tricks.com/almanac/properties/w/word-break/
css variables: https://www.madebymike.com.au/writing/using-css-variables/
media queries: https://www.uxpin.com/studio/blog/media-queries-responsive-web-design/
I'm looking for a smart way to control fonts sizes depending on browser resolution - as reusable ass possible.
So i have done the following:
<section>
<h1>Contact</h1>
</section>
And in LESS file i've defined:
.h1 {
font-size: 90px;
}
section h1 {
.h1;
}
So, as you see i have .h1 class defined and i can reuse it.
But later i saw that my idea is now working (media queries don't work:)
#media only screen and (max-width: 991px) {
.h1 {
font-size: 20px;
}
}
.h1 class has 90px always and media queries didn't change font size to 20px.
My question: is this possible to tweak to work ?
This way i can have small amount of reusable classes and change their size in just one place instead of many places.
Thanks.
PS: I've benn using REM's for long time but it's not perfect for me.
I use a fluid-typography mixin, as show in this guide. This page links to a codepen showing a less mixin.
Essentially you pass through the font size values you want to scale between and also the screen sizes that the scaling to occur between. Beneath is some code directly from the codepen link:
.fluid-type(#property, #min-vw, #max-vw, #min-size, #max-size) {
#{property}: #min-size;
#media screen and (min-width: #min-vw) {
#{property}: calc( #min-size ~" + " unit(#max-size - #min-size) ~" * ((100vw - " #min-vw ~") /" unit(#max-vw - #min-vw) ~")" );
}
#media screen and (min-width: #max-vw) {
#{property}: #max-size;
}
}
the way I use it:
h1{
.fluid-type(font-size, #mobileSize, #desktopSize, 36px, 72px);
}
credit to Mike
Ok, I have encountered a problem while experimenting with media queries. I'm wondering if any of you could possibly help me on this issue. The purpose of this code is simple. When the screen size is above 600px the banner should not be visible and when the screen size is below 600px the banner should appear.
#media (max-width: 600px) {
.banner {
display: none;
}
}
<header class="banner">
<h1>Banner</h1>
<p>Banner Content</p>
</header>
Now as you run the code above(I assume you just did) there is nothing wrong.
Ok, now I will add similar code.
#media (max-width: 600px) {
.banner {
display: none;
}
}
.banner {
display: block;
}
<header class="banner">
<h1>Banner</h1>
<p>Banner Content</p>
</header>
Outside of the query is a style that contradicts the style given in the media query. Now what I believe to know about media queries. The styles within the query should override any other existing styles just as long as the screen-size condition is met.
If this is normal, what would be the best way of having the style within the media query override the other existing styles outside the query.
(Assuming all else is equal) Styles are activated in the order of precedence that they're encountered, unless encased in what amounts to an IF query, such as a media query.
.banner {
display: block;
}
So the above CSS will always display, no matter what other IF statements come before the rule itself. Which is not what you want.
Solutions:
1) You instead need it to be encapsulated within its own media query to only show when ABOVE 600px so:
#media (min-width: 601px) {
.banner {
display: block;
}
}
2) You place all your media queries in reverse order, so all at the bottom of (last in) your CSS file(s), so the media qualifiers are read AFTER the standard rules.
EDIT:
As Sean qualifies in comments, there are various more specific CSS selections, rather than just the order of appearance in the file, that can bend which rules take precedent over others. The order of appearance works in this case and works when the subject rules are all equal (such as all direct classes only) but please note that there will be other CSS rule instances that can complicate the issue. This answer is not intended for more complex CSS rule ordering.
It depends on the order of the rules: Every rule that comes AFTER a rule in a media query (for the same class or ID) will override it.
In your case the "general" rule for .banner is below/after the media query, so it overrides the rule in the media query. You have to write the general rules first, followed by the media queries.
I'm trying to understand screen vs. print behavior. What's the reason the APSW docs look different in print vs. screen? (In print, the table of contents column vanishes, and the main column takes up the whole print width)
(I'm trying to debug my sphinx document which doesn't have this behavior, but I figure if I can understand one that works properly, I can figure out why mine doesn't.)
Just something to note, after looking closely at the #media print section in basic.css cited by those of you who answered — there was one line different between my basic.css and the one in APSW:
div.bodywrapper {
margin: 0 !important;
width: 100%;
}
The !important modifier was missing from my basic.css and that was causing the margin: 0 to get overridden.
This is done using media types. With them, you can limit style rules to a certain output device like screen, printer, or handheld.
See here: http://apsw.googlecode.com/svn/publish/_static/basic.css
This is linked to the media type.
You can either link it to a group of properties:
#media screen {
body { font-size: 13px }
}
or to an entire stylesheet
<link href="blah.css" media="all" rel="stylesheet" type="text/css" />
In your case:
#media print {
div.document,
div.documentwrapper,
div.bodywrapper {
margin: 0 !important;
width: 100%;
}
div.sphinxsidebar,
div.related,
div.footer,
#top-link {
display: none;
}
}
They have #media rules.
Take a look at:
http://apsw.googlecode.com/svn/publish/_static/basic.css
They include another css-file in their stylesheet via
#import url("basic.css");