Using HTML5 CSS in Eclipse - css

I am beginner in SAPUI5. I am building SAPUI5 application with HTML5 in Eclipse. In index.html page I am creating a html5 page, I have created css folder under WebContent. In index.html I added to refer css file. But properties in css are not affecting in html page. Do I need to add any other code to refer CSS file.
Css:
#CHARSET "ISO-8859-1";
body {
background-image: "image/splash-sunrise.jpg";
background-size: 100px 100px;
background-repeat:no-repeat;
}

To use CSS within the SAPUI5 environment you should link your controls to a specific CSS class. You can do it like this:
var myButton = new sap.m.Button();
myButton.addStyleClass("myButtonStyle");
And your CSS could look like this:
#CHARSET "ISO-8859-1";
.myButtonStyle {
color:#FFCCDD;
}
Make sure that you load the CSS file into your application, for example like this in your html file:
<link href="css/style.css" type="text/css" rel="stylesheet" />
Of course you can use this for your whole page as well. For your needs you could also take a look at the App control which provides some utilities for background images if you´re using mobile controls.

Related

How do I use relative filepaths for an image in a different folder from my CSS file?

I have a web page with the following folder structure:
MyWebpage
- css
- layout.css
- img
- wallpaper.jpg
- js
- index.html
I have the following line included in index.html
<link rel="stylesheet" type="text/css" href="css/layout.css">
Now, I want to use the image wallpaper.jpg as the background for the <body> element. How can I use relative referencing here? Should I locate the file relative to the CSS file, like this,
body {
background: url('../img/wallpaper.jpg');
}
or relative to the HTML file, like this?
body {
background: url('img/wallpaper.jpg');
}
It really depends on where you are writing your CSS.
If you are writing an inline style or using <head> <style> tags in the HTML file, then use a path relative to the HTML file (../ in this case), as you are telling browser to load the image from the HTML file.
And if you are writing the style in the CSS file, the style is relative to the CSS file destination (no ../ in this case), as you will load the CSS file from the HTML file and the CSS file will load all the required resources.

Thymeleaf URL expression in .css file

I'm using Spring MVC and the Thymeleaf view engine. I have an external style.css file with the CSS for my page. In the CSS file, I want to refer to a relative image URL.
This is my style.css file:
.background {
width: 100%;
background-image: url('/path/to/image/bg.png');
}
The above tries to access an image with the following URL, which doesn't exist:
http://localhost/path/to/image/bg.png
My real image is at:
http://localhost/myapp/path/to/image/bg.png
This StackOverflow question gives the answer to my question for inline CSS: How to set background url for css files in thymeleaf?
But how do I do this for an external .css file?
Put all your images folder structure with images path/to/image/bg.png inside the images folder under resources/static. Then refer to it in CSS as:
.background {
width: 100%;
background-image: url('../images/path/to/image/bg.png');
}
And then you can use this CSS in your templates as:
<head>
<link rel="stylesheet" media="screen" th:href="#{/css/application.css}"/>
</head>
Your files structure should look like this:

What is difference between external and internal css?

I watched a flex tutorial and I found parts mentionning external and internal css. So what is the differences between the two ?
External CSS refers to a file location, ie
<link rel="stylesheet" href="your-file-here.css">
Internal CSS
Means that the CSS is included on the page, wrapped in style tags in the <head>:
So:
<style>
#wrapper { width:960px; margin:0 auto; }
</style>
When internally using CSS, styles can be used in what is called inline styles.
Which looks like:
<p style="color: #333; font-size: 22px;">Blah blah blah.</p>
The only real benefit to internal CSS, is that the browser doesn't need to make an additional GET request to download the .css file. But external is preffered. As it means you just need to modify the .css file, and it will be reflected in all pages which include a reference to that specific file.
Internal CSS
Defined inside <style> elements.
Embedded directly inside the page.
External CSS
Linked via the <link rel="stylesheet"> element.
Exists as a seperate file on the server.
The main advantage of an external CSS file, is that it can be cached independently from pages, meaning that the client only needs to download it once, which saves on loading times and bandwidth.
Also, by linking many pages to once CSS file, you only need to change one place, and have all of the site immediately affected (without having to go on every page and make the change).
An internal style sheet is a style tag in the head section of the page:
<style type="text/css">
body { margin: 0; padding; 10px; }
</style>
An external style sheet is a CSS file that is used by the page from a link tag in the head section:
<link rel="stylesheet" href="pagestyles.css" />
An external style sheet can also be specificed using the #import CSS rule, either from an internal style sheet or another external style sheet:
#import "otherstyles.css";
There is also a third type of css; inline styles that are specified on the element that they apply to:
<div style="background:#ccc;">

