|
|
|
|
![]() ![]() |
Aug 11 2007, 08:41 AM
Post
#1
|
|
|
Premium Member Group: [HOSTED] Posts: 286 Joined: 17-June 07 Member No.: 22,702 |
Not being an HTML designer, but having a requirement to make a web page look pretty, I now have the following problem (I am absolutely convinced the solution for this must be very, very simple, I just need to find the right tutorial, which I couldn't find even after googling with the keywords outsource style section external CSS file):
I want to take an inline <style> ... stuff ... </style> section from a web page, create a CSS file out of it, then replace the inline style section with a reference to the CSS file. Take as an example the page you are reading now. How would I be able to accomplish that? I know it's a basic question and I'll keep researching the Internet as we speak, but if anyone has a quick solution to this, it's your chance to earn some hosting credits. |
|
|
|
Aug 11 2007, 08:50 AM
Post
#2
|
|
|
Premium Member Group: [HOSTED] Posts: 474 Joined: 5-November 06 Member No.: 17,016 |
All you need to search is "external css", all the answer will pop right out
I just briefly show you how to do it Create a plain text file with the css you wanted in it, then add this line to the HEAD section CODE <link href="path/to/your/css" rel="stylesheet" type="text/css"> Example content of css file CODE .header { background-image: url(../images/header-bg.png); background-repeat: no-repeat; border-left: 1px solid #FFF; border-right: 1px solid #000; border-top: 1px solid #FFF; padding-left: 30px; padding-top: 8px; height: 35px; } basically it's what ever within the STYLE tag. That's it. Next time when you google, don't put the search terms as a question, it won't really work. All you need is just the keyword Good Luck |
|
|
|
Aug 11 2007, 09:24 AM
Post
#3
|
|
|
Premium Member Group: [HOSTED] Posts: 286 Joined: 17-June 07 Member No.: 22,702 |
Works as advertised, thanks faulty.lee
|
|
|
|
Aug 11 2007, 10:27 AM
Post
#4
|
|
|
The Modernator Group: Members Posts: 486 Joined: 6-August 06 From: The Interweb! Member No.: 15,021 |
Css is soo powerfull!! you could spend ages looking at all the things it can do, a lot of designers these days (me included) try to do virtually everything on the page using CSS.
Also having your CSS checked by a validator at http://www.w3.org/ is a must for serious designers.This will point out anything in the CSS that is not a "correct" way of using a CSS command. You can also use this site http://www.cleancss.com/ to clean up and optimise your code. |
|
|
|
Aug 11 2007, 11:32 AM
Post
#5
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 998 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
then add this line to the HEAD section CODE <link href="path/to/your/css" rel="stylesheet" type="text/css"> It is good practice to close these tags with " />" instead of just ">", because this is required in XHTML. Another way to include an external stylesheet is to use the following code: CODE <style type="text/css" media="all"> @import url(style_images/css_2.css); </style> While it works the same way as the previous one in newer browsers, it will not function in older ones (e.g. Netscape 4). If you don't see it as being useful, think of it this way - browsers that don't support @import also don't support CSS to the extent necessary today. In order to avoid any possible errors, you should use <link> for basic CSS rules (font-family, font-color etc.) and @import for advance ones, which wouldn't be recognized by older browsers anyway. |
|
|
|
Aug 11 2007, 11:28 PM
Post
#6
|
|
|
Super Member Group: [HOSTED] Posts: 740 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 |
It is good practice to close these tags with " />" instead of just ">", because this is required in XHTML. Another way to include an external stylesheet is to use the following code: CODE <style type="text/css" media="all"> @import url(style_images/css_2.css); </style> While it works the same way as the previous one in newer browsers, it will not function in older ones (e.g. Netscape 4). If you don't see it as being useful, think of it this way - browsers that don't support @import also don't support CSS to the extent necessary today. In order to avoid any possible errors, you should use <link> for basic CSS rules (font-family, font-color etc.) and @import for advance ones, which wouldn't be recognized by older browsers anyway. Thanks for the information, the use of @import was one of the few things that i don't completely understand about css until now. Best regards, |
|
|
|
Aug 12 2007, 12:50 AM
Post
#7
|
|
|
Premium Member Group: [HOSTED] Posts: 474 Joined: 5-November 06 Member No.: 17,016 |
It is good practice to close these tags with " />" instead of just ">", because this is required in XHTML. Another way to include an external stylesheet is to use the following code: CODE <style type="text/css" media="all"> @import url(style_images/css_2.css); </style> While it works the same way as the previous one in newer browsers, it will not function in older ones (e.g. Netscape 4). If you don't see it as being useful, think of it this way - browsers that don't support @import also don't support CSS to the extent necessary today. In order to avoid any possible errors, you should use <link> for basic CSS rules (font-family, font-color etc.) and @import for advance ones, which wouldn't be recognized by older browsers anyway. I didn't notice bout the "/>", i simply copied from one of my project file. Hmm, meaning most of my project are not XHTML compliant. Thanks for the info. As for the @import, i seldom use advance CSS, and normally i target 1 specific browser only, mainly firefox, probably the same version, for simplicity. Thus everything should work as if it's photocopied. I don't deal with end user, i can ask my client to use what ever browser of my choice. One of the reason is security, and the other is shorter development time due to less issue with cross browser compatibility |
|
|
|
Aug 12 2007, 11:02 AM
Post
#8
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 998 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
I don't use @import, either, but it is a good thing to know. But let's face it - even without any precise data, I am quite sure 80 per cent of the Internet population uses newer browsers which deal with CSS rather well ("rather" is there because of IE
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 21st August 2008 - 10:35 PM |