How to make a div have a fixed size?

前端 未结 6 1883
北恋
北恋 2020-12-13 17:16

I made a site so when you click the button 30px it changes the font inside the div.

I have a ul inside it with the bottons. When I change t

6条回答
  •  独厮守ぢ
    2020-12-13 18:00

    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.

提交回复
热议问题