Search code examples
csshtmlfixed

How to make a div have a fixed size?


I made a webpage, on which clicking the button 30px changes the font inside the div.

I have a ul inside it with the buttons. When I change the font size, the div expands and the nav buttons move with it as well.

How do I make it so it stays fixed but the fonts can still change.


Solution

  • Try the following css:

    #innerbox
    {
       width:250px; /* or whatever width you want. */
       max-width:250px; /* or whatever width you want. */
       display: inline-block;
    }
    

    This makes the div take as little space as possible, and its width is defined by the css.

    Expanded answer

    To make the buttons fixed widths do the following :

    #innerbox input
    {
       width:150px; /* or whatever width you want. */
       max-width:150px; /* or whatever width you want. */
    }
    

    However, you should be aware that as the size of the text changes, so does the space needed to display it. As such, it's natural that the containers need to expand. You should perhaps review what you are trying to do; and maybe have some predefined classes that you alter on the fly using javascript to ensure the content placement is perfect.