views:

302

answers:

4

I'm trying to emulate a tab bar with html

I'd like the width of each tab to be set according to the text lenght (that is, no fixed width) and to word wrap in case it exceeds the screen width

I've almost achieved it

<html>
<head>

<style type="text/css">
    #myTabs .tab {
    float: left;
    }

    #myTabs .tab_middle {
        margin: 0;
        padding: 0;
        border: none;
    background-image:url('images/tabs/tab_middle.png');
    }

    #myTabs .tab_left {
        margin: 0;
        padding: 0;
        border: none;
        background-image:url('images/tabs/tab_left.png');
    }

    #myTabs .tab_right {
        margin: 0;
        padding: 0;
        border: none;
    background-image:url('images/tabs/tab_right.png');
    }

</style>

</head>

<body>

<div id="myTabs">
  <div class='tab'>
        <span class='tab_left'>&nbsp;</span>
        <span class='tab_middle'>very very looong</span>
        <span class='tab_right'>&nbsp;</span>
    </div>
  <div class='tab'>
        <span class='tab_left'>&nbsp;</span>
        <span class='tab_middle'>another loooong tab</span>
        <span class='tab_right'>&nbsp;</span>
    </div>
    <div style='clear:both'></div>
</div>

</body>
</html>

but, there's a very annoying space between the opening tab image and the closing one...

as you can see I've tried with padding, spacin, and border, with no luck...

any idea?

thanks a lot

saludos

sas

-- edit I tried replacing the spans with a small table (one row, three TDs) but it's the same, only the space between is smaller...

+1  A: 

Get rid of the newlines between the spans. Example:

<div class='tab'> <span class='tab_left'>&nbsp;</span><span class='tab_middle'>very very looong</span><span class='tab_right'>&nbsp;</span> </div>

Newlines are counted as a space in HTML.

njbair
A: 

hard to test without the images but I added background color and display:inline to the root tabs. Please try this:

<html>
<head>

<style type="text/css">
    #myTabs .tab {
        float: left;
        display:inline;
    }

    #myTabs .tab_middle {
        margin: 0;
        padding: 0;
        border: none;
    background-image:url('images/tabs/tab_middle.png');
    }

    #myTabs .tab_left {
        margin: 0;
        padding: 0;
        border: none;
        background-image:url('images/tabs/tab_left.png');
    }

    #myTabs .tab_right {
        margin: 0;
        padding: 0;
        border: none;
    background-image:url('images/tabs/tab_right.png');
    }

</style>

</head>

<body>

<div id="myTabs">
  <div class='tab' style="background-color:Red;">
        <span class='tab_left'>&nbsp;</span>
        <span class='tab_middle'>very very looong</span>
        <span class='tab_right'>&nbsp;</span>
    </div>
  <div class='tab' style="background-color:Green;">
        <span class='tab_left'>&nbsp;</span>
        <span class='tab_middle'>another loooong tab</span>
        <span class='tab_right'>&nbsp;</span>
    </div>
    <div style='clear:both'></div>
</div>

</body>
</html>
Cheddar
nice try, but the space is still there, in red on the first tab and green on the second...
opensas
A: 

Tab middle, left and right also need to float left.

BigChrisDiD
A: 

njbair's response is correct...

just for the record, another option was to use a table, with the border-collapse: collapse; attribute...

saludos

sas

oops, another gotcha... in Internet Explorer 6.0 the first approach (spans) doesn't work as expected, when resizing the window IE wordwraps the span, breaking the tab, while with the table approach even IE sends down the whole tab...

opensas