Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    Adding CSS to ASP?

    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

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    The CSS you posted contains one rule, for <p> tags. The ASP that you posted doesn't write any <p> tags.

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    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

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    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

  • #6
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    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

  • #7
    Regular Coder
    Join Date
    May 2008
    Location
    Oxford, UK
    Posts
    422
    Thanks
    14
    Thanked 27 Times in 27 Posts
    Why don't you style up body?

  • #8
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    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

  • #9
    Regular Coder
    Join Date
    May 2008
    Location
    Oxford, UK
    Posts
    422
    Thanks
    14
    Thanked 27 Times in 27 Posts
    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;}

  • #10
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,606
    Thanks
    6
    Thanked 997 Times in 970 Posts
    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.

  • #11
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    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

  • #12
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    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

  • #13
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    Have you looked at this site: http://www.w3schools.com/asp/default.asp?
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #14
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Many thanks, Jerry. Looks good!


  •  

    Posting Permissions

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