12

I want to design a tab header. The html code is,

<div class="tab-header">
    <a href="" class="current">tab1-title</a>
    <a href="">tab2-title</a>
</div>

Now I need to apply a background image to the current class, too make effect like this, enter image description here

But the inline element a is not big enough for this background image, so I adjust the width and height of the element a. But the adjustment failed, the width/height of the element did not change.

How could I get the right effect?

Thanks.

Jichao
  • 40,341
  • 47
  • 125
  • 198

4 Answers4

30

To apply width, set css property 'display' to either 'block' or 'inline-block'.

block: the element will sit in a single line. In such case you may want to set float so links are in the same line;

inline-block; the element will have height, width, etc, and multiple elements will sit in the same line (block).

James Chen
  • 10,794
  • 1
  • 41
  • 38
4

Set the display property to inline-block, and then you can set the width, height, and vertical-align as necessary.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
1

Use

display: inline-block;

on the inline element. With a little tweaking, this has wide cross-browser support and is incredibly useful for the kind of layout you're after.

harpo
  • 41,820
  • 13
  • 96
  • 131
-2

You'll have to use display:block on the anchor.

ScottE
  • 21,530
  • 18
  • 94
  • 131