为什么max-width不能用于此?

egr*_*103 16 html css button

使用普通的旧CSS,为什么"max-width"不能用于以下方面:

button {
  text-align: center;
  max-width: 540px;
  height: auto;
  display: block;
  padding: 10px 0;
  margin: 0 auto;
  border: none;
}
Run Code Online (Sandbox Code Playgroud)

这个元素的包装:

#wrapper {
  max-width: 1024px;
  overflow: hidden;
  position: relative;
  margin: 0 auto;
  padding: 0 50px;
  text-align: center;
}
Run Code Online (Sandbox Code Playgroud)

编辑

代码添加到jsfiddle:http://jsfiddle.net/BXdrG/

Mic*_*umo 29

为了max-width正常工作,您的元素首先需要一定的width.使用100%来达到你想要的效果.看这里:

http://jsfiddle.net/QsHa9/


egr*_*103 22

好吧,我误解了它的用法.为了得到一个不会伸展到大尺寸的流畅按钮,我添加了以下内容:

width:100%;
max-width: 540px;
Run Code Online (Sandbox Code Playgroud)

谢谢评论者!


Mil*_*ern 5

button {
  text-align: center;
  max-width: 540px;
  height: auto;
  display: block;
  padding: 10px 0;
  margin: 0 auto;
  border: none;

  width:100%; /* you forgot this */
}
Run Code Online (Sandbox Code Playgroud)