Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Outsourcing A Style Section To An External Css File
dserban
post Aug 11 2007, 08:41 AM
Post #1


Premium Member
Group Icon

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.
Go to the top of the page
 
+Quote Post
faulty.lee
post Aug 11 2007, 08:50 AM
Post #2


Premium Member
Group Icon

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
Go to the top of the page
 
+Quote Post
dserban
post Aug 11 2007, 09:24 AM
Post #3


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
Member No.: 22,702



Works as advertised, thanks faulty.lee
Go to the top of the page
 
+Quote Post
Mark420
post Aug 11 2007, 10:27 AM
Post #4


The Modernator
Group Icon

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.
Go to the top of the page
 
+Quote Post
pyost
post Aug 11 2007, 11:32 AM
Post #5


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 998
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



QUOTE(faulty.lee @ Aug 11 2007, 10:50 AM) *
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.
Go to the top of the page
 
+Quote Post
TavoxPeru
post Aug 11 2007, 11:28 PM
Post #6


Super Member
Group Icon

Group: [HOSTED]
Posts: 740
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



QUOTE(pyost @ Aug 11 2007, 06:32 AM) *
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,
Go to the top of the page
 
+Quote Post
faulty.lee
post Aug 12 2007, 12:50 AM
Post #7


Premium Member
Group Icon

Group: [HOSTED]
Posts: 474
Joined: 5-November 06
Member No.: 17,016



QUOTE(pyost @ Aug 11 2007, 07:32 PM) *
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
Go to the top of the page
 
+Quote Post
pyost
post Aug 12 2007, 11:02 AM
Post #8


Nenad Bozidarevic
Group Icon

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 smile.gif)
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How Do I Make A RPG Battle System?(13)
  2. Php Script To Download File From Another Site(9)
  3. How Can I Open A *.sit File(10)
  4. Shut Down, Restart, Log Off XP Using A Batch File(23)
  5. How Do I Compress One File Into Several Parts?(10)
  6. How To Save A Image In Pdf File And Download It?(10)
  7. Recover Tables From A MySQL .frm File(8)
  8. FTP Or File Manager - Which Is Better?(37)
  9. How To Increase Windows Shutdown Speed(39)
  10. Text File Operations VB.NET(5)
  11. Restore Windows File And Folder Protection(4)
  12. What Is Mkv? Need Help With This File Format?(6)
  13. Uploading Image File Through JSP Code To Server(9)
  14. Deleting A Corrupt File(25)
  15. Need Help Urgently (missing Or Corrupt Hal.dll File).(6)
  1. Loading External Actionscript(3)
  2. Messed Up My Boot.ini File With Vista...(13)
  3. Extplorer(7)
  4. Is A Php File Searchable?(8)
  5. Problem With Move_uploaded_file()(5)
  6. Safari And Hosts File(8)
  7. Use Of Xml Properties File For One Key - Multiple Value Mapping(0)
  8. How To Copy File & Folders From Linux To Windows?.(12)
  9. Linux Basic Command - For Storing Compilation Error To File(1)
  10. Need To Edit A Wav File [solved](1)
  11. Re-ordering Welcome Screen & Moving Heavily Fragmented File(1)
  12. Style P And H? Html Tags(2)
  13. Mysql And User File_priv(0)


 



- Lo-Fi Version Time is now: 21st August 2008 - 10:35 PM