Solved

Where should I add CSS within an .aspx page

Posted on 2010-11-08
5
841 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The answer was partially correct.
0
 

Author Comment

by:dshrenik
Comment Utility
The CSS must go inside this:

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now