School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 306,971 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,847 people online right now. Registration is fast and FREE... Join Now!




Inline CSS in HTML Website

 

Inline CSS in HTML Website

pyr0b0y

5 Nov, 2009 - 07:56 PM
Post #1

New D.I.C Head
*

Joined: 22 Feb, 2009
Posts: 30



Thanked: 1 times
My Contributions
I'm working on my first website using HTML for all of the content, and postion, color, etc are being done with inline CSS. For my homepage, I defined the background image and positioned it as well with the <style> tag. I have no problem opening my site in Safari, but the webpage will not open in any other browser, not even Firefox. Can someone please point me in the right direction? Thanks

CODE
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to David Copello Woodworks</title>
<style media="screen" type="text/css">
body
{
    background:
    url('../Images/Header.jpg') no-repeat 125px 1px,
    url('../Images/Wood_Background_Word.jpg') no-repeat 125px 280px,
    url('../Images/Wood_Background_1.jpg') no-repeat 125px 800px;
    background-color:black;
}
</style>
</head>
{
<div style="position: absolute; top:216px; left:130px;">
    <a href="../Webpages/Homepage.html">
        <img src="../Images/Home_Tab.jpg" alt="" width="94" height="60" />        
    </a>
</div>

<div style="position: absolute; top:216px; left:260px;">
    <a href="../Webpages/Products & Services.html">
        <img src="../Images/Products_Tab.jpg" alt="" width="263" height="60" />    
    </a>
</div>

<div style="position: absolute; top:216px; left:550px;">
    <a href="../Webpages/About Us.html">
        <img src="../Images/About_Tab.jpg" alt="" width="150" height="60" />    
    </a>
</div>

<div style="position: absolute; top:215px; left:730px;">
    <a href="../Webpages/Contact Us.html">
        <img src="../Images/Contact_Tab.jpg" alt="" width="150" height="60" />    
    </a>
</div>
}

<body>

<a href="http://www.google.com" style="position:absolute; color:black; top:1400px; left:1200px;">Google</a>
</body>
</html>



Attached File(s)
Attached File  Homepage.html ( 1.53k ) Number of downloads: 13

User is offlineProfile CardPM
+Quote Post


ravish012

RE: Inline CSS In HTML Website

5 Nov, 2009 - 11:05 PM
Post #2

New D.I.C Head
*

Joined: 5 Nov, 2009
Posts: 3



Thanked: 1 times
My Contributions
Hi,
Try having a seperate CSS file cuz its easier to read the code then... just try the following n see if it works

1. watch out for { } u might wanna remove them in a few places.
2. check <body> declaration
3. check image paths
4. Try creating a separate CSS file for better viewing

If possible post a screenshot of how ur page looks in safari.
User is offlineProfile CardPM
+Quote Post

sam_benne

RE: Inline CSS In HTML Website

6 Nov, 2009 - 03:57 AM
Post #3

D.I.C Addict
Group Icon

Joined: 16 Jan, 2008
Posts: 645



Thanked: 8 times
Dream Kudos: 400
My Contributions
Its best to use an external CSS file as this can edit all pages that are connected to it plus it makes life easier.
User is offlineProfile CardPM
+Quote Post

pyr0b0y

RE: Inline CSS In HTML Website

6 Nov, 2009 - 10:16 PM
Post #4

New D.I.C Head
*

Joined: 22 Feb, 2009
Posts: 30



Thanked: 1 times
My Contributions
I'm having trouble figuring out how to write an external CSS file because the position isnt for the whole page, its for indiviual pics on the page. Can you please provide an example or a good website? Here is a screenshot of what the homepage looks like in safari:

IPB Image

This post has been edited by pyr0b0y: 6 Nov, 2009 - 10:17 PM


Attached thumbnail(s)
Attached Image Attached Image
User is offlineProfile CardPM
+Quote Post

sam_benne

RE: Inline CSS In HTML Website

7 Nov, 2009 - 12:48 AM
Post #5

D.I.C Addict
Group Icon

Joined: 16 Jan, 2008
Posts: 645



Thanked: 8 times
Dream Kudos: 400
My Contributions
External css is just CSS in a CSS file you can then use the link rel tag to include it to your page in the header.
User is offlineProfile CardPM
+Quote Post

moopet

RE: Inline CSS In HTML Website

7 Nov, 2009 - 12:51 AM
Post #6

D.I.C Regular
***

Joined: 2 Apr, 2009
Posts: 348



Thanked: 34 times
My Contributions
QUOTE(pyr0b0y @ 7 Nov, 2009 - 05:16 AM) *

I'm having trouble figuring out how to write an external CSS file because the position isnt for the whole page, its for indiviual pics on the page. Can you please provide an example or a good website? Here is a screenshot of what the homepage looks like in safari:

IPB Image


You need to get rid of the {} in the HTML. I'm assuming you don't want them displayed on the page? They're (in your case) only for style blocks.

See the bit you have in STYLE tags?
CODE
<style media="screen" type="text/css">
body
{
    background:
    url('../Images/Header.jpg') no-repeat 125px 1px,
    url('../Images/Wood_Background_Word.jpg') no-repeat 125px 280px,
    url('../Images/Wood_Background_1.jpg') no-repeat 125px 800px;
    background-color:black;
}
</style>

Put that into its own .css file. Remove the style tags:
CODE

body
{
    background:
    url('../Images/Header.jpg') no-repeat 125px 1px,
    url('../Images/Wood_Background_Word.jpg') no-repeat 125px 280px,
    url('../Images/Wood_Background_1.jpg') no-repeat 125px 800px;
    background-color:black;
}

Link to it from your HTML page with (in the head section):
CODE

<link rel="stylesheet" media="screen,projection" type="text/css" href="YOUR_FILENAME_HERE.css" />


That will start you on the road to separating style from content. Now, to target a particular element, use classes or ids - the former represents a group of elements, the latter a single one. In your case it doesn't matter a lot, just don't use the same id more than once. Classes are indicated in stylesheets using a dot (.) and ids are indicated using a hash (#). I'll let you google or ask more about that later, but here's an example of what you could do.
In the HTML, add an id to an element you previously used inline styles for:
CODE

<div style="position: absolute; top:216px; left:130px;">

becomes:
CODE

<div id="fred">

In the stylesheet, add:
CODE

div#fred
{
    position: absolute;
    top:216px;
    left:130px;
}


As to why your page doesn't work in different browsers, it would be helpful if you could point us to a hosted copy, where the images are available. It's fairly trivial to use a plugin such as firebug in firefox to tweak styles on the fly. I believe safari has a similar feature but I've not played with it beyond saying "ewww" once or twice.
User is offlineProfile CardPM
+Quote Post

pyr0b0y

RE: Inline CSS In HTML Website

11 Nov, 2009 - 09:09 PM
Post #7

New D.I.C Head
*

Joined: 22 Feb, 2009
Posts: 30



Thanked: 1 times
My Contributions
Thanks for the help, I managed to write my CSS in another file and link it in the HTML. Using I have no problem and it's a lot easier to rewrite changes in CSS. I'm still having the problem of IE and Firefox not displaying as Safari does. Here are the pics of what my homepage looks like in IE and Firefox. (They both display the same webpage)

IPB Image

This post has been edited by pyr0b0y: 11 Nov, 2009 - 09:10 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 04:52AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month