Solved

Where should I add CSS within an .aspx page

Posted on 2010-11-08
5
853 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
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 tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
Suggested Courses

632 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