1

Html

<table style='width: 150px; border: 1px solid black;'>


 <tr>
    <td>blablabla</td>
      <td>blablabla</td>
  </tr>
     <tr>
    <td>abcd</td>
      <td>abcd</td>
  </tr>
</table>

I want to change the table width to 600px. I couldnt figure out the selector for changing width.
Please help , i am learning css.

5 Answers 5

1

Just do like this

HTML

<table style='width: 150px; border: 1px solid black;'>


 <tr>
    <td>blablabla</td>
      <td>blablabla</td>
  </tr>
     <tr>
    <td>abcd</td>
      <td>abcd</td>
  </tr>
</table>

CSS

table {
  width:600px!important;
  border:1px solid black;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank You ! I wasnt using !important It was so easy , i dont know why people downvote it ! :p
if necessary than only use !important if not than don't it is bad practice
1

Change the width value in the style attribute.

 <table style="width: 600px;">

yields a table that is 600px wide.

2 Comments

You want to change the CSS width using JavaScript? Why didn't your write that in your question?
Have i mentioned anywhere using javascript? i clearly wrote using css. btw i got it :)
1

You should use like this -

table [style]{width:600px !important}

Comments

0

It is specified inline right there in your code.

<table style='width: 150px; border: 1px solid black;'>

change this

<table style='width: 600px; border: 1px solid black;'>

Alternatively

Use a class in your table and use the selector in your css file.

<table class="tbl" style='width: 150px; border: 1px solid black;'>

CSS

.tbl{width:600px!important} /*!important override inline css 150px*/

If you can remove the inline css used in table, you need not to use !important like this-

<table class='tbl'>

CSS

.tbl{width:600px}

2 Comments

Ops , No i dont want to change it from html for some reason , can i change it through css?
Hey Thank you. Class thing worked for me :) But using table {width: 600px !important;} also worked :) Thanks for your help
0

To those who width !important didnt work, try also changing min-width and setting it to !important.

.myCssTable { 
width: 80% !important;
min-width: 80% !important;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.