Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a div have a fixed size?

Tags:

html

css

fixed

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 the size of font 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.

like image 254
Mike Collins Avatar asked Jan 25 '13 16:01

Mike Collins


People also ask

How do I make my div not expand?

Answer: Use the CSS display Property You can simply use the CSS display property with the value inline-block to make a <div> not larger than its contents (i.e. only expand to as wide as its contents).

How do I fix a box size in HTML?

Using width, max-width and margin: auto; Setting the width of a block-level element will prevent it from stretching out to the edges of its container. Then, you can set the margins to auto, to horizontally center the element within its container.

How do I force a div to full width?

What you could do is set your div to be position: absolute so your div is independent of the rest of the layout. Then say width: 100% to have it fill the screen width. Now just use margin-left: 30px (or whatever px you need) and you should be done.


2 Answers

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.

like image 189
Kami Avatar answered Sep 19 '22 08:09

Kami


you can give it a max-height and max-width in your .css

.fontpixel{max-width:200px; max-height:200px;} 

in addition to your height and width properties

like image 22
Mike Avatar answered Sep 17 '22 08:09

Mike