No right floating for small-state in Foundation-framework - css

I have a <p class="right"> in my Zurb Foundation-based layout. But I don't want it to float right on small screens. Is there a built-in solution in Foundation? Or do I have to create my own class for it?
Thanks in advance!

No, there isn't. In accordance to this you have to create your own class (or classes).
One class for #medium-up screens
SCSS
.medium-right {
#media #{$medium-up} {
float: right !important;
}
}
Compiled CSS (with default Foundation breakpoints)
#media only screen and (min-width: 40.063em) {
.medium-right {
float: right !important;
}
}
HTML (usage)
<p class="medium-right">
Class for every screen size
If you want to generate right classes for every screen size, you can use something like this:
SCSS
#for $i from 1 through length($align-class-names) {
#media #{(nth($align-class-breakpoints, $i))} {
.#{(nth($align-class-names, $i))}-right { float: right !important; }
}
}
Compiled CSS (with default Foundation breakpoints)
#media only screen and (max-width: 40em) {
.small-only-right {
float: right !important;
}
}
#media only screen {
.small-right {
float: right !important;
}
}
#media only screen and (min-width: 40.0625em) and (max-width: 64em) {
.medium-only-right {
float: right !important;
}
}
#media only screen and (min-width: 40.0625em) {
.medium-right {
float: right !important;
}
}
#media only screen and (min-width: 64.0625em) and (max-width: 90em) {
.large-only-right {
float: right !important;
}
}
#media only screen and (min-width: 64.0625em) {
.large-right {
float: right !important;
}
}
#media only screen and (min-width: 90.0625em) and (max-width: 120em) {
.xlarge-only-right {
float: right !important;
}
}
#media only screen and (min-width: 90.0625em) {
.xlarge-right {
float: right !important;
}
}
#media only screen and (min-width: 120.0625em) and (max-width: 6249999.9375em) {
.xxlarge-only-right {
float: right !important;
}
}
#media only screen and (min-width: 120.0625em) {
.xxlarge-right {
float: right !important;
}
}

I use Foundation without compiled SCSS as part of my toolchain.
For this situation, I've addressed this issue by adding some simple logic to my application Javascript that's included with every page:
app_stuff = {
resize_handler: function (event) {
if (window.matchMedia(Foundation.media_queries['small']).matches)
{
$(".medium-up-text-right").removeClass("text-right");
}
else
{
$(".medium-up-text-right").addClass("text-right");
};
}
}
:
$(window).resize(Foundation.utils.throttle(app_stuff.resize_handler, 10));
(This is an edited version of my actual code, untested. The full code is at https://github.com/gklyne/annalist/blob/master/src/annalist_root/annalist/data/static/js/annalist.js, and the corresponding Django master page template is at https://github.com/gklyne/annalist/blob/master/src/annalist_root/annalist/templates/base_generic.html - relevant includes are at the end of the template.)

Related

A media query that is wrongly taken into account

I have an issue with media query. I tried to reproduce it on fiddle without success. So sorry if you have not a fiddle. As I have been searching quite a lot of time, I only expect from you to give me ideas how to resolve it.
I have those media queries
#media (min-width: 576px) {
input, textarea, .invalid-feedback {
width: 22vw;
}
}
#media (min-width: 768px) {
input, textarea, .invalid-feedback {
width: min(16.66vw, 200px);
}
}
When I display my screen with a width of 782px and lower, the media query #media (min-width: 576px) is taken into account, which is not normal. Do you have an idea ?
EDIT
I think there is a problem with media queries. I tried the following
#media (min-width: 576px) {
input, textarea, .invalid-feedback {
width: 22vw;
}
body {
background-color: red !important;
}
}
#media (min-width: 768px) {
input, textarea, .invalid-feedback {
width: min(16.66vw, 200px);
}
body {
background-color: green !important;
}
}
and I can't see a background color red or green when I have a size of 779px

Css: responsive other divs when hide a previous div

My page here: https://webtan.jp/
I hide this section:
#top__fullcarousel {
display: none;
}
but after hiding it, the following part (the siteContent block) didn't fit (
the error here)
I fixed the padding and it's only working with viewport(min width 1200px), not working rightly with other viewports (mobile, ipad...)
.siteContent {
padding-top: 129px;
}
How can I responsive it in this case?
You can explicitly set padding that you need for each by each device width:
#media screen and (max-width: 1000px) {
.siteContent {
padding-top: 129px;
}
}
#media screen and (max-width: 850px) {
.siteContent {
padding-top: 109px;
}
}
#media screen and (max-width: 600px) {
.siteContent {
padding-top: 89px;
}
}
#media screen and (max-width: 320px) {
.siteContent {
padding-top: 69px;
}
}
Of course you can use a lot of another methods, but this one is most ease way.

How do I hide or show content with CSS depending on screen size?

