I have a Django/Python application and I want to use semantic UI in my views. I'm importing semantic using the CDN link, so my base HTML file has the following header...
<head>
...
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui#2.4.2/dist/semantic.min.css">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght#300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{% static "styles.css" %}">
...
</head
As you may see I want to load google fonts. However, all semantic UI elements seem to use the Lato, 'Helvetica Neue', Arial, Helvetica, sans-serif font by default and this is difficult to override.
All the advice I've seen online tells me to "customize the site.variables file". But where is this site.variables file? Is it something that I make, and if so, where do I put it so Semantic UI can detect it?
UPDATE: This is my CSS
html {
font-family: 'Montserrat', sans-serif;
}
Error here.
href="{% static "styles.css" %}"
Should be href="{% static 'AppName/styles.css' %}".
You can't you double quotes inside double quotes.
You may also like to use django-semantic-ui
Related
I have my HTML file which links to the CSS and it is working fine
<link rel="stylesheet" href="{% static '/Website/css/bootstrap.min.css' %}" />
<link rel="stylesheet" href="{% static '/Website/css/style.css' %}" />
<link rel="stylesheet" href="{% static '/Website/css/ionicons.min.css' %}" />
<link rel="stylesheet" href="{% static '/Website/css/font-awesome.min.css' %}" />e here
Then I have several images in the HTML file which are loading fine
<link rel="shortcut icon" type="image/png" href="{% static '/Website/images/fav.png' %}"/>
One div element id <div id="lp-register"> obviously links to above style.css selector as per below
#lp-register{
background: linear-gradient(to right, rgba(0,0,0, 0.7) , rgba(0,0,0, 0)), url('../images/test.png') fixed no-repeat;
background-size: cover;
background-position: center;
position: absolute;
top: 0;
width: 100%;
min-height: 100vh;
}
the images are in the static folder structured as this
static
- images
- test.png
and the setting.py has the correct static file definition
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
When I load the HTML page that particular image is not being loaded, and no error I see in the Django server, furthermore if I inspect the element I see that url('../images/test.png') remain with the old settings
linear-gradient(to right, rgba(0,0,0, 0.7) , rgba(0,0,0, 0.7)), url("http://placehold.it/1920x1280") fixed no-repeat
and does not change no matter what. In addition to that if I inspect the element and modify the settings manually to
linear-gradient(to right, rgba(0,0,0, 0.7) , rgba(0,0,0, 0)), url('../images/test.png') fixed no-repeat
which is what I want, seems that is working fine but when I change it in CSS does not
Can anybody help please?
{% load static%} in your HTML and then load the stylesheet.
You have set the static files in the settings.py the correct way, I think this should work.
url('../images/test.png') for this kind of linking in CSS we have to use this way to call these static files
url('{% static 'images/test.png' %}')
Its weird but I removed everything in the css file, the website still shows all the colours and stuff. I dont know what happened so I need t ask for help.
here is the main html:
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="css/animate.min.css" rel="stylesheet">
<link href="css/bootstrap-dropdownhover.min.css" rel="stylesheet">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
</head>
the style sheet:
(yes its literally nothing)
I'm running flask and I dont know whats happening so..
also the screenshot for the webiste when I put all the styles in:
would be happy if anyone can help me get past this part
Likely, your browser is caching the CSS. If you are in Google Chrome, a longer-term solution while developing is to open the DevTools (Ctrl+Shft+I), go to Network/Disable Cache and then hit the "open to new window" button so you can minimise it.
I'm trying to load an image to my page and set it as my background, below is the css and html that I am working with. The CSS page seems to load, as my test font and background colors show up but for whatever reason my background image doesn't.
I am using Django as my web framework.
Appreciate the help!
HTML:
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<title>Test</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="{% static 'personal/css/frontpagebackground.css' %}" type = "text/css"/>
</head>
<body>
<p>This is a test</p>
</body>
</html>
CSS:
body
{
background-image:url(personal/static/personal/img/home.jpg) no-repeat;
background-repeat:no-repeat;
background-size:100%;
background-color: green;
min-height: 100%;
}
p {
font-style: italic;
color: red;
}
You used background-image, so the no-repeat is not actually working. Try adding the no-repeat below as background-repeat: no-repeat;.
background-image: url('image-url-here.png');
background-repeat: no-repeat;
I've had problems like this with django, primarily because my {% static %} location was confusing me. I think this is a non-css issue, and a path issue.
It helped me to use the dev console to check for Resource Failed To Load error. It will spit out the path that the machine is looking for, and it's likely different than what you specified.
I.e. is your css file located along
personal/static/personal/img/home.jpg
relative to your css file? You might just need to back up a directory, i.e.
../personal/static/personal/img/home.jpg
Either way, the console should give you your path, and use that to determine where your CSS file is digging for the image.
If your CSS files are in a path such as /static/css/style.css
and the images are under a path such as /static/images/test.jpg
then you have to place the test.jpg image directly in the folder with the style.css i.e. /static/css/test.jpg and in your HTML file give it the name test.jpg without using the static path i.e. background-image:url('test.jpg');:)
Folder Blueprint
Templates
File.html
Static
Fonts
Style
In the css file , i tried :
#font-face{
font-family:<Font_name>
src:{{ url_for('static',filename='fonts/<font_name>.ttf') }} ;
}
What changes are to be made to add custom fonts ?
You can't use template tags in css. the Jinja template tags are only meant for html files and templates not css.
To use a css file, you have to insert the link manually there, something along the lines of:
#font-face{
font-family: customfont;
src: /static/Fonts/font.ttf';
}
The only way to get around this is to serve a template, that contains the css embedded in <style></style> tags that way flask would be able to interprete the template tags. so with that you should have something like this
<style>
#font-face{
font-family: <Font_name>
src: {{ url_for('static',filename='fonts/<font_name>.ttf') }} ;
}
</style>
Assuming your project directory is setup such (Arrows = level of directories):
~/
>static/
>>fonts/
>>>MyFont.woff
>templates/
>>index.html
>main.py
the following implementation of a fontface in your index.html's style tag should work:
<html>
<head>
<style>
#font-face {
font-family: "MyFont";
src: url("/static/fonts/MyFont.woff");
}
</style>
</head>
</html>
I have been trying to style bokeh widgets with a css file in flask that I modified from the gapminder demo. In particular, I am currently trying to style the dropdown, tab and slider widgets without much progress. I was able to style the tooltips using the gapminder css example, but would ultimately like to know if there are other examples or, even better, a listing of all of the bokeh style options (i.e. .bk-... styles). I'm not sure if this should work properly, as I'm still learning web dev, by my current index.html file in flask looks like:
<html>
<head>
<link
href="https://cdn.bokeh.org/bokeh/release/bokeh-0.12.1.min.css"
rel="stylesheet" type="text/css">
<link
href="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.1.min.css"
rel="stylesheet" type="text/css">
<link
rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles/gapminder.css') }}">
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-0.12.1.min.js"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.1.min.js"></script>
{{ script | safe }}
</head>
<body>
<div class=page>
{{ div | safe }}
</div>
</body>
</html>
Thanks in advance for the help.
Not sure if you are still searching for a response, but here is what I have done to adress this issue.
<style>
{% include 'styles.css' %}
.bk-root .bk-toolbar-right .bk-button-bar-list .bk-toolbar-button:hover .bk-tip {
color: #5DADE2;
}
.bk-root .bk-slider-parent input[type="text"]{
color: #FDFEFE;
}
</style>
It is quite manual, in that I first generated the bokeh plots, inspected the widget elements i wanted to change then simply added this into the index.html file. If you want to see which attributes you can edit, just inspect them and you will see them there.
For this example i changed the color of the tool names when you hover on them and also the slider value color.
I also had a seperate .css file which i included, so you could move it all in there.