---
title: "How to change CSS property before element is created?"  
description: "How to change CSS property before element is created?"  
author: "Anonymous User"  
published: 2012-12-28  
updated: 2012-12-28  
canonical: https://www.mindstick.com/forum/517/how-to-change-css-property-before-element-is-created  
category: "css-css3"  
tags: ["css-css3"]  
reading_time: 1 minute  

---

# How to change CSS property before element is created?

Hello every one \
\

I have to modify the div's [css](https://www.mindstick.com/forum/514/background-gradient-ie7-css-problem) before the window.onload, and [body](https://yourviews.mindstick.com/story/2120/rare-species-having-electricity-in-their-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](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)*\

## Replies

### Reply by AVADHESH PATEL

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>
```

\


---

Original Source: https://www.mindstick.com/forum/517/how-to-change-css-property-before-element-is-created

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
