user35
user35

Reputation: 468

css not working inside div of contentPlaceHolder in asp.net

I have a aspx page which is inheriting the master page.So the content in this page are kept inside contentplaceholder.The content has a div say div1 which inturn has two more div say div2 and div3 inside It.When i applay style to the div1 it works but for div2 and div3 it dosen't.
When i use firebug,the style sheet shows only the div id of div1.But i do have div2 and div3 as well.

Here's the code.

<asp:Content ID="Content2" ContentPlaceHolderID="adminCPH1" Runat="Server">
<link href="../Styles/adminStyl.css" rel="stylesheet" type="text/css" />
<div id="div1">
   <div id="div2">
     I am div2 inside div1
   </div>

  <div id ="div3">
    I am div3 inside div1
  </div>
</div>
</asp:Content>

And here is the stylesheet:

#div1
{
    background-color:red;
    width:300px;
    height:200px
}

#div2
{
    background-color:green;
    width:100px;
    height:200px
}

#div3
{
    background-color:blue;
    width:100px;
    height:200px
}

EDIT
This thing is now working.After trying everything two days ago,I left the code as it is and when I ran the program two days after its working good.But when i make the change in css it's still not working. I use the firebug and now this shows all the divs I have created.I make change from the firebug,it works.I make change in the original file,nothing change.I don't know what is going on.I guess it will work once again after I restart my PC.

Upvotes: 0

Views: 3141

Answers (4)

Jon P
Jon P

Reputation: 19797

Sounds like your CSS file is being cached... which is the normal and desired behaviour.

Your options are, after making the update, when displaying in the browser hit Ctrl+F5 to flush the browser cache for the page.

Your other option is to add a cache breaker to the CSS reference after making the change.

<link href="../Styles/adminStyl.css?v=1" rel="stylesheet" type="text/css" />

Change the value after v when you make changes.

Upvotes: 1

Farrokh
Farrokh

Reputation: 1167

ok,you should use method(change and test).and what is this method?change and test until find the solution and now

please replace div id's with together and check it work or not and whats the result..

<asp:Content ID="Content2" ContentPlaceHolderID="adminCPH1" Runat="Server">
<link href="../Styles/adminStyl.css" rel="stylesheet" type="text/css" />
<div id="div3">
   <div id="div2">
     I am div2 inside div1
   </div>

  <div id ="div1">
    I am div3 inside div1
  </div>
</div>
</asp:Content>

or

<asp:Content ID="Content2" ContentPlaceHolderID="adminCPH1" Runat="Server">
<link href="../Styles/adminStyl.css" rel="stylesheet" type="text/css" />
<div id="div2">
   <div id="div3">
     I am div2 inside div1
   </div>

  <div id ="div1">
    I am div3 inside div1
  </div>
</div>
</asp:Content>

show your result to us.

thank you

Upvotes: 0

Farrokh
Farrokh

Reputation: 1167

please try this steps:

  1. add a contentPlaecHolder in of your master page
  2. add its content section in your page
  3. add your stylesheet defination inside it
  4. check...

    <asp:Content ID="Content2" ContentPlaceHolderID="Head" Runat="Server">
          <link href="../Styles/adminStyl.css" rel="stylesheet" type="text/css" />
    </asp:Content>
    

if it works problem solved ;) but if not try styling your div's inside html such as

hope this was helpful

Upvotes: 0

IrishChieftain
IrishChieftain

Reputation: 15253

Remove the CSS tag from where you have it now. Then drag the stylesheet from solution explorer to the head section in the master page in code view.

Upvotes: 0

Related Questions