Solved

Where should I add CSS within an .aspx page

Posted on 2010-11-08
5
846 Views
Last Modified: 2012-05-10
When I add the following code in a ContentPlaceHolder in my .aspx page (creating using Visual Studio 2010), it says that "Element 'style' cannot be nested within element 'div'".

When I add it outside a  ContentPlaceHolder, it does not accept it.
When I use the second code snippet, it says "You can only have one <head runat="server"> control on a page."

Please let me know where I must add the code.
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="Js/jquery.min.js"></script>
    <style type="text/css">
    .imgMargin
    {
    margin-left:3px;
    margin-right : 3px;
    }
    </style>
</head>

Open in new window

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<style type="text/css">
    .buttonMargin
    {
    margin-left:2px;
    margin-right : 2px;
    }
    </style>

Open in new window

0
Comment
Question by:dshrenik
  • 3
5 Comments
 

Author Comment

by:dshrenik
ID: 34084710
When I remove 'runat="server"' from the second code snippet, it says that "Element 'head' cannot be nested within element 'div'".
0
 
LVL 5

Accepted Solution

by:
Itsacon earned 500 total points
ID: 34084884
style elements should go inside the head element, which should go in front of the body element (which should be generated by the MainContent placeholder).

Try moving the MainContent after the head element, place the style element inside the head and remove the runat="server" attribute from the head element
0
 

Expert Comment

by:nordenLFT
ID: 34085135
Hi dshrenik,
Are you using a Master Page? If so, create the ContentPlaceHolder within the <head> section of the master page. In your ASPX page, add the CSS style in the <asp:content>.
0
 

Author Closing Comment

by:dshrenik
ID: 34085420
The answer was partially correct.
0
 

Author Comment

by:dshrenik
ID: 34085427
The CSS must go inside this:

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question