I would like to use a CSS file in an HTML page passed on to ui.WebView.load_html but I cannot figure out which filename to use. The simple assumption that the filename should be relative to the location of the Python script calling the method does not seem to work, e.g <html><link rel="stylesheet" type="text/css" href="etc/styles.css"><body><p id="content">TO BE FILLED</p></body></html> with styles.css located in the etc sub directory of my script directory does not work. If I use the CSS definitions inline, such as <html><style>...</style></html>, they work fine.
Any idea? Thanks a lot!
Forum Archive
Which filename to use for a local CSS file?
marcus67
Dec 30, 2015 - 01:51
tomkirn
Dec 30, 2015 - 08:30
Hi,
I tried this as well and had to use absolute paths to get it work. I dont get happy with relative paths at all.
BR Tom
JonB
Dec 31, 2015 - 07:02
If you used load_url instead of load_html, relative paths work. Although not well documented, load_url works with an abspath(i.e, without the need for file://)
load_html has no concept of your url, so of course relative paths do not work.
You could also should be able to use a <base> HTML tag inside the
marcus67
Jan 14, 2016 - 00:56
@JonB I changed the loading as you suggested and it works! Thanks a lot!