如何使一个div有一个固定的大小? [英] How to make a div have a fixed size?

查看:415
本文介绍了如何使一个div有一个固定的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个网站,当您点击按钮30px时,它会更改 div 内的字体。

我在里面有一个 ul 与bottons。当我改变字体的大小时, div 会展开,导航按钮也随之移动。

我使它保持固定,但字体仍然可以改变。

解决方案

尝试以下CSS

#innerbox
{
width:250px; / *或任何你想要的宽度。 * /
最大宽度:250px; / *或任何你想要的宽度。 * /
display:inline-block;
}

这使得div占用尽可能小的空间,并且宽度被定义由CSS。



//扩展回答



要使按钮固定宽度,请执行以下操作:

#innerbox input
{
width:150px; / *或任何你想要的宽度。 * /
最大宽度:150px; / *或任何你想要的宽度。 * /
}

但是,您应该知道,随着文本大小的变化,你需要更多的空间来显示它。因此,容器需要扩展是很自然的。你也许应该回顾一下你想要做的事情;并可能有一些预定义的类,您可以使用JavaScript改变它们以确保内容放置是完美的。


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.

解决方案

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 it's 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, you need more space 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.

这篇关于如何使一个div有一个固定的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