...

View Full Version : Adding CSS to ASP?



SteveH
07-08-2008, 01:58 PM
Hello

I am trying to format the output of this ASP file:

<%@ Language="VBScript" %>
<html>
<head>
<title>RSS Reader</title>

</head>
<body>
<%
If DateDiff("h", Application("rss-html-time"), Now()) >= 2 then

Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True

xmlDOM.Load("http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml")


'Get all of the <item> tags in the feed
Set itemList = xmlDOM.getElementsByTagName("item")
strHTML = strHTML & "<ul>"
'Iterate over each item
For Each item In itemList
'Parse the item children
For each child in item.childNodes
Select case lcase(child.nodeName)
case "title"
title = child.text
case "link"
link = child.text
case "description"
description = child.text
End Select
Next
'Build the HTML for each bullet item
strHTML = strHTML & "<li>"
strHTML = strHTML & "<a href='" & Server.HTMLEncode(link) & "'>"
strHTML = strHTML & Server.HTMLEncode(title)

strHTML = strHTML & "</a>"
strHTML = strHTML & "<br>"

strHTML = strHTML & description
strHTML = strHTML & "<br> "
strHTML = strHTML & "</li>"
Next
strHTML = strHTML & "</ul>"
Set xmlDOM = Nothing
Set itemList = Nothing
Application.Lock
Application("rss-html") = strHTML
Application("rss-html-time") = Now()
Application.UnLock

End If
Response.Write(Application("rss-html"))
%>
</body>
</html>

You can see it here:

http://stevehigham59.7host.com/feedTest.asp

If I try to add some CSS to it to make it look a little more presentable, something like this....

<style type="text/css">

p{font: normal normal 100 12px tahoma; text-align: justify;}

</style>

....it does not alter the formatting.

What is preventing me from formatting it? Is it this:

Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")


And if so, how can I get round it, please?

Thanks.

Steve

Spudhead
07-08-2008, 02:14 PM
The CSS you posted contains one rule, for <p> tags. The ASP that you posted doesn't write any <p> tags.

SteveH
07-08-2008, 02:24 PM
Hello Spudhead

Thanks for your reply.

I can't see the feed, obviously, from the ASP script so I can't format the text of the feed itself, so would I format strHTML with the <p> or other tags? Or where I have, for instance: case "title", how would I format that?

Cheers again.

Steve

Spudhead
07-08-2008, 02:28 PM
I can't suggest to you how to layout your HTML - you're the only one who knows how you need it to appear. But if your ASP is writing out <li> tags, then your CSS needs to contain rules that apply to <li> tags. Currently your title is inside an <a> tag, which is inside a <li> tag. So your CSS would need a rule that applies to <a> tags inside <li> tags.

SteveH
07-08-2008, 02:51 PM
Hello Spudhead again

I applied this:

<style type="text/css">

A:link { text-decoration: none }
A:active { text-decoration: none }
A:visited { text-decoration: none }

</style>

to the head of my ASP script and it has worked - thank you for your suggestion.

I suppose in my original post I was asking where to correctly place my HTML tags in my ASP script. So if I wanted

p{font: normal normal 100 12px tahoma; text-align: justify;}

where would I put the <p> tag?

Cheers for your help.

Steve

SteveH
07-08-2008, 03:48 PM
For example, if I do this, I can still seee Times New Roman in the output:


<style type="text/css">

p{font: normal normal 100 10px tahoma; text-align: justify;}

A:link { text-decoration: none }
A:active { text-decoration: none }
A:visited { text-decoration: none }

</style>

<body>
<%
If DateDiff("h", Application("rss-html-time"), Now()) >= 2 then

Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True

xmlDOM.Load("http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml")

'Get all of the <item> tags in the feed
Set itemList = xmlDOM.getElementsByTagName("item")
strHTML = strHTML & "<p><ul>"
'Iterate over each item
For Each item In itemList
'Parse the item children
For each child in item.childNodes
Select case lcase(child.nodeName)
case "title"
title = child.text
case "link"
link = child.text
case "description"
description = child.text
End Select
Next
'Build the HTML for each bullet item
strHTML = strHTML & "<li>"
strHTML = strHTML & "<a href='" & Server.HTMLEncode(link) & "'>"
strHTML = strHTML & Server.HTMLEncode(title)

strHTML = strHTML & "</a>"
strHTML = strHTML & "<br>"

strHTML = strHTML & description
strHTML = strHTML & "<br> "
strHTML = strHTML & "</li>"
Next
strHTML = strHTML & "</ul></p>"
Set xmlDOM = Nothing
Set itemList = Nothing
Application.Lock
Application("rss-html") = strHTML
Application("rss-html-time") = Now()
Application.UnLock

End If
Response.Write(Application("rss-html"))
%>
</body>
</html>

Cheers

Steve

brazenskies
07-08-2008, 08:15 PM
Why don't you style up body?

SteveH
07-09-2008, 11:12 AM
Hello brazenskies

Thanks for your message.

I'm hoping to do that (I only need to use the <p> tab, really). Is it the following that I would need to put tags on to?

case "title"
case "link"
case "description"

Cheers

Steve

brazenskies
07-09-2008, 01:15 PM
if you don't want to set a site wide font you could just style up the <li> tag

li {font: normal normal 100 12px tahoma; text-align: justify;}

VIPStephan
07-09-2008, 01:31 PM
Uhm, not sure it has been covered yet but CSS ist styling HTML, not ASP. And therefore, don’t look at your ASP code to find out what to style, look at the HTML output, i. e. view your page in the browser of your choice, and then view its source code. The HTML you see there is what you can style. This way no distracting server side code is there to confuse you.

And by the way: You can’t have lists within paragraphs.

SteveH
07-09-2008, 01:46 PM
Many thanks to you both.

Yes, that is what I was wanting advice on, really: where to write the HTML without the ASP distraction - looking at the page source through a browser.

Thanks again.

Steve

SteveH
07-10-2008, 12:52 PM
Hello adityaj123

Thanks for the link, but it looks like a basic HTML tutorial rather than one which deals with placing tags in ASP script.

Steve

jerry62704
07-10-2008, 11:09 PM
Have you looked at this site: http://www.w3schools.com/asp/default.asp?

SteveH
07-11-2008, 10:31 AM
Many thanks, Jerry. Looks good!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum