Forum Moderators: not2easy

Message Too Old, No Replies

Problem with CSS in an applied template

CSS looks different when template is applied to a new html page

         

meak

5:54 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



HI guys,

Maybe someone can help me with this problem...

Basically I have been trying to create a template for HTML pages using CSS.

I have created a style sheet, and linked it to the template, and everything looks exactly how i want it to.

The problem comes when I come to apply the template to a new HTML page. When I preview the new HTML page (with template applied) it looks like the CSS goes wonky and some of the divisions have moved.

It's really frustrating because the template looks perfect, but when it is applied to a new page, it goes wrong.

The styles and colours are all there but the css boxes have just moved.

I checked the code between the HTML page and the original template and the coding is exactly the same apart from the very top line which says

[ <!-- InstanceBegin template="/Templates/Basic.dwt" codeOutsideHTMLIsLocked="false" --><!DOCTYPE HTML PUBLIC> ]

as opposed to

[<!DOCTYPE HTML PUBLIC>]

on the template page.

Any help would be really greatly appreciated! this is driving me mad!

Meak

Lance

5:57 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



Just a guess.

If this is in IE6, and IE6 is in compliant mode because of the!DOCTYPE statement, then having a comment before the!DOCTYPE will switch IE6 back to quirks mode which may render differently.

meak

5:58 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



maybe if you have a look, you will see what i mean

the template is here <snip>
and the html page is here <snip>

as you can see, in the test.htm page, the right hand menu has dropped, for no apparent reason, when it is fine in the template!

(PS, all the existing pages on my site are coded separately, which is why i'm trying to create this template)

[edited by: SuzyUK at 4:29 pm (utc) on Aug. 20, 2004]
[edit reason] oops no URLS per TOS #13 [webmasterworld.com] [/edit]

dan121

8:39 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



like what lance said,

change
<!-- InstanceBegin template="/Templates/Basic.dwt" codeOutsideHTMLIsLocked="false" --><!DOCTYPE HTML PUBLIC>

to just

<!DOCTYPE HTML PUBLIC>

createErrorMsg

1:33 am on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is definitely the DOCTYPE. I saved the page, removed the stuff before the DOCTYPE and loaded it locally in Firefox and it displays fine. Without the DOCTYPE first, FF kicks into quirks and botches the box model.

Incidentally, your doctype, while not technically invalid, is missing some information. Go here, [w3.org...] for the full list of valid doctypes.

meak

9:13 am on Aug 20, 2004 (gmt 0)

10+ Year Member



Thanks guys,

you are aright.
Removing the gumpf from the doctype line does work.

HOWEVER... the only way to do this is to detach the html from the template... thus rendering the template useless.

Is there any way to change it without detaching from the template?

And which doctype heading should i have?

jetboy_70

9:22 am on Aug 20, 2004 (gmt 0)

10+ Year Member



Try manually moving the template comment from the start of the file to after the <html> tag. Also move the closing one to before the closing </html> tag.

Are these comments in the template itself? If so, make the changes there, preferably in a text editor as opposed to Dreamweaver itself.

meak

9:44 am on Aug 20, 2004 (gmt 0)

10+ Year Member



Nope, that doesn't work for me.

The problem is when Dreamweaver applies the template to the new html page.... it also adds the extra code

<!-- InstanceBegin template="/Templates/Basic.dwt" codeOutsideHTMLIsLocked="true" --><!DOCTYPE HTML PUBLIC>

when i only want it to say

<!DOCTYPE HTML PUBLIC>

how do i go about stopping dreamweaver doing this?

jetboy_70

10:03 am on Aug 20, 2004 (gmt 0)

10+ Year Member



The comment is how Dreamweaver links the page to the template. Remove it and it stops being linked. You know this anyway though.

On Ultradev the comments are applied inside the <html> element by default. I assume you are using a later version?

meak

10:05 am on Aug 20, 2004 (gmt 0)

10+ Year Member



i have dreamweaver MX, the most recent version.

I know that the comment links to the template.... but surely something is wrong here, seeing as the template is not displayed properly when linked to.

jetboy_70

10:08 am on Aug 20, 2004 (gmt 0)

10+ Year Member



Of course it would help if you had an opening <html> tag to begin with ...

... and read the page that createErrorMsg linked to.

meak

12:52 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



thanks to all those who replied...

I have solved the problem now!

I needed to insert the following into the <head> tag

<!--Templateinfo codeOutsideHTMLIsLocked="true" -->

and now it works!

meak

12:53 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



i do have an html tag!

<!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">

encyclo

1:03 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], meak. You might want to review the terms of service [webmasterworld.com] for the forum, especially the part about putting links to your site. ;)

You seem to have found the solution, but having looked at your site anyway, the doctype you have chosen is inappropriate for the style of markup you are using in the rest of the document. I would recommend using the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

