wood burning stoves 2.0*
The moose likes Servlets and the fly likes CSS ???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "CSS ????" Watch "CSS ????" New topic
Author

CSS ????

verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
I am building a jsp site and decided to use CSS to format the pages. This is my first experience with CSS, so forgive me if this is a simple question. From what I have read, you should put the formatting definitions such as <B>, <font color="#DFDFDF">, etc into the CSS file. You should then be able to override the settings in the css by putting the formatting directly into your jsp file. Therefore, I am putting the formatting that will be used 99% of the time in the CSS. When I have a special case that needs special formatting, I put that special formatting directly into the jsp file. However, when I view the file, the special formatting is not recognized; it still uses the formatting defined in the CSS file. What do I need to do so that the formatting in the jsp file overrides what is defined in the CSS?
Thanks for your help.
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
The problem CSS is that it is very much browser dependent.
You can override global style definitions in your external CSS file by using the inline "style" attribute against particular tags.
eg.
say your global CSS definitions were:
<style ...>
h1 {
color:red;
font-size:15pt;
}
...
</style>
normally if you applied this style sheet to your HTML page, each <h1> tag would have red text of size 15pt.
To override this use the inline style attribute.
eg.
<h1 style="color:black;font-size:10pt;...">
Also note, if you mix "old-school" display formatting tags (<b>,<font>, etc) with CSS formatting you will get unpredictable results that will depend on your browser for how it will be rendered.
Hope this helps,
James.
verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
James,
Thanks for your reply. A couple follow - up questions:
1) "CSS is very much browser dependent." For the time being, our site will be on IE5. In the future, we will also support Netscape. What types of differences are there? Would I be safer to use "old school" formatting instead of css? What should I look out for in this case of supporting two browsers?
2) Where do I put the inline style attribute? Immediately before I want to change it? What do I do to revert back to the css definition after my one special case?
Thanks for your help.
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Verduka,
1)
The type of differences are shown here http://www.webreview2.com/style/mastergrid.shtml
I guess try to keep things simple, use "safe" tags (eg. <div>, <span> ) that have CSS properties well supported by different browsers.
A common approach, is to use browser detection at the client or server and then determine if you will apply your CSS or not.
eg. if (http_user_agent is IE5.x) {
use nice CSS formatting;
} else {
revert to "old-school" formatting;
}
Sorry this doesn't answer all of your questions, but this is a large topic, there are plenty of resources on the Internet that discuss this in more detail.

My advice is to try things out for yourself, have a couple of different browsers installed on your workstation, see what works and what doesn't.
2)
The inline style attribute only applies to the tag it was defined in, so in the example I gave, if you used another <h1> tag with no "style" attribute it would default to using the global styles set up in the CSS file.
This is can be a rather large topic on how "cascading" of style sheets is applied.
James.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CSS ????
 
Similar Threads
include directive doubt
JSP/Servlet combination
Struts JSP J2EE Security
confusion on struts tile
Problem in using javascript in spring web mvc system: