Solved

CSS width not working in Firefox

Posted on 2008-11-03
3
428 Views
Last Modified: 2012-06-27
I found this piece of code on EE, it breaks a page up into simple tabs.

I've tried to adjust the width of the tabs by adding the width tag as below but it wont work in Firefox, it works perfecctly in Internet Explorer. Anyone any thoughts? Many thanks
<style type="text/css">

#tab1, #tab2, #tab3, #tab4 {display:none;}

.tabBtn {background:#ccc;width:200px;}
 

.showTab1 #tab1,

.showTab2 #tab2,

.showTab3 #tab3,

.showTab4 #tab4 {display:block;}
 

.showTab1 #tabBtn1,

.showTab2 #tabBtn2,

.showTab3 #tabBtn3,

.showTab4 #tabBtn4 {background:pink;}

</style>

<script type="text/javascript">

function setTab(num)

{

  document.getElementById('tabHolder').className = 'showTab' + num;

}

</script>

<div id="tabHolder" class="showTab1">

  <a href="#" id="tabBtn1" class="tabBtn" onclick="setTab(1)">Tab 1</a>

  <a href="#" id="tabBtn2" class="tabBtn" onclick="setTab(2)">Tab 2</a>

  <a href="#" id="tabBtn3" class="tabBtn" onclick="setTab(3)">Tab 3</a>

  <a href="#" id="tabBtn4" class="tabBtn" onclick="setTab(4)">Tab 4</a>

  <table id="tab1">

    <tr><th>Data1</th></tr>

  </table>

  <table id="tab2">

    <tr><th>Data2</th></tr>

  </table>

  <table id="tab3">

    <tr><th>Data3</th></tr>

  </table>

  <table id="tab4">

    <tr><th>Data4</th></tr>

  </table>

</div>

Open in new window

0
Comment
Question by:kbit
3 Comments
 
LVL 3

Accepted Solution

by:
SreejithG earned 250 total points
ID: 22865960
Use padding (padding-right) instead of width. Code attached.

regards,
Sreejith
<style type="text/css">

#tab1, #tab2, #tab3, #tab4 {display:none;}

.tabBtn {background:#ccc;padding-right:200px;	}

 

.showTab1 #tab1,

.showTab2 #tab2,

.showTab3 #tab3,

.showTab4 #tab4 {display:block;}

 

.showTab1 #tabBtn1,

.showTab2 #tabBtn2,

.showTab3 #tabBtn3,

.showTab4 #tabBtn4 {background:pink;}

</style>

<script type="text/javascript">

function setTab(num)

{

  document.getElementById('tabHolder').className = 'showTab' + num;

}

</script>

<div id="tabHolder" class="showTab1">

  <a href="#" id="tabBtn1" class="tabBtn" onclick="setTab(1)">Tab 1</a>

  <a href="#" id="tabBtn2" class="tabBtn" onclick="setTab(2)">Tab 2</a>

  <a href="#" id="tabBtn3" class="tabBtn" onclick="setTab(3)">Tab 3</a>

  <a href="#" id="tabBtn4" class="tabBtn" onclick="setTab(4)">Tab 4</a>

  <table id="tab1">

    <tr><th>Data1</th></tr>

  </table>

  <table id="tab2">

    <tr><th>Data2</th></tr>

  </table>

  <table id="tab3">

    <tr><th>Data3</th></tr>

  </table>

  <table id="tab4">

    <tr><th>Data4</th></tr>

  </table>

</div>

Open in new window

0
 
LVL 7

Assisted Solution

by:Valleriani
Valleriani earned 250 total points
ID: 22865976
I have used padding for this:

padding:0px 52px; <-- change the 52px and it will set.

With the first number can change the height a bit, though it will clash if you don't move down the data.

Second number is the padding width, it will stay centered.
<style type="text/css">

#tab1, #tab2, #tab3, #tab4 {display:none;}

.tabBtn {

background:#ccc;

padding:0px 52px;

}
 

.showTab1 #tab1,

.showTab2 #tab2,

.showTab3 #tab3,

.showTab4 #tab4 {display:block;}
 

.showTab1 #tabBtn1,

.showTab2 #tabBtn2,

.showTab3 #tabBtn3,

.showTab4 #tabBtn4 {background:pink;}

</style>

<script type="text/javascript">

function setTab(num)

{

  document.getElementById('tabHolder').className = 'showTab' + num;

}

</script>

<div id="tabHolder" class="showTab1">

  <a href="#" id="tabBtn1" class="tabBtn" onclick="setTab(1)">Tab 1</a>

  <a href="#" id="tabBtn2" class="tabBtn" onclick="setTab(2)">Tab 2</a>

  <a href="#" id="tabBtn3" class="tabBtn" onclick="setTab(3)">Tab 3</a>

  <a href="#" id="tabBtn4" class="tabBtn" onclick="setTab(4)">Tab 4</a>

  <table id="tab1">

    <tr><th>Data1</th></tr>

  </table>

  <table id="tab2">

    <tr><th>Data2</th></tr>

  </table>

  <table id="tab3">

    <tr><th>Data3</th></tr>

  </table>

  <table id="tab4">

    <tr><th>Data4</th></tr>

  </table>

</div>

Open in new window

0
 

Author Comment

by:kbit
ID: 22866164
Many thanks both, I've taken inspiration from each of you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS Divs in Safari 3 39
CSS measurement 10 34
FIx alignment of two texts 1 26
Wrapper for APPs 9 28
CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now