开发者

external CSS issue

开发者 https://www.devze.com 2022-12-17 13:48 出处:网络
Okay, time for my dumb question of the day. I have an external css file that basically assign a background image to a button.

Okay, time for my dumb question of the day.

I have an external css file that basically assign a background image to a button.

Css Code:

input.keypad
{
    cursor: pointer;
    display: block;
    min-width: 64px;
    width: 64px; 
    height: 64px;
    margin: 0;
    border: 0;
    background: url(images/btn1.jpg) no-repeat center top;
}

Html code:

<input class="keypad" type="button" name="btnClickMe" id="btnClickMe" value="Click Me">

My dilema is that the first time I load the page it works 100%, but when I refresh it, it seems to ignore the width and height set in the css file. Th开发者_开发问答e image is is in the background, but cut off because of this.

I thought it might be some sort of caching so I included pragma tags which did not help at all. Any ideas?


Use Firebug to find the reason. It will help you to see which css properties are applied to the element and so on.

You select the element and you will see all css properties of it.

external CSS issue


(source: getfirebug.com)

You have to learn that there are many useful tools out there which can help you solve many of your problems :) Especially Firebug. It is a must-have tool.


Here's some suggestions...

First, do all your page refreshes with Ctrl+F5 in Firefox to override browser cache each time.

Second, check that the button doesn't have a parent element somewhere in the CSS overriding it, such as "form.myForm input { ... }".

Third, instead of declaring the button background in the CSS, move that declaration into your HTML like this:

<input type="image" class="keypad" src="images/btn1.jpg"/>

... whilst keeping the size declarations in CSS as they are now.

See if some of those might help.


Firstly I'd like to thank Balon for pointing me in the right direction.

After using the browser add on he suggested and viewing the html source, I noticed that my <link tag pointing to the external css file was being placed within the <body of the html which I found very odd. Upon reviewing my html code, I saw that my <link tag was infact in the <head> tag, but was below the <script tag, which after swapping the tags around, the code now works 100%.

Here is an example of what I am trying to put across:

Code Before (Broken):

<script type="text/javascript" language="javascript1.2" src="script/example.js"></script>
<link rel="stylesheet" href="css/example.css" type="text/css" media="screen">

Code After (Fixed):

<link rel="stylesheet" href="css/example.css" type="text/css" media="screen">
<script type="text/javascript" language="javascript1.2" src="script/example.js"></script>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号