Closed Thread
Results 1 to 7 of 7

Thread: Programming confusion

  1. #1
    Tyger's Avatar
    Tyger is offline Newbie
    Join Date
    Nov 2007
    Location
    USA
    Posts
    2
    Rep Power
    0

    Programming confusion

    alright, first off, I wasn't sure which forum to put this in. And since it's my first post I apologize if it's in the wrong place.

    I'm building a website, and I know how to use html and css but this is the first site I'm building from scratch. I'm not using dreamweaver, or any software like that. I'm not sure how to use the css in with the html, I tried reading and figure it out but I'm still confused.

    The summary is (for those who don't understand my rambling) the whole what goes where and how to put the css onto the page is what's confusing me. despite knowing html and css.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    Generally there are three ways you can use CSS:
    1) A separate file
    2) Defined in the <head> of your html file
    3) As a tag attribute

    I the third method is going to be depreciated in future versions of XHTML - I'm not sure which method you are asking about, since you want to use "css in with the html" I'm going to assume you mean the third method.

    Most tags accept a style attribute, that style allows you to define the style using CSS for that particular element. Example:

    [highlight="html4strict"]
    <img src="../image.png" style="border: 1px solid" />
    [/highlight]

  4. #3
    ETbyrne's Avatar
    ETbyrne is offline Learning Programmer
    Join Date
    Nov 2007
    Location
    Lapeer, MI
    Posts
    30
    Rep Power
    0
    The best method is to create a file for the CSS and then link to it in the <head> tags. Like so...

    Code:
    <head>
    <link rel="stylesheet" href="styles.css" type="text/css" />
    </head>
    This is assuming the file with your CSS in it is called styles.css
    Whatever the name of your CSS file is it must have the file extension .css

  5. #4
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Quote Originally Posted by ETbyrne View Post
    The best method is to create a file for the CSS and then link to it in the <head> tags. Like so...

    Code:
    <head>
    <link rel="stylesheet" href="styles.css" type="text/css" />
    </head>
    This is assuming the file with your CSS in it is called styles.css
    Whatever the name of your CSS file is it must have the file extension .css
    Yup, that will even help in future website editing, because if you modify that external file the whole website will be modified.. That's why I love CSS.

  6. #5
    Join Date
    Nov 2007
    Posts
    20
    Rep Power
    0
    Like they said, you can put it in as an: Internal or External Style Sheet, or insert the style tag.

    Here's and example of Internal style sheets.

    HTML Code:
    <html>
    <!-- Internal Style Sheets go in the head tag -->
    <head>
    
    <style type="text/css">
    body {
      background-color:#000000;
    }
    </style>
    
    </head>
    </html>
    It's a bad example, but you should get the idea.

    Here's an example of External Style Sheets:

    This is the HTML

    HTML Code:
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="Source" />
    </head>
    </html>
    Now here's the CSS

    Code:
    body {
      background-color:#000000;
    }
    External Style Sheets are in seperate documents, with the .css extention.

    Now here's an example of inserting the style tag:

    HTML Code:
    <html>
    <body>
    
    <div style="width:200px; height:200px; border:1px solid #000000; position:absolute; left:400px; top:150px;">
    
    </div>
    
    </body>
    </html>
    External Style Sheets are the easiest to read, and maintain, next would be Internal Style Sheets, and lastly inserting the style tag.

    Hope it helps, Thanks, Death

  7. #6
    DevilsCharm's Avatar
    DevilsCharm is offline Programming God
    Join Date
    Jul 2006
    Posts
    884
    Rep Power
    0
    Interesting how there are so many ways to output the same result.

  8. #7
    Join Date
    Nov 2007
    Posts
    20
    Rep Power
    0
    Yes that's both good, and bad. Good because it's not that hard to use, and get the desired output, but bad because:

    1. The W3C created CSS to seperate structure(HTML) from style(CSS).
    2. Making your CSS Internal/Inserting it with the style tag defeats what the W3C is trying to do. The reason I say this is because it makes the content of your head element extremely messy. Even with endentions, it's just sloppy there's no foundation or organization to using it. Using the style tag is even worse. Your doing exactly what the W3C worked so hard to get rid of.......putting structure with the style of the page.
    3. Your more prone to mistakes by using them, because they are so munched together.

    External style sheets are the best hands down, you're able to organize them by there file name. For example:

    Say you wanted a black border around a white page, you can do it like this:

    HTML Code:
    <html>
    
    <head>
    <style type="text/css">
    
    body {
      background-color:#ffffff;
    }
    
    .main {
      width:100%;
      height:100%;
      border:1px solid #000000;
    }
    
    </stlye>
    </head>
    
    <body>
    <div class="main">
    </div>
    </body>
    
    </html>
    or do this:

    Code:
    <head>
    <link rel="stylesheet" href="Main.css" />
    </head>
    and then put the CSS in another document, named Main.css

    It's cleaner easier to edit, and saves you time and headaches.


    - Death

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Confusion with 2D array
    By matija in forum Python
    Replies: 5
    Last Post: 04-07-2011, 04:28 AM
  2. string in C: confusion
    By elvira23 in forum C and C++
    Replies: 12
    Last Post: 09-25-2009, 11:11 AM
  3. little confusion in C
    By wwwildbill in forum C and C++
    Replies: 2
    Last Post: 02-17-2009, 09:19 PM
  4. sizeof operator confusion..
    By novice in forum C and C++
    Replies: 1
    Last Post: 12-05-2008, 07:03 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts