Search code examples
htmlwidth

Set width in % in context of the site


I want a page which looks same in all browsers, so what i was trying to do is setting css: width= x%.

Width is only working with the nearest wrapping tag, like <div>...</div>

How do I set width in context with the page/website or body?

I checked position: ... out, but thats not what i want

Code:

<table><tr><td>
            <a href="/lala">link</a>
                </td><td>
                    <strong>writing a book</strong>
                </td></tr>
            <tr><td>
            <textarea class="form-control" style="width: 45%" disabled>text 1</textarea>
                </td><td>
            <textarea class="form-control" rows="3" cols="50" disabled>text2</textarea>

                </td>
            </tr>
        </table>

Solution

  • Instead of using the % use vw (it stands for viewport width) and if you want the textarea to be 75% of the page you can set the textarea to 75vw.

    Check a demo here

    textarea{
        width: 75vw;
     }