For the HTML tag, you won't need the xmlns attribute if you use the above doctype, but you should declare the language of the document there instead, which will help search-engine bots and screenreaders identify the language appropriately (I assume the document will be in English):

<html lang="en">

meak

1:52 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



thanks for that... i've changed it now.

sorry about linking to my site.... i just thought it might be the only way to show people what i meant!

createErrorMsg

2:14 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not VERY familiar with DW, but I believe there is an option somewhere (File menu, most likely) that allows you to Export without template tags. If I were you, I would get the page how you want with the template, then once the site is done, export a template tag-less version to upload to your server. If you need to make site wide changes, just change the template version still stored on your local machine and RE-export without the tags for upload. This way you cut down on the DW "tag soup" by removing the template tags from the pages your users actually see.

And you should consider moving the style information out of the markup and into an external stylesheet. It speeds up the page and makes changing/tweaking your layout MUCH easier. DW MX may even have a way of automating this for you.

meak

4:07 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



Cheers for that

It's all soretd and I don't want to even touch it again in case it goes wrong!

I already have a whole external style sheet, so I'm not sure which style markup you are referring to>?

createErrorMsg

4:23 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



not sure which style markup you are referring to

Your code is littered with inline style attributes. In fact, in order to see how the pieces of the site are positioned, requires flipping back and forth between the external stylesheet and the source code where the inline styles are. A minor nuisance for me, looking over your code, but a potential headache for you when the day comes that you want to make layout changes to your site. Keeping it ALL in one place makes for easier updates.

meak

11:35 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



any chance you could advise me on how to combine the whole lot into one style sheet?

i'm new to css, and thought that this was a pretty good first effort

createErrorMsg

1:11 am on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thought that this was a pretty good first effort

Don't misunderstand me! This is all meant as constructive, not destructive critisism. Your site does look good, and most of what is 'wonky' about the CSS looks like trademark DW tagsoup (stuff DW did without you necessarily knowing it). I suspect all of those inline styles were added by DW in response to point-and-click choices you made in Design View. Since the site is working fine, you may not want to go in and clean things up. but if you DO, here's a way to start.

Open your external stylesheet in a text editor and have it ready to go. Then open the source code for the document and zero in on the main <div>s of your page. Any of those <div>s that have style="WHATEVER" in the tag, you want to move that style info into the external stylesheet. So find the stylesheet selector that matches the <div> and copy the style information, in proper CSS format, into the stylesheet. (If the <div> already has an entry in the stylesheet, simply add the inline rules to the existing rule declaration. If there isn't already an entry, make one.)

So, say you find this in the source code...

<div id="main" style="float:left; width:200px; margin:0;">

...in the stylesheet, this becomes...

#main {
float: left;
width: 200px;
margin: 0;
}

...and the <div> tag should be edited to this...

<div id="main">

You can see how much cleaner that looks, which is one of the main reasons doing this is worthwhile.

Once you've got the main <div>s pared down, then move on to smaller, more specific elements until all of the style info is out of the source code and squirreled happily away in the stylesheet.

Bear in mind that this is only a suggestion. Some people are extremely anal about using ONLY external stylesheets and keeping the html code clean. I happen to be one of them, but that doesn't make it the right way, just a way.

Great job and congratulations on your first CSS site!
:)

meak

11:25 am on Aug 21, 2004 (gmt 0)

10+ Year Member



ooof... OK, i see what you mean! I also like clean html, but I think I might leave it for another day.... looks like a big job!

thankx for the advise though, it is much appreciated!

bjones

10:21 pm on Feb 24, 2008 (gmt 0)

10+ Year Member



I have a similar question to this issue. I have created a webpage template using CSS in Dreamweaver MX3. When I create a new page using the template everything looks fine, however if I make any changes to the template the following comments

<!-- InstanceBegin template="/Templates/main_index.dwt" codeOutsideHTMLIsLocked="false" -->

are placed in the very top line above

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

How do I eliminate this from happening so that my CSS does not mess up?

SuzyUK

10:57 pm on Feb 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld bjones..

while I understand your question, in that you need nothing to appear before the Doctype because of Quirks Mode rendering - I can honestly say I don't know how to achieve that with DW, as far as I know, once you have set up your basic template, then it should be only defined areas that are instance editable, which means that your pre <doctype> section need never be touched..

note my past tense, I only tried it a few times, so cannot give you the best advice

I will ask around the forums to see if we can find you a better answer.. or perhaps you might be better asking in WYSIWYG [webmasterworld.com] forum.. those guys know their editors and can perhaps help you better how set it up for your needs

-Suzy

rolandsea

4:40 am on May 6, 2008 (gmt 0)

10+ Year Member



To solve the Dreamweaver issue I believe you need to edit the .dwt file. Find the "TemplateInfo codeOutsideHTMLIsLocked=""" commented section and make sure it is in the <head> tag. This should place it after the DOCTYPE declaration. Hope this helps.