Solved

Where should I add CSS within an .aspx page

Posted on 2010-11-08
5
849 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net mvc 2 33
Query in AngularJS 8 43
Images showing on the internet -- asp.net -- VB.net.  Why some do and some don’t. 3 22
.CSS HTML Help 3 21
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

761 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