Alternatives
There are alternative to using css and you may come across instances where you cannot or should not use css for either layout or styling. Some of these reasons may be that you are working on a site that has not utilized css and you only need to make small changes, You may need to work around a css bug or browser compliance issue (see Apply a different or additional Style Sheet Based on Browser), or you may simply feel that css is not appropriate in these instances you can make use of the following. Style declared in resx file (asp.net) Tabular layout Declare attributes in html However I would stress that most of the time css provides a robust way of laying out and styling your website and I would always use css styling from the start of any project and try to avoid the use of both tabular layout and html style tags. I do however use Styles declared in resx files if I am using css and one such use of this on my site is the flag image next to the language dropdown.
How To
For this I have used an asp.net example but the principal is the same for php etc.
Create an aspx page called Test.aspx and place it in the root of your site.Create a Style Sheet called Test and place it in the root of your site.
Add the following code in to your css file imediately below the last } contained in the file.
.TestClass{ font-size: 23px; font-weight: bold; color: Red;}
In the head section of you page just above the </head> tag add the following code .
<link href="Test.css" rel="stylesheet" type="text/css" />
Create a label or copy the below
<asp:Label ID="lblTestCss" runat="server" Text="This is a Test"></asp:Label>
Add the following text in to the first label tag
CssClass=”TestClass”
It should look something like this
<asp:Label ID="lblTestCss" runat="server" CssClass=”TestClass” Text="This is a Test"></asp:Label>
Run your project and you should see a page with the following content.
This is a Test That is essentially it!!
A few consideration’s/points to note.
• If you are using asp.net masterpages then the link to the css only needs to go in to the masterpage and not each page providing they are using the masterpage • If you are using Visual Studio or Visual Web Developer you can drag the css file on to the page in design view and it will insert the relevant link • In Visual Web Developer 2008, Visual Studio 2008 and Visual Studio 2010 there is a Manage Styles Window that can be accessed from the View Menu. It is fairly intuitive and easy to use
|
|
Summary
That is essentially it!!
A few consideration’s/points to note.
If you are using asp.net masterpages then the link to the css only needs to go in to the masterpage and not each page providing they are using the masterpage • If you are using Visual Studio or Visual Web Developer you can drag the css file on to the page in design view and it will insert the relevant link • In Visual Web Developer 2008, Visual Studio 2008 and Visual Studio 2010 there is a Manage Styles Window that can be accessed from the View Menu. It is fairly intuitive and easy to use
Further Information
|