I had to change the Base_URL since the pages were not loaded by simply giving localhost/magento/ so i had to change it as localhost/magento/index.php
I set the values of the web/unsecure/base_url and web/secure/base_url as http://localhost/magento/index.php/ in the default scope and same in the website scope. By changing this way all pages were loaded correctly but without the CSS .
I did many changes described in many forums and nothing worked out. Then i changed the values of website scope of web/unsecure/base_url and web/secure/base_url as http://localhost/magento/ and frontend seems to be working well with the CSS files being loaded properly.
But the problem persists in the backend where CSS is not loading..
Help me. Thanks in advance.. :)