I'm trying to change the style of some semantic ui components. I've created a css file and I've been changing the parameters there. Then I noticed that all component css files (in Semantic UI folder) have the following code at the end:
/*******************************
Theme Overrides
*******************************/
/*******************************
Site Overrides
*******************************/
I've copy pasted the code from my css file to the bottom of the component css file but the styles were not updated/overrided. I tried to use !important but it didn't worked either.
I've tried something like this:
/*******************************
Theme Overrides
*******************************/
.ui.header {
border: solid red; !important
border-width: 2px; !important
}
I was expecting this element to get a red border around it
<div class="ui small header">This is a header</div>
Any idea why it didn't worked ?
You need to add your overriding CSS styles in src/site/elements/header.overrides file and run gulp build command.
If "gulp watch" is already running, then it will automatically run build task on detecting changes in the aforementioned file.
The src/site folder is present to override any style introduced by the selected theme.
Try including '!important' within ';' in your code like this,
.ui.header {
border: solid red !important;
border-width: 2px !important;
}
Another possible solution would be to nest all your application's less styling under a unique id, used at the root element of your app.
for example in my own case:
#__next {
.is-pink {
color: pink
}
.mb-70 {
margin-bottom: 70px !important;
}
}
Related
I'm using css modules in a create-react-app project (React V17.0.2 / React-Scripts V4.0.3). All seems well in local but the styles break in production (hosted on netlify).
I believe the problem is that the css modules are not recognizing variables I've defined globally in plain css files. Here's an example of the set up I came up with:
index.css file imported at the top level index.js in my react project:
#import '../Global/ColorScheme.css';
body {
// body styles
}
a {
// global a tag styles
}
ColorScheme.css:
:root {
--green: #00b890;
--pink: #ef767a;
--brown: #554348;
--orange: #fb8f67;
}
Then some CSS module consuming global styles from ColorScheme.css..
SomeFile.module.css
.greenBox {
background-color: var(--green);
height: 500px;
width: 500px;
border: 1px solid #333;
}
Example Component
import React from 'react';
import styles from '../somePath/SomeFile.module.css';
export default function MyComponent() {
return <div className={styles.greenBox} />;
}
When I run it locally I will get a green box with height & width at 500px with a 1px solid black border around it. So all is working as expected. However the production build will show a 500px by 500px box with 1px solid black border but no background color. I'm guessing it's the disconnect is when a css module is using a variable defined in a plain css file. Maybe something with the way webpack compiles down a create-react-app for production build?
Does anyone have any ideas as to why this might be happening and any way I can get around it? I've seen instances of global variables in css modules but I'm trying to avoid importing the global styles in every single module.
I found the solution to my own problem and originally had that solution in the OP as an edit. Moving this to 'Answer my own question' so it's more clear if someone finds this issue in the future:
I found a work around by chance, but I don't understand the 'why' or 'how'. It seems like my custom CSS properties defined in :root were working, just not the ones I titled with color names (i.e. --navy, --green, --orange, or even --gray-scale-0). After running create-react-app's standard npm run build the produced main.css file would replace my css like this:
Some CSS Module Before Build
.someClass {
color: var(--green);
background-color: var(--gray-scale-0);
}
Same Class in Main.####.chunk.css After Build
.someClass {
color: var(green);
background-color: var(gray);
}
Changing my custom properties to something like --theme-orange or --theme-green works just fine. I'm still new to webpack and preprocessors so if anyone knows why this happens I'd love to know.
You should define the variable with $ and use it also with $ without any problem =>
$green : #00b890;
.greenBox {
background-color: $green;
}
I am trying to apply CSS to Vaadin 8 component. I have followed this example and still unable to apply CSS. I understand that i can call the addStyleName method and i am able to apply the build in ValoTheme styles (for example ValoTheme.PANEL_BORDERLESS does make a button smaller), but my custom styles are ignored. I have tried defining my custom CSS rules in the following files:
/src/Main/webapp/VAADIN/themes/apptheme/styles.css
#import "../reindeer/styles.css";
.mystyle {
color: red;
background: #012345;
background-color: #012345;
}
Then in Java i create a button:
Button btn = new Button(" Test ");
btn.addStyleName("mystyle");
My custom style does not get applied to the button. I suspect that i am not defining CSS correctly. Please share your knowledge of how to do this correctly in Vaadin 8.
This is not related, but are you actually using a reindeer theme?
Otherwise, you should put you styles in your own theme file (the default one generated from an archetype is mytheme.scss)
It's suggested to leave styles.scss as it is. Also, it's mentioned in comments section of the file:
This file prefixes all rules with the theme name to avoid causing conflicts with other themes. The actual styles should be defined in mytheme.scss
If you want, you could add your styles there as well under
.mytheme {
#include addons;
#include mytheme;
.testStyle{
color: red;
background: #012345;
background-color: #012345;
}
}
While it works, I will still suggest to add them to your custom scss file (Based on your folder name it is apptheme.scss)
Mine mytheme.scss looks like this:
#import "../valo/valo.scss";
#mixin mytheme {
#include valo;
.testStyle{
color: red;
background: #012345;
background-color: #012345;
}
}
After styles are applied, button looks like this:
Style files are located under webapp/VAADIN/themes/mytheme
I have an issue :
I'm working on an existing page which uses this calss , componentContainer to set different page style.
In order to update the screen content i had to include an existing .css file, so everything works fine but ia have a problem with this file in fact it also implement a class named also componentContainer, as follow:
#componentContainer {
background-color: rgb(242, 242, 242);
}
As you can see the page background is grey but i want it white.
Which is the best way to get rid of this style element background-color: rgb(242, 242, 242) without affecting the page content?
You can give:
#componentContainer {
background-color: #fff;
}
in your external CSS file to change the colour.
If it does not work use !important [it will force the style to be over-right by your custom style.], you can use this style:
#componentContainer {
background-color: #fff !important;
}
I hope the above code will solve your issue.
You cannot remove style definitions but you can override them. CSS styles are applied in order so if you have another style definition
#componentContainer {
background-color: #fff;
}
and make sure it shows up in your HTML (either inline, in the same CSS file or in a new CSS file) after the style definition mentioned above then that will be overridden.
You need to overwrite that class after including desired css file.
Overwrite in your page style with important property
**strong text**componentContainer {background-color: white !important;}
I am trying to make a toggle between night mode and day mode only by changing colors. I have some base color variables inside my _colors.scss, and they are used all over my site. I use React to toggle a className between 'night-mode' and 'day-mode' at the first div of the project.
I have tried to wrap the variables in the mentioned class names, but the result is that no other files can access the variables. Therefore I was hoping for a solution where I can use a night-mode file and a day-time file and toggle between them.
As I see it now, the issue is that I can't wrap the $variables or the #import in a class name, which makes it difficult to know what mode is selected. I am looking for a solution that does not include jQuery (I have a variable globally stored that can be used for javascript reference if that ends up to be the best solution).
You can't toggle scss files at runtime, since they are already compiled to css.
I would go with CSS custom properties (sometimes called CSS variables) instead of pure Sass variables.
Example:
:root {
--background: lightblue;
}
.night-mode {
--background: darkblue;
}
.component {
background-color: var(--background);
}
Toggle the class .night-mode on with javascript depending on the time of day.
You may of course feed your CSS custom properties from Sass variables in your scss files:
$bg-day: lightblue;
$bg-night: darkblue;
:root {
--background: $bg-day;
}
.night-mode {
-- background: $bg-night;
}
.component {
background-color: var(--background);
}
I have added the following lines to bootstrap/less/panels.less
//hover color for panel heading
.panel-heading:hover {
background-color: #dfdfdf;
}
But it wouldn't load to the css in the browser. yet I can manually add it in the css editor (in chrome dev tools) and it works.
Any solutions ?
If it works in chrome dev tools and in css file not, that means it is overwritten from other rule. You can overwrite the rule by increasing the specificity (e.g. concatenate another class name or some other selector), or, to be sure, use "!important":
.panel-heading:hover {
background-color: #dfdfdf !important;
}