PDA

Click to See Complete Forum and Search --> : Define CSS (Newbie)


Mike Hildner
Dec 3rd, 2004, 05:54 PM
Apologies, I think a newbie question here, searched, but can't seem to find.

What's the best way to define a css file for your .aspx pages? Can't find a property for the page or document.

Strange enough, when you start a new C# ASP.NET application, you don't even get a default Styles.css. So I created a new VB ASP.NET app and copied that Styles.css to my C# project. Now I need to "link" to the .css so all my pages will use the same styles.

Thanks,
Mike

mendhak
Dec 3rd, 2004, 11:12 PM
In the <head> section, add

<link rel="stylesheet" href="stylesheetname.css">

The lazy man's way would be, open the HTML view of your aspx page, and drag that css file into the page. It'll create the tag for you.

Mike Hildner
Dec 4th, 2004, 02:59 AM
Thanks, mendhak, for the reply. I guess I know how to use that with HTML pages, is there any more to it with ASP.NET? In particular, if I put a Web Forms Label on the designer, it has a property named "CssClass". I set this to H1 or whatever, and nothing looks different during design or runtime. Or am I doing this wrong?

mendhak
Dec 4th, 2004, 04:50 AM
Have you set any special formatting for H1 in your CSS?

Mike Hildner
Dec 4th, 2004, 04:55 AM
Err, umm, no :blush: To be honest, I really don't know what I'm doing. I just grabbed the Styles.css created by a new VB.NET ASP.NET project - I will try, though. Thanks.

Mike Hildner
Dec 4th, 2004, 05:14 AM
Again, I'm a newbie at this. I have an aspx page, added this to the <head>:
<link rel="stylesheet" href="Styles.css">

In the designer, I added a Web Forms Label and the HTML looks like:

<asp:Label id="lblMendhak" style="Z-INDEX: 110; LEFT: 528px; POSITION: absolute; TOP: 48px"
runat="server" Height="32px" Width="160px" CssClass="H1">mendhak</asp:Label>

You can see that in the properties page, I made the CssClass set to H1. My Styles.css has this:

H1, H2, H3, H4, H5, TH, THEAD, TFOOT
{
COLOR: #0D5692;
}

The default color was #003366, but I changed, just to see if anything would change. Styles.css is in the virtual directory.

TomGibbons
Dec 4th, 2004, 03:57 PM
That CSS is defining the style for the H1 element, not a class called H1. If you wanted a H1 class, you could use this:.H1
{
COLOR: #0D5692;
}
:)

mendhak
Dec 5th, 2004, 06:04 AM
Give your CSS classes better names so as to avoid confusions like this one.

Here's a CSS tutorial btw, you can quickly run through it. CSS is extremely easy. Once you get the basic idea, it's just a matter of applying it and referencing google once in a while. :)

www.w3schools.com/css

TomGibbons
Dec 5th, 2004, 08:29 AM
Yeah, as an extension on what Mendhak said, I always try to name my classes depending on what they're going to be used for. Such as.code
{
font-family: "Courier New",Courier, Arial;
font-size: 10pt;
}Again, just to eradicate any confusion.

:)

hellswraith
Dec 5th, 2004, 12:03 PM
You can take your stylesheet in the solution explorer and drag it onto the aspx page on the design surface. This stops you from having to paste the html on every page, you can just drag a stylesheet over.

Mike Hildner
Dec 6th, 2004, 10:04 AM
ok - makes sense now. Thanks all for the info.

nemaroller
Dec 8th, 2004, 01:07 PM
ok - makes sense now. Thanks all for the info.

You can also use style tags inline... in the <head> section of a webpage, if you wish to customize that page seperately from an externally referenced stylesheet.


<head>
<style type="text/css">
.h1 { font-family: verdana,arial,helvetica,sans-serif; color: #CC6600; font-size: medium; }
.h1color { font-family: verdana,arial,helvetica,sans-serif; color: #CC6600; font-size: small; }</style>
</head>