最大宽度会自动更改其值

发布于 2025-02-04 08:53:53 字数 512 浏览 1 评论 0原文

我有一个关于最大宽度的问题,为什么它会自行更改依赖范围。

这是我的代码:

div {
  height: 100px;
  max-width: 500px;
  background-color: powderblue;
}

因此,最大宽度为500px,但是当我调整显示大小时,max宽度值更改。

在下图中,我的结果大小为150px宽度: 在此处输入映像

您可以看到我的部门宽度实际上是150px,而不是500px 最大宽度值。

那么,为什么最大宽度自动更改其值?说显示宽度是否小于最大宽度,那么它与屏幕的宽度匹配是正确的吗?

干杯

I have a question about max-width and why does it change itself Dependeds on display width.

here is my code:

div {
  height: 100px;
  max-width: 500px;
  background-color: powderblue;
}

So the max-width is 500px but when I resize my display size, max-width value changes.

In the image below I have a result size with 150px width:
enter image description here

as you can see my division width is actually 150px, not 500px which was my max-width value.

So why does max-width automatically changed its value? Is it correct to say if the display width is smaller than max-width, then it matches the width of screen?

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

秋凉 2025-02-11 08:53:53

使用最大宽度,您告诉浏览器该元素的最大宽度是什么。
如果元素的最大宽度大于500px,它将使元素的高度更大。

使用最大宽度,您设置了最大宽度,因此它可能较小,但不大于500px

with max-width, you tell the browser what is max-width of the element.
if the max-width of the element is bigger than 500px it will make the height of the element bigger.

with max-width, you set the maximum width and therefore it can be smaller but not bigger than 500px

2025-02-11 08:53:53

最大宽度确定元素可以拥有的最大宽度。这意味着您的元素可以获得每个宽度的宽度小于最大宽度。
您应该编写最小宽度以指定您期望的最小宽度。

Min-width:500px;

并为确切的值写宽度

Max-width determines maximum width which an element can have. It means your element can get every width less than your max-width.
You should write min-width to specify minimum width that you expect.

Min-width:500px;

And write width for exact value.

琉璃繁缕 2025-02-11 08:53:53

最大宽度告诉元素不能超过该点,最小宽度告诉元素不能低于该值,因此,如果您希望元素不缩小或降低其宽度,请使用最小宽度

Max-width tells that the element cant exceed that point, min-width tells that the element cant be below the value, therefore use min-width if you want your element not to shrink or lower its width

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文