Html 设置div的最小宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6042733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:39:40  来源:igfitidea点击:

setting minimum width of div

html

提问by user517406

I have a page with many different objects of different widths. I am not setting the width of the div that the objects are within as I want it to be able to expand to include whatever items are within it. But I do want the div to have a minimum width. Is it possible to do this?

我有一个页面,其中包含许多不同宽度的不同对象。我没有设置对象所在的 div 的宽度,因为我希望它能够扩展以包含其中的任何项目。但我确实希望 div 具有最小宽度。是否有可能做到这一点?

回答by Marwelln

It is very possible. Just use CSS min-width. The MDN pagehas details.

这是很有可能的。只需使用 CSS min-widthMDN 页面有详细信息。

回答by Kerem Baydo?an

Use CSS:

使用 CSS:

min-width

Definition and Usage

定义和用法

The min-width property sets the minimum width of an element. Note: The min-width property does not include padding, borders, or margins!

min-width 属性设置元素的最小宽度。注意: min-width 属性不包括内边距、边框或边距!

like

喜欢

#example {
  width: 150px;
  min-width: 100px;
  max-width: 200px;
}

回答by Valentin Despa

Checkout some real documentation regarding this, Mozilla Developer Network.

查看有关此的一些真实文档,Mozilla 开发人员网络

回答by Xavier

this is achievable via css;

这可以通过 css 实现;

element
{
    min-width:100px;
}