HOW TO CHANGE CSS PROPERTY BEFORE ELEMENT IS CREATED?

john rob

Total Post:108

Points:756
Posted by  john rob
 1673  View(s)
Ratings:
Rate this:
Hello every one

I have to modify the div's css before the window.onload, and body.onload.

 

<html>

    <head>

        <style type="text/css">

            html, body {

                width: 100%;

                height: 100%;

                padding: 0px;

                margin: 0px;

            }

            div {

                margin-left: auto;

                margin-right: auto;

            }

        <script>

 

HTMLDivElement.prototype.style.marginTop = (window.innerHeight/2 - HTMLDivElement.scaleHeight/2) + "px";

        </script>

    </head>

 

    <body>

        <div>

        foo<br/>bar

        </div>

    </body>

</html>

Thanks in advance

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: How to change CSS property before element is created?

    Hi John rob

    Without changing your HTML code try this code:

     <style type="text/css">       

            #nav

            {

                width: 100%;

                overflow: auto;

                border: solid 1px red;

            }

            #ulListNavi

            {

                margin: 0;

                padding: 0;

                list-style: none;

            }

            #nav #ulListNavi li

            {

                float: left;

            }

            #nav #ulListNavi li a

            {

                margin-left: 5px;

            }

        </style>


      Modified On Dec-28-2012 09:40:43 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!