Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have main div , in that i have background color .
than i have other div which have image (in png form ), in this div i have multiple divs . so from multiple divs i posted 1 div.

1) when I have used this code for div , its works fine in chrome , safari , ie and not works in firefox.:
ASP.NET
<div style="position: absolute; top:52.5em; left:10.1em;">
                  <asp:Label ID="lbl1" runat="server" CssClass="background fontStyle"></asp:Label>   
              <asp:Label ID="lbl2" runat="server" CssClass="background fontStyle"></asp:Label>
              </div>


2) when i used this code , it works only in firefox , and in other browser lables are got disturbed from their position.
ASP.NET
<div style="position: relative; top:30.8em; left:10em;">
    <asp:Label ID="lbl1" runat="server" CssClass="background fontStyle"></asp:Label>   
<asp:Label ID="lbl2" runat="server" CssClass="background fontStyle"></asp:Label>
</div>
Posted
Updated 24-Jun-14 20:15pm
v3
Comments
SRS(The Coder) 25-Jun-14 3:19am    
You can use jQuery .CSS() method to set the position for any div you want by getting the browser details in jQuery like $.browser.
i have used css file,
and i want to set at same position of div for all browser.

like ,
if in chrome i have set , <div id="divEspana" style="position: absolute; left: 20em; top:64.8em;>
it will work in all browser.
r u getting me mam?if not than let me know.
thank x.
Or is there any way to know browser like , if i opened page in opera so , there will be different css class (class , not css file) than if i opened chrome/mozilla so different css class , to set div's position , top, left , etc.

Thank x
SRS(The Coder) 25-Jun-14 6:09am    
Hi Bhagyashree,

Thanks for your response to my comment.
I think there is a confusion, actually i wanted to tell you regarding the jQuery .css() method not about css file which we use to assign styles to our page elements.

For this you have to include the jQuery file into your project and to add a reference to that file. Then using this method you can assign different classes to your div element by checking the current browser. Please have a look to the example i have posted as answer.

I have added the entire sample file html code for you which you can test :-

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <style type="text/css">
        .class1 {
            width:200px;
            height:200px;
            background-color:black;
        }
        .class2 {
            width:300px;
            height:300px;
            background-color:red;
        }
    </style>
    <title></title>
    <!-- This jQuery file is at root of my project and referenced here to use the jQuery script. -->
    <script src="jquery-2.0.3.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btnTest").toggle(function () {
                $("#divTest").addClass("class1");
                $("#divTest").removeClass("class2");
            }
            , function () {
                $("#divTest").addClass("class2");
                $("#divTest").removeClass("class1");
            });
        });
    </script>
</head>
<body>
    <form id="frmTest"  runat="server">
    <div id="divTest">
        <input type="button" id="btnTest" value="Test" />
    </div>
    </form>
</body>
</html>


Hope this will be of help to you.
 
Share this answer
 
v2
Comments
thank you mam.
really a big thanks for reply but i dont want on button click , when i open my page in different browser div's positions are disturebed (in chrome if my div is on correct position but in Mozilla same div was not in same position as in chrome ).

Thank you.
SRS(The Coder) 26-Jun-14 1:34am    
If this solves your issue then please mark it as answer. :)
Also the above jQuery code can be done without using the toggle method of jQuery by handling the click event of the button, as mentioned below :-

JavaScript
$(function () {
  $("#btnTest").on("click",
  function () {
     if(!$("#divTest").hasClass("class1")){
          $("#divTest").addClass("class1");                        						  $("#divTest").removeClass("class2");
     }else{
          $("#divTest").addClass("class2");
          $("#divTest").removeClass("class1");
     }
  });
});



Hope this will also be of your help.
 
Share this answer
 
Comments
SRS(The Coder) 26-Jun-14 1:42am    
I have created one JavaScript fiddler for you :-

http://jsfiddle.net/smrutis1984/wZFpS/1/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900