Just like Bootstrap, Ionic (Ionic 3) lets us resize the width of a column based on screen size using col-sm-8, col-md-6, col-lg-4. Bootstrap also comes with classes like visible-xs, hidden-sm, etc. that enables us to show or hide content according to the screen size. Does Ionic 3 ship with anything that lets us do the same?
I copied the following CSS classes from Bootstrap 4 Alpha into my project and they work perfectly.
.invisible {
visibility: hidden !important;
}
.hidden-xs-up {
display: none !important;
}
#media (max-width: 575px) {
.hidden-xs-down {
display: none !important;
}
}
#media (min-width: 576px) {
.hidden-sm-up {
display: none !important;
}
}
#media (max-width: 767px) {
.hidden-sm-down {
display: none !important;
}
}
#media (min-width: 768px) {
.hidden-md-up {
display: none !important;
}
}
#media (max-width: 991px) {
.hidden-md-down {
display: none !important;
}
}
#media (min-width: 992px) {
.hidden-lg-up {
display: none !important;
}
}
#media (max-width: 1199px) {
.hidden-lg-down {
display: none !important;
}
}
#media (min-width: 1200px) {
.hidden-xl-up {
display: none !important;
}
}
.hidden-xl-down {
display: none !important;
}
Docs:
https://v4-alpha.getbootstrap.com/layout/responsive-utilities/
Example:
<div hidden-xs visible-block-md>Hidden on small screen</div>
A SCSS solution would be:
$screen-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px
) !default;
#each $keySize, $valueSize in $screen-breakpoints {
[hidden-#{$keySize}] {
#media (min-width: $valueSize) {
display: none;
}
}
}
#each $keySize, $valueSize in $screen-breakpoints {
[visible-block-#{$keySize}] {
#media (min-width: $valueSize) {
display: block;
}
}
}
#each $keySize, $valueSize in $screen-breakpoints {
[visible-inline-block-#{$keySize}] {
#media (min-width: $valueSize) {
display: inline-block;
}
}
}
If you're using Ionic you could go with something like:
#each $breakpoint in map-keys($screen-breakpoints) {
$infix: breakpoint-infix($breakpoint, $screen-breakpoints);
#include media-breakpoint-up($breakpoint, $screen-breakpoints) {
// Provide `[hidden-{bp}]` attributes for floating the element based
// on the breakpoint
[hidden#{$infix}] {
display: none !important;
}
}
}

Changing Foundation's topbar breakpoint with custom CSS?

I'm trying to move from Bootstrap to Foundation, but I'm having an issue in trying to identify how to exactly change the breakpoint for the topbar in Foundation. I'm using a a CDN version of the minified CSS for Foundation, so I do NOT have access to the settings SASS file to modify this. Is there a quick CSS override workaround? So far my searches on here, and Google, haven't turned up a working solution.
Import another CSS file below the minified Foundation CSS that will target the topbar
<link rel="stylesheet" href="foundation-min.css">
<link rel="stylesheet" href="override.css">
So, for example, if .topbar has margin: 1px; override it on override.css by setting another margin: 2px; attribute there.
This post will help
https://stackoverflow.com/a/31511646/6294600
Have you checked this one https://zurb.com/university/lessons/change-foundation-s-default-breakpoints
EDIT: a hint here...
look for the .show-for-medium class... I hope you know what to do after that... Don't give up...
#media screen and (max-width: 39.9375em) {
.hide-for-small-only {
display: none !important; } }
#media screen and (max-width: 0em), screen and (min-width: 40em) {
.show-for-small-only {
display: none !important; } }
#media screen and (min-width: 40em) {
.hide-for-medium {
display: none !important; } }
#media screen and (max-width: 39.9375em) {
.show-for-medium {
display: none !important; } }
#media screen and (min-width: 40em) and (max-width: 63.9375em) {
.hide-for-medium-only {
display: none !important; } }
#media screen and (max-width: 39.9375em), screen and (min-width: 64em) {
.show-for-medium-only {
display: none !important; } }
#media screen and (min-width: 64em) {
.hide-for-large {
display: none !important; } }
#media screen and (max-width: 63.9375em) {
.show-for-large {
display: none !important; } }
#media screen and (min-width: 64em) and (max-width: 74.9375em) {
.hide-for-large-only {
display: none !important; } }
#media screen and (max-width: 63.9375em), screen and (min-width: 75em) {
.show-for-large-only {
display: none !important; } }
These parts can be found in
https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/foundation.css
Change the values, I hope this answers the question. Happy Coding...
LAST BIT OF INFO:
change the min-width size
#media screen and (min-width: 64em) {
.top-bar{
display:none;
}
}

Swap out 3 differently-sized logos with media queries?

I'm trying to have 3 different logo sizes (small, med, big) based on different screen sizes. Here's my code:
#media screen and (max-width: 487px) {
.site-header .site-branding {
background-image: url("../images/logo_small.png") !important;
}
}
#media screen and (max-width: 1079px) {
.site-header .site-branding {
background-image: url("../images/logo_med.png") !important;
}
}
#media screen and (min-width: 1080px) {
.site-header .site-branding {
background-image: url("../images/logo_big.png") !important;
}
}
This works swapping from big to med, but it won't swap again from med to small. Why?
Try to use the min-width on the second media query also. Even when the screen is small the second query is true and the last css gets preference so its loading the second query image.
Make the following change.
#media screen and (max-width: 487px) {
.site-header .site-branding {
background-image: url("../images/logo_small.png") !important;
}
}
#media screen and (min-width: 487px) and (max-width: 1079px) {
.site-header .site-branding {
background-image: url("../images/logo_med.png") !important;
}
}
#media screen and (min-width: 1080px) {
.site-header .site-branding {
background-image: url("../images/logo_big.png") !important;
}
}
You can order it like this:
CSS:
#media screen and (min-width: 1080px) {
.site-header .site-branding {
background-image: url("../images/logo_big.png") !important;
background: blue;
}
}
#media screen and (max-width: 1079px) {
.site-header .site-branding {
background-image: url("../images/logo_med.png") !important;
background: green;
}
}
#media screen and (max-width: 487px) {
.site-header .site-branding {
background-image: url("../images/logo_small.png") !important;
background: red;
}
}
DEMO HERE
See: http://css-tricks.com/logic-in-media-queries/ under 'Overriding'.
I think what is happening is both the first and second media queries are true, so the second one is overriding the first; thus, never reaching the point to switch to small.
Solution: move the first media query to be the final one... should fix it and adjust accordingly.

Resources