0

Instead of

<style> some css code</a>

and then using

<a href="mylink" class="some class">anchor</a>

I want to use something like this:

<a href="mylink" style="something">anchor</a>

So how would I convert this css in such a form (something):

<style>
.twitterbird {
margin-bottom: 10px;
width: 160px;
height:160px;
display:block;
background:transparent url('twitterbird.png') center top no-repeat;
}

.twitterbird:hover {
background-image: url('twitterbird_hover.png');
}
</style>
Zox
  • 203
  • 3
  • 8

3 Answers3

2

I don't understand why you aren't linking to an external stylesheet.

Put...

<link rel="stylesheet" type="text/css" href="<!--thename of your css file.css-->" />

in your <head> section.

Take all of your styling and save it in a filename that is linked in the href="" of that line.

Like this...

.twitterbird {
margin-bottom: 10px;
width: 160px;
height:160px;
display:block;
background:transparent url('twitterbird.png') center top no-repeat;
}

.twitterbird:hover {
background-image: url('twitterbird_hover.png');
}

In the .css (cascading style sheet) file you do not use style tags. You would then use class names and id just as you would if you had your css between tags at the top of your html/php file.

Ryan Mortensen
  • 2,307
  • 3
  • 22
  • 27
1

Given your example, you could use inline css:

<a href="mylink" style="margin-bottom: 10px; width: 160px; height: 160px; display: block; background: transparent url('twitterbird.png') center top no-repeat;">anchor</a>

Unfortunately, you won't be able to include the :hover bit like others have already mentioned.

boz
  • 4,891
  • 5
  • 41
  • 68
1

Try this

<a href="mylink" 
 style="margin-bottom: 10px;width: 160px;height:160px;display:block;background:transparent url('twitterbird.png') center top no-repeat;" 
 onmouseover="this.style.background='url(twitterbird_hover.png)'"       
 onmouseout="this.style.background='url(twitterbird.png)'">anchor</a>

please not that this is not the best way to go about it, you shouldn't really use inline styles/javascript

iConnor
  • 19,997
  • 14
  • 62
  • 97