Twitter Bootstrap classes(grids, navs) not rendering

So I have twitter bootstrap response in my app assets stylesheets, and it shows in the head of the document from Google Chrome's dev tools like so:
<link href="/assets/bootstrap-responsive.css?body=1" media="all" rel="stylesheet" type="text/css">
Yet when I use classes to try and make bootstrap buttons, use the grid system or the built-in nav, nothing happens. For instance, Here's how I tried to the gride system to work.
%h1 Your Polls
.dashboard-wrapper.row
.user-polls.span6
%h1 test
.create-polls.span6
= link_to 'Create New Poll', new_poll_path, remote: true
With this CSS:
.dashboard-wrapper{
margin-top: 50px;
}
.user-polls {
}
.create-polls{
}
Any ideas on why it might not be working?
Thanks!!
bootstrap-responsive.css is a small file containing responsive (phone/tablet) tweaks for the main bootstrap.css file. Did you include the main bootstrap.css file?

CSS not working in stylesheet

I have a set of Styles that were first created inside the style attribute on a page.
I want to move it from being on the page itself into a stylesheet.
however, when I move it to a .css file, the page breaks, move the code back to the html doc and it works fine again.
This makes absolutely no sense, moving styles from a style to a css file shouldnt break the code should it?
Am I missing something? I am not changing any of the code, its simply a copy and paste.
This is just a shot in the dark as (at the time of this post) you haven't provided source code.
Make sure you're linking to your stylesheet using a link tag in the head of the HTML document.
If you had:
<style type="text/css">
/* <![CDATA[ */
#someid
{
margin: 0;
padding: 3px 12px;
}
/* ]]> */
</style>
You'll need to have
#someid
{
margin: 0;
padding: 3px 12px;
}
in your CSS file with:
<link rel="stylesheet" type="text/css" href="path/to/style.css" />
to link to the stylesheet.
Some common newbie mistakes include:
<style type="text/css" src="path/to/style.css">: because it's a similar syntax to the <script> tag, which would make sense, but is invalid
<link rel="stylesheet" src="path/to/style.css">: but link elements use href not src
placing link elements within the body: although browsers will tend to manage link elements in the body, there are likely going to be some errors, and it's not a defined behavior
not specifying a doctype declaration: allows the browser to go into quirks mode, which is never a good idea.
You should make sure the stylesheet is properly imported.
Sometimes the #import doesn't work well if not used accordingly, so always reference your stylesheet:
<link rel="stylesheet" type="text/css" href="name-of-stylesheet.css" />
Always remember to close the <link> tag as it's a self-close tag. I think #zzzzBov forgot to mention that.
Finally, if that doesn't work, try to override some of the styles by physically writing (above the </head> section) something like:
<style type="text/css">
body { background: blue; }
* { color: red; }
</style>
and see if that gives you a blue background and red colored text. It should. After that, try to implement the referencing method and make sure you reference the stylesheet file to the right directory.
Good luck!
I had the same problem, but the cause was not some mistake in the code but the fact that the .css file was loaded with some delay after making the modifications in it. The server needed 5 - 10 minutes to update the changes.
I had this problem as well, and the reason was that the path had to be updated for some url() references since the css file was in another folder than the html file it previously was called from.
So basically
background-image: url('patterns/debut_dark.png');
had to be changed to
background-image: url('../patterns/debut_dark.png');
Don't include <style type="text/css"></style> in your .css file.
I had the same issue and was quite frustrating. I had a css file that was properly referenced, however not all the elements were being loaded from it. As it turns out, it was a cache problem in Chrome. After clearing it and restarting the window, the css elements were working correctly.
Ran across same problem. Found there were lines in my css file that should have been commented out (a block of colour palette information that I had cut and paste to the top of the file for quick reference).
If all your syntax seems fine, then its most likely a browser cache problem that we can easily fix. In your html/php file, reference your new .css style sheet (e.g. styles.css) by adding an extra random parameter. This will force browsers visiting your page to fetch your latest styles.css.
In the of your html/php file, you should have something like this to load your new styles.css file:
<link rel="stylesheet" type="text/css" href="styles.css" />
simply change it to be like this:
<link rel="stylesheet" type="text/css" href="styles.css?ref=v1" />
that extra "?ref=v1" will prevent browsers from re-using the styles.css file they have cached, and will force browsers to get your very latest styles.css file. As you make updates to the styles.css file and upload them to your web server, just change the "v1" to "v2" etc. or whatever naming system you like so that browsers are forced to reload the latest styles.css. Note adding this "?ref=v1" to the link does not need you to change the name of your styles.css file (you can change the file name but i find that gets messy). This is a simple and clean way to force browsers into re-fetching your very latest .css file.

Resources