Solved

override table width

Posted on 2006-10-31
11
347 Views
Last Modified: 2012-06-21
I have a div tag which surrounds 3rd party content. It looks like so:

<div id="mainpage">

<table width="755">
<tr>
<td>TEXT</td>
</tr>
</table>

</div>

The problem i am having is that the table is too big. If possible i would like to set a width in the div tag that would override the table width.

Is this possible?

i have already added a style="width:455" to the div tag, but this failed to work.

0
Comment
Question by:asphead
[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
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17841070
You might try something like:

div#mainpage table {
    width: 900px;
}


If that doesn't work you could try it with !important too.

I can't remember offhand where HTML attributes fit in the cascade, but I think they count the same as if the table had style="width: 755px;" as an attribute of the tag.  In that case the !important will definitely be necessary, but will also correctly override the width given in the HTML.
0
 
LVL 7

Expert Comment

by:Animasu
ID: 17841091
you can allways do this

<style>
table{width:500px;}
</style>

- Animasu
0
 
LVL 7

Expert Comment

by:Animasu
ID: 17841101
VoteyDisciple Beet me to it :P i'de use his/hers!

- Animasu
0
Technology Partners: 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!

 

Author Comment

by:asphead
ID: 17841226
i've tried putting in this:

<div id="mainpage" style="width: 455px !important;">

but it doesn't work. is my syntax correct?
0
 

Author Comment

by:asphead
ID: 17841244
also, it seems that the !important rule is ignored by IE !!!
0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 17841525
what you're doing is still only applying css to the div, not to the table.

you need to put up in between your head tags the css to affect the table inside the div like the other experts have said. Or you could put it in a stylesheet that is being used on your page.

div#mainpage table {
    width: 500px;
    width: 500px !important
}

and yes IE will ignore the !important
0
 

Author Comment

by:asphead
ID: 17841761
if it won't work in IE then I will need to find another workaround as it needs to work in all browsers
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17842263
I double checked how specificity is calculated for style attributes ( http://www.w3.org/TR/REC-CSS2/cascade.html ) and I was correct; it counts the same as if the table were styled with an ID.

Thus, the selector "div#mainpage table" is more specific, and will take precedence without the !important.  To be sure, I tested it just now and it works just as expected.  

As VirusMinus pointed out, though, your rule is still applying style to the DIV, not the table.  You have to use the selector I gave (or what VirusMinus wrote).   Incidentally, what Animasu suggested will not work; your selector has to have an ID in it.
0
 

Author Comment

by:asphead
ID: 17842903
hi VirusMinus ,

could you post the example you created that shows it working?

i haven't had any luck with it so far...

thanks!
0
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 150 total points
ID: 17842931
What I tried was:

<head>
<style type="text/css">
div#main table {
    width: 200px;
}
</style>
</head>

<body>

<div id="main">
<table width="500">
<tr><td>A</td><td>B</td></tr>
</table>

</div>

</body>



Is it possible the nature of the table's contents are such that it has to expand the table wider than the width you're giving to fit?  Like, one really long word, for example?  That can be overcome too, if that's the case.
0
 

Author Comment

by:asphead
ID: 17843357
thanks VoteyDisciple - that worked for me
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…

689 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