?
Solved

CSS width not working in Firefox

Posted on 2008-11-03
3
Medium Priority
?
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
SreejithG earned 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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