March 15, 2012

Certain properties don't transfer over from external style sheet

Question by Adam

So I’m currently designing a website, and I’m using the same CSS for every page. Originally, I had it included in each individual document, however it got annoying having to change it on every page, so instead I set them all to work off an external style sheet. Now, it worked for the most part, however a couple properties stopped working, namely text-align and float. What’s weird is that if you include those properties in an internal style sheet, it starts working again. I’m guessing it has to do with some sort of priority thing, but I’m wondering why those specific properties don’t work, and if there’s any way of specifying those properties in an external style sheet. Thanks!

CSS:

    div.box1
    {
        border-width:0px;
        text-align:left
    }
    img.floatLeft
    { 
        float: left; 
        margin: 5px;  
    }

    img.floatRight
    { 
        float: right;  
        margin: 5px;  
     }

HTML:

<div class="box1">
<font face="helvetica">
    TEXT TEXT TEXT <br><br><br>
    <b>NAME</b>
    <br>
    <img src="NAME" class="floatRight">
    TEXT TEXT TEXT<br><br>
    <b>NAME2</b>
    <br>
    <img src="NAME2" width="214" height="130" class="floatLeft">
    TEXT TEX TEXT
</font>
</div>

Answer by Starx

There is a typo at text-align:left. You are missing a semicolon ; to terminate the statement. Rest is fine.

Your left floated image does not have any attribute src, height or width so it will basically not show itself in the DOM.

See a working demo

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!