Why my SASS project is disregarding media breakpoints? - reactjs

I used to use CSS for a React project, but for the implementation of a "dark mode" functionality I decided to move to SASS.
I also use bootstrap so I organize my files according to the documentation.
/* App.scss */
#import "~bootstrap/scss/bootstrap.scss";
#import './styles/_themes';
#import './styles/_fonts';
h1, h2, h3, h4, h5, h6 {
font-family: $font-family-secondary;
#include themed() {
color: t($title-color)
}
}
p {
font-family: $font-family-primary;
#include themed() {
color: t($text-color)
}
}
hr, .nav-tabs {
#include themed() {
border-color: t($text-secondary-color)
}
}
.base {
height: 100%;
width: 100%;
#include themed() {
background-color: t($background-color)
}
}
.main {
width: 750px;
#include themed() {
background-color: t($background-color)
}
}
First, I thought it was a bootstrap problem, but the breakpoints are also being disregarding in my own files.
/* Footer.scss */
#media (max-width: 767px){
#footer h5 {
padding-left: 0;
border-left: transparent;
padding-bottom: 0px;
margin-bottom: 10px;
}
}
I made a minimal reproducible example and posted it to codesandbox: https://codesandbox.io/s/immutable-fire-qu9oe
Please, try to decrease the screen size and check the media breakpoints being disregarded.
What am I doing wrong?
Thank you very much!
EDIT:
Thanks to robertp's answer I could fix my custom media breakpoints.
But how can I fix bootstrap ones?
For example, in my navbar I have a media breakpoint for a bootstrap class:
/* Navbar.scss */
#media (max-width: 571px) {
.collapsing {
#include themed() {
position: absolute !important;
z-index: 3;
width: 100%;
top: 75px;
}
}
.collapse.show {
#include themed() {
display: block;
position: absolute;
z-index: 3;
width: 100%;
top: 75px;
}
}
.navbar.open {
#include themed() {
transform: translate(0, 0)
}
}
.overlay.open {
#include themed() {
height: 100%;
opacity: 1;
}
}
}
But it didn't work. Also, how I could fix all bootstrap grid system classes?
EDIT 2:
The problem was the import order. If I put the bootstrap import at the end of the file everythings works as expected!

It seems to be due to specificity in the theme. Your footer H5 element is styled as per the theme, so you need to override the themed version of it.
Screenshot of the themed styling overriding your mediaquery based styling:
This should work:
#media (max-width: 767px){
#footer h5 {
#include themed() {
padding-left: 0;
border-left: transparent;
padding-bottom: 0px;
margin-bottom: 10px;
}
}
}

Related

styled components using global ::selection pseudo element

I'm trying to apply a global stylesheet to my React project, which will change the highlight color from the default blue.
However, I can't figure out how to use the ::selection pseudoelement with styled components.
const GlobalStyle = createGlobalStyle`
#import url('https://fonts.googleapis.com/css2?family=Manrope:wght#300;400;700&display=swap');
* {
/* border: 1px solid blue; */
}
html {
font-size: 62.5%; // sets 1rem = 10px
padding: 0;
margin: 0;
&::selection,
&::-moz-selection {
color: red;
background-color: yellow;
}
}
Figured it out, the ::selection pseudoelement should be at the root level
const GlobalStyle = createGlobalStyle`
#import url('https://fonts.googleapis.com/css2?family=Manrope:wght#300;400;700&display=swap');
* {
/* border: 1px solid blue; */
}
html {
font-size: 62.5%; // sets 1rem = 10px
padding: 0;
margin: 0;
}
::selection, {
color: red;
background-color: yellow;
}

"Maximum call stack size exceeded" after upgrading to alpha version of antd

Using npm I updated my antd dependency to 4.17.0-alpha.0. When I tried to run my react app after I updated it, it throws an error.
The error:
./src/App.less (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-8-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--5-oneOf-8-3!./node_modules/less-loader/dist/cjs.js??ref--5-oneOf-8-4!./src/App.less)
Maximum call stack size exceeded
The App.less (I believe there's nothing wrong with this):
#import "~antd/lib/style/themes/default.less";
#import "~antd/dist/antd.less";
#import "~antd/dist/antd.compact.less"; // Introduce the official compact less style entry file
.login-form-container {
height: 80vh;
.login-form {
padding: 30px 0;
background-color: #fff;
.button {
width: 100%;
}
}
}
.footer {
background-color: #primary-color;
.text {
color: #fff;
}
}
.title {
padding: 0;
margin: 0;
}
#notif {
margin: 0;
padding: 0;
}
.header-icon {
font-size: 18px;
color: #black;
}
.page-header {
margin: 5px;
}
.content-container {
background-color: #fff;
padding: 15px;
min-height: 70vh;
margin: 10px 25px;
}
(P.S.) The reason why I want to update to the alpha version because of the Drawer component. The Drawer component has an extra prop which is available only in the latest alpha version. Here's the Drawer Documentation. Maybe I missed something.
I am new to Ant Design.
Install new alpha release to fix it.
npm install --save antd#4.17.0-alpha.2

How do you style nested css in react?

