Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Where should I add CSS within an .aspx page

Posted on 2010-11-08
5
Medium Priority
?
855 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 1500 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
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…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…
Suggested Courses

730 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