I use Magento Blank as a parent theme.
I have created _theme.less.css in /app/design/frontend/MYVENDORNAME/MYTHEMENAME/web/css/source/ that contains this code:
#button-primary__background: #color-orange-red1;
#button-primary__hover__background: #color-orange-red4;
#button-primary__border: 1px solid #color-orange-red2;
#button-primary__hover__border: 1px solid #color-orange-red2;
I have flushed cache.
But buttons are still blue.
What am I doing wrong?
This code needs to go into a .less file and be compiled into a .css file as this isn't code styles that can be read natively in a css file.
First add your custom css
Go to:
/app/design/frontend/Magento/MYVENDORNAME/MYTHEMENAME/layout/default_head_blocks.xml
And add css under head block looks like this:
<head><css src="css/custom.css" /></head>
And than after create custom.css file in this path:
/app/design/frontend/Magento/MYVENDORNAME/MYTHEMENAME/web/css/custom.css
Run your css, hopefully it's work for you.
All you had to do was to copy files from:
/vendor/magento/theme-frontend-blank/web/css/
Into theme directory:
/app/design/frontend/MYVENDORNAME/MYTHEMENAME/web/css/
You don't have to move all files, you can just replace the files you want to make changes to.
I think you have to learn LESS to be able to style the theme properly. But for simple static CSS changes this might work:
1) Add /dev1/vendor/magento/theme-frontend-blank/web/css/_styles.less with the following content:
#import 'source/lib/_lib.less'; // Global lib
#import 'source/_sources.less'; // Theme styles
#import 'source/_components.less'; // Components styles (modal/sliding panel)
body{background:#f00}
Related
I'm struggling with the dotLESS #import to have a separate variables file; I just constantly get "variable is undefined".
If I browse to the variable config file it works; if I put the variables inline in the main stylesheet it works; but in an #import, no dice. I'm mapping .css as well as .less to the extension, however it also doesn't work if I use .less only.
The variables file LESS-config.less is:
/*
.LESS VARIABLES
*/
#mbw_dark_cyan: #1293b5;
#mbw_cyan: #11add4;
#mbw_magenta: #e935da;
#control_text: #ffffff;
#action_delete: #ff5400;
#section_level1_bg: #mbw_dark_cyan;
#section_level1_fg: #control_text;
#button_bg: #mbw_dark_cyan;
#button_fg: #control_text;
#button_icon: #control_text;
#data_table_header: #mbw_cyan;
.dummy {
color: #control_text;
}
Which renders as:
/*
.LESS VARIABLES
*/
.dummy {
color: #ffffff;
}
Calling stylesheet main.css is:
#import (less) '/css/LESS-config';
button {
background: #button_bg;
}
Which gives the error:
variable #button_bg is undefined on line 4 in file '/css/main.css':
[3]: button {
[4]: background: #button_bg;
----------------^
[5]: }
As I said, if I replace the import with the same variables copied and pasted, it all works fine.
I've tried saving without BOM as in another answer, but that doesn't help.
EDIT, I've tried:
Removing the (less)
Changing to double quotes
Using relative path LESS-config as opposed to virtual absolute as above
Adding logger="dotless.Core.Loggers.AspResponseLogger" log="debug" to
web.config (cache is already false)
Adding debug="1"
Adding
debug="true"
Absolutely no change in behaviour.
EDIT 2:
I created a cut-down css that only had the import statement in it; when I browse to it the imported styles are in there. However, on a refresh, I just get a blank response.
So it seems to be something to do with my IIS config / caching? I've turned off content compression but no joy; disabled all output caching for .less and .css, still no joy!
FIXED as per Toni's comment; https://stackoverflow.com/a/51754771/318411:
This turned out to be a dotLESS issue, tracked on GitHub here: https://github.com/dotless/dotless/issues/553
The complete fix was to:
Upgrade dotLESS to version 1.6.7
Downgrade Microsoft.Extensions.DependencyInjection to 1.1.1.0 due to Method
not found error
Change the file extension of the import from .css to .less
Now all working.
Please try version 1.6.7 which fixes an error that imports are only executed on the very first request.
I potentially see two problems that you have.
You are trying to call #import (less) in a css file. This is a syntax specific to less framework.
Your main.css is not a less file.
Change your main.css to a main.less file and now try generating your css from main.less as your root file.
Assuming your import url for LESS-config.less is correct.
The above mentioned corrections should probably do the trick.
#import (less, optional) "mystyle.css"; is Less syntax, you cannot use it in CSS (Less #import Rules).
If you want to use #import in your CSS, it should follow this syntax (See here)
#import url|string list-of-mediaqueries;
But, you cannot import a Less file inside your CSS anyways.
The way I would have done this:
Say you have 3 .less files: config.less, color.less, header.less
I would create a style.less file with the following content:
/*------------------------------------------------------------------------------*/
style.less
/*------------------------------------------------------------------------------*/
/* 01. config */
#import "config.less";
/* 02. color */
#import "color.less";
/* 03. header */
#import "header.less";
Then I would complie style.less which would produce, style.css and I would include style.css in my website.
Im using Meteor
why node modules are load at last, and overwrite my own css files in imports/ directories?
Im using bootstrap, but there are classes that I don't like as background-color body. Here happens this:
in my directories:
import/ui/socially/socially.less
body{ backgrond-color: #000000;}
but don't work, when the firefox or chrome refresh the same default bootstrap color always appear.
I read the documentation Order Loads but this no solution my issue.
I don't wanna overwrite original files of the bootstrap, or delete, or edit because is not good idea when I will use .git
Any ideas?
Thanks for all. Please I have many days in this issue jajaja
Check your css syntax
body{
background-color: #000000
}
Make sure you load your external CSS file after the bootstrap css file else your rules will get overwritten
If it still doesn't work. Try this :
body{
background-color: #000000 !important
}
I want to extend the theme used by Sphinx and ReadTheDocs with my own custom styles.
What is the best way I can do this so that my changes will stick?
Edit: as of 2021 the following answer is outdated, please use html_css_files = [] in your conf.py instead of using the application API after version 1.8 (current Sphinx version at time of writing is 4.1.1). The add_stylesheet option below has been renamed add_css_file in version 1.8, and seems more intended for Sphinx extension developers.
Assumptions
Your RTD doc set has something like the following structure:
(root path)
(some other stuff not germane to this discussion)
_static/
_templates/
conf.py
You're also building locally using sphinx-build or sphinx-autobuild using the default theme, but your deployed server might use the sphinx-rtd-theme instead.
Use Case: Hatnotes
For this illustration, I'm going to show how to create custom styling for "hatnotes", a concept which is prevalent in MediaWiki docs and which corresponds roughly to the admonition construct in RST. You can apply what's shown here to create any custom CSS and include it in your doc set.
Step 1: Create Custom CSS
The custom CSS file should go somewhere under the _static/ directory, as that's where the build process and scripts will find it. I would encourage a css/ subdirectory, since you might have other customizations to add, like JavaScript files.
Create your custom CSS file and put it in this directory. Write your style specifications as an overlay to whatever might already exist in the theme you'll be using in the build. Also don't assume anything about whether your style will override an existing style in the theme, as you can't guarantee when your styles will be added in relation to the default ones.
Here's my custom CSS for hatnotes. I saved this at _static/css/hatnotes.css.
.hatnote
{
border-color: #c8c8c8 ;
border-style: solid ;
border-width: 1px ;
font-size: x-small ;
font-style: italic ;
margin-left: auto ;
margin-right: auto ;
padding: 3px 2em ;
}
.hatnote-gray { background-color: #e8e8e8 ; color: #000000 ; }
.hatnote-yellow { background-color: #ffffe8 ; color: #000000 ; }
.hatnote-red { background-color: #ffe8e8 ; color: #000000 ; }
.hatnote-icon { height: 16px ; width: 16px ; }
Step 2: Add Styles to Templates
For the default theme, it is sufficient to create a template that overrides the default layout.html to add your custom CSS to the layout. Use of templates is well documented at sphinxdoc.org. In your override template, simply set the css-files variable (an array) with an appended list of your custom CSS files.
Here is my template which adds the hatnotes CSS. I saved this as _templates/layout.html.
{% extends "!layout.html" %}
{% set css_files = css_files + [ "_static/css/hatnotes.css" ] %}
That's all you need to do for the default theme. For the Sphinx/RTD theme, there's an additional step, where you…
Step 3: Add Stylesheets to the Theme
For the Sphinx/RTD theme, your template will be ignored. Instead of using the template mechanism, you have to add a function to your conf.py file which adds the CSS file to the app's theme. Somewhere near where your conf file sets the html_theme attribute, add something like the following:
def setup(app):
app.add_stylesheet( "css/hatnotes.css" )
Note that, this time, there's no _static/ at the front of the path; the add_stylesheet() function assumes that part of the path.
Finishing the Use Case
Now that you've set up your custom styles for both the default theme and the Sphinx/RTD theme, you can actually use them in your doc.
Following the usual paradigm of defining stock hatnotes as "templates" in MediaWiki (sorry, not the same as templates in Sphinx and RTD), I set up an includes/ directory where all my hatnotes would be stored.
Here's how to construct a hatnote with the custom style information. This file is includes/hatnotes/stub-article.rst.
.. container:: hatnote hatnote-gray
|stub| This article is a stub. Please improve the docs by expanding it.
.. |stub| image:: /images/icons/stub.png
:class: hatnote-icon
Here we set up our "stub" hatnote to have the default hatnote styling, the gray background, and use a "stub" icon as the inline image, with the hatnote-icon style applied to that image.
Now we can use the file as an included resource in a document.
Foo Article
===========
.. include:: /includes/hatnotes/stub-article.rst
Blah blah I haven't written this article yet.
Whether you're using the local default theme or the Sphinx/RTD theme, the hatnote will be rendered with the styles you added by setting up the _templates/layout.html template and the conf.py script to both include the custom CSS file you put under the _static/ directory.
End State
Your doc repository now has this stuff in it:
(root path)
_static/
css/
(custom CSS files…)
_templates/
layout.html — (adds your custom CSS to the default layout)
conf.py — (with new function to add custom CSS to app's theme)
I don't know which is most "official" but if you go to the "customisation" page of the Furo theme (developed by one of the Sphinx developers) and then scroll to "Custom CSS Files" it links to a guide to "injecting code" which in turn simply links out to ReadTheDocs's page on Adding Custom CSS which does not suggest running Python code (as the answers above do) but setting a conf variable, which seems better.
html_css_files = [
'css/custom.css',
]
Adding to the accepted answer: There are various other approaches for this, e.g. adding to footer or adding to extrahead. The latter is recommended by the RTD docs.
Also I found the setup() function was never necessary, as long as you have html_static_path = ['_static'] in your conf.py.
Note that normally, you should replace the absolute path [ "_static/css/hatnotes.css" ] with [ pathto("_static/css/hatnotes.css", True) ] or the style sheet will not be loaded for RST files inside subdirectories, but it is evidently unnecessary for the accepted answer. Not sure why.
I am experimenting on themes. For this i have downloaded and installed ruby.
I am clueless as in how to have a different css file to have my own theme for the application.
I think i have make changes to a file with an extension .scss. Can someone walk me through the steps to have my own theme for the application ?
Why not you define partials for theme and put theme related stuff in variables. These partials whould'nt create any .css file. Here is example
Make 3 files home.scss, _homePartials.scss and _homeTheme.scss
_homePartials.scss
$textColor: #333;
_homeTheme.scss
.text { color:$textColor; }
home.scss
.text { width:100%; }
#import '../partials/homePartials';
#import '../partials/homeTheme';
take a look at http://blog.behance.net/dev/how-we-used-sass-to-build-17-websites-in-five-days
We have many images which are actually picked up based on a color theme (e.g. blue, red, gray ...). We create files with a common name under each theme (e.g. background, ...), is there a way to define the color theme in a common place so that the definition can be abstracted out. This would prevent me from changing the color theme all over the css file.
body {
background: url('../img/blue/background.png');
font-size: 13px;
margin: 0px;
}
While the options suggested here are viable approaches, I'd like to mention SASS and LESS
They are two CSS extension languages, which amongst other things provide variables for doing this sort of color stuff you mention.
You can create dynamical CSS file by using any serverside scripting language like PHP.
style.css.php:
<?php
header("Content-type: text/css");
$theme = 'blue';
$color1 = '#fefefe';
?>
body {
background: url('../img/<?=$theme?>/background.png');
font-size: 13px;
margin: 0px;
}
.sometext {
color: <?=$color1?>
}
I don't believe you can with a pure css implementation as you would need to define your base paths for your images in a variable which you set with some logic (switch statement, if/else if, ..etc.) and then use that variable in the css.
Here are some options I thought of to do this. If you create a pseudo css file with your variable defined as a string that does not occur in css (ex: $basePath) and build out all your css rules in this fake css file as "$basePath+image.jpg". Then with some server side code retrieve the css file and create your template css files by replacing $basePath+ with the actual base path for that theme. The server side code would then save those css files as theme1.css, theme2.css, ...etc.
You then could use url variables to switch between themes using some server side code to insert a reference to the correct css theme file.
This way you would only need to maintain your pseudo template css file. Although you would need to rerun your css creation code each time you change the template css file so that your theme css files get updated.
Not natively in CSS - but you can write some scripts to compile your theme CSS files from templates with variable substitution. I would suggest having a 'layout' and a 'colour' css. The layout would be consistent irrespective of which theme the user is using. The colour css contains only those settings that change per theme.
<style type="text/css">
#import ulr(layout.css);
#import ulr(theme_<?= $activeTheme ?>_.css);
</style>
You could use a tool such as http://lesscss.org/ (if you like Ruby) to create your themed CSS files.
We use NAnt for something similar to this (not CSS, but same idea), and it saves a heap of time rather than maintaining multiple files that differ only by values.