I have nested selectors in my css file. I'm new to React and trying to make it work with my js file. Does anyone have any tips?
I found: https://blog.logrocket.com/the-best-styling-in-react-tutorial-youve-ever-seen-676f1284b945
It seems to be helpful but does not mention how to deal with nested css. For example, I have &:before and &:after, #include signUpActive, among others. This is really some confusing stuff.
.img {
overflow: hidden;
z-index: 2;
position: absolute;
&:before {
content: '';
position: absolute;
transition: transform 1.2s ease-in-out;
}
&:after {
content: '';
position: absolute;
}
#include signUpActive {
&:before {
transform: translate3d(640px,0,0);
}
}
&__text {
z-index: 2;
position: absolute;
transition: transform 1.2s ease-in-out;
&.m--up {
#include signUpActive {
transform: translateX(260px*2);
}
}
&.m--in {
transform: translateX(260px * -2);
#include signUpActive {
transform: translateX(0);
}
}
}
&__btn {
overflow: hidden;
z-index: 2;
position: relative;
&:after {
content: '';
z-index: 2;
position: absolute;
}
&.m--in {
transform: translateY(36px*-2);
#include signUpActive {
transform: translateY(0);
}
}
&.m--up {
#include signUpActive {
transform: translateY(36px*2);
}
}
}
}
}
It is actually not "nested CSS". But it is a SASS/SCSS code. Both SASS and SCSS have similar purposes, with several slight differences. Please check here for more detail: https://www.geeksforgeeks.org/what-is-the-difference-between-scss-and-sass/ . Personally, I would suggest SCSS over SASS by considering it is less strict than SASS.
If you like to use just normal CSS, then just write and import CSS scripts to your react. It will be no problem. You should not follow that "nested CSS" way which is SASS/SCSS ( I would not recommend that actually ).
Let assume you stick with SASS/SCSS. If you are using "CRA" ( create react application ), it is just as simple as import your .scss file to react component like the following:
import React from "react";
import ReactDOM from "react-dom";
import "./styles.scss";
function App() {
return (
<div className="App">
<div className="panel">
<h2>Panel</h2>
<div className="panel__inner">
<h3>Inner panel</h3>
</div>
</div>
</div>
);
}
While the styles.scss is just a normal SCSS code at same directory, like follow:
#import "./scss-mixins/mixins.scss"; //Using relative path to the .scss file
.App {
font-family: sans-serif;
text-align: center;
.panel {
padding: 15px;
background: #f9f9f9;
&__inner {
padding: 10px;
background: green;
}
}
}
Just ensure that you have node-sass in your package. Otherwise you should do npm install node-sass --save. Please read more at official documentation here: https://facebook.github.io/create-react-app/docs/adding-a-sass-stylesheet.
You can check working example at: https://codesandbox.io/s/x2z4ly6y2z

Bootstrap AngularJS fullscreen table

I have a table with a lot of columns and a horizontal scrollbar. I'm searshing a way to show it in fullscreen, like you can do in gmail when you want to see an mail attachement with a glyphicon-resize-full
If someone have an idea :)
edit : I'm trying with this :
<div id="overlayContainer" class="overlay">
<div id="overlayContent" class="overlay-content">
</div>
using a css to have a bigger table on a black background
<style>
.overlay {
height: 0;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
#media screen and (max-height: 450px) {
.overlay a {
font-size: 20px;
}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
and I fill the div overlayContent or close it by this way :
$scope.fullScreenElement = function () {
document.getElementById("overlayContainer").style.height = "100%";
document.getElementById("overlayContainer").style.width = "100%";
document.getElementById("overlayContent").innerHTML = document.getElementById("tableContent").innerHTML;
};
$scope.reduceElement = function () {
document.getElementById("overlayContainer").style.height = "0%";
document.getElementById("overlayContainer").style.width = "0%";
};
But with that I can't use JS functions of my table :(
edit : Here is an example : http://plnkr.co/edit/1ge8r8zFANDNt2P2k0kI?p=preview
I couldn't reproduce it, but table should have horizontal scrollbar and you should't see lasts columns at the right. And if you expand it, you see the entire table but javascript like click on column name to sort (it's not in my Plunker) doesn't work
edit : I tried a second time with your angular.element(document.getElementById($scope.id)).addClass("overflowFullScreen");
Nimmi, and it's better than my first try, it keeps JS functions. I continue with this, but looks good. Thank you !
final edit : I resolves lasts problems caused by z-index and a missing vertical scrollbar but it is done ! Thank you for your help !

Firefox view responsive layout doesn't work

I am working on a responsive layout locally. I am testing with firefox responsive layout tool. For some reason Firefox is not applying the media query for 320px. I tried this solution Browser not recognizing max-device-width but it didn't work.
Any idea?
My code
#media only screen and (max-width: 320px) {
.btn-default {
display: inline-block !important;
}
.slide figure figcaption {
right: 21%;
width: 67%;
}
aside {
width: 64%;
margin-top: 0%;
margin-right: 30%;
}
.footerFloat {
width: 25%;
float: left;
min-width: 200px;
margin-left: 118px;
}
.textul {
text-align: left;
}
h1 {
font-size: 20px;
text-align:left;
margin: -36px 0px 16px;
}
}
When I debug my code with inspect element at 320px resolution it doesn't read the above code. Intsead goes to:
#media only screen and (max-width : 800px) {
.btn-default {
display: inline-block !important;
}
aside {
width: 64%;
margin-top: 0%;
margin-right: 30%;
}
header {
background-position: center;
background-image: url('Images/logo_mobile.png') ;
}
h1 {
font-size: 20px;
text-align:center;
margin: -136px 0px 16px;
}
.textul {
text-align: left;
}
}

Resources