Search code examples
csswidth

Percentage width in css


I have developed a html css code. It works perfect on all browsers but when I am uploading it to the website's sidebar it is not displaying properly.

<p>
 <ul style="display:inline; list-style-type: none;">
 <li style="
background:none repeat scroll 0 0 rgba(255, 57, 65, 0.9) !important;
 text-decoration:none;

position: relative;
margin: 0 0 -6px 0;

padding: 15px 15px 15px 15px;

list-style:none;

width: 100%;

border: 0;

 ">
 <a style="color: #000000; text-decoration: none;text-align:center;" href="#">F Awan</a></li>

 <li style="background:none repeat scroll 0 0 rgba(255, 103, 57, 0.9) !important;padding:5px;text-decoration:none;width:95%;text-align:right;color: #000000; text-decoration: none;

 position: relative;

    margin: 0 0 -6px 0;

    padding: 15px 15px 15px 15px;

    list-style:none;



    border: 0;

 ">(IT Consultant, UK) </li> 
 <li style="background:none repeat scroll 0 0 rgba(255, 218, 57, 0.9) !important;padding:5px;text-decoration:none;color: #000000; text-decoration: none;


 position: relative;

    margin: 0 0 -6px 0;

    padding: 15px 15px 15px 15px;


    width: 90%;

    border: 0;


 "><a style="color: #000000; text-decoration: none;text-align:center;" href="#">FUddin</a> </li> 
 <li style="background:none repeat scroll 0 0 rgba(193, 241, 78, 0.9) !important;padding:5px;text-decoration:none;width:85%;text-align:right;color: #000000; text-decoration: none;

 position: relative;

    margin: 0 0 -6px 0;

    padding: 15px 15px 15px 15px;

    list-style:none;



    border: 0;

 "> (Systems Engineer, Pakistan)</li> 


 <li style="
 background:none repeat scroll 0 0 rgba(29, 195, 246, 0.9) !important;;padding:5px;
 text-decoration:none;color: #000000; text-decoration: none;

 position: relative;

    margin: 0 0 -6px 0;

    padding: 15px 15px 15px 15px;

    list-style:none;

    width: 80%;

    border: 0;
    ">

 <a style="color: #000000; text-decoration: none; href="mailto:f_awan@hotmail.com?Subject=Hello%20again">Interact with Us </a>

 </li>
</ul>
</p>

Here is the JSFiddle.


Solution

  • It's better if you remove width & use margin-right instead of it. Write like this:

    CSS

    .red{
    background:rgba(255, 57, 65, 0.9);
    }
    .orange{
    background:rgba(255, 103, 57, 0.9);
        text-align:right;
        margin-right:5%;
    }
    .yellow{
    background:rgba(255, 218, 57, 0.9);
        margin-right:10%;
    }
    .green{
    background:rgba(193, 241, 78, 0.9);
        text-align:right;
        margin-right:15%;
    }
    
    .blue{
    background:rgba(29, 195, 246, 0.9);
        margin-right:20%;
    }
    

    Check this http://jsfiddle.net/RN2Hy/1/