【问题标题】:Why does setting width in a CSS class attached to my labels not change their width? [duplicate]为什么在附加到我的标签的 CSS 类中设置宽度不会改变它们的宽度? [复制]
【发布时间】:2015-08-10 21:53:36
【问题描述】:

我有这个 html:

<label class="fixedwidthlbl" for="city">City</label>
<input type="text" name="city" id="city">
<br/>
<label class="fixedwidthlbl" for="state">State</label>
<input type="text" name="state" id="state">
<br/>
<label class="fixedwidthlbl" for="yearin">Year Arrived</label>
<input type="text" name="yearin" id="yearin">
<br/>
<label class="fixedwidthlbl" for="yearout">Year Departed</label>
<input type="text" name="yearout" id="yearout">
<br/>
<input type="submit" name="insertdocument" id="insertdocument" value="Add Place Lived">

...还有这个 CSS:

.fixedwidthlbl {
    width: 320px;
    padding: 2 px;  
}

然而“fixedwidthlbl”类对我的标签没有影响。

我有一个小提琴here

我的 HTML 和/或 CSS 有什么问题?

【问题讨论】:

    标签: html css


    【解决方案1】:

    标签是内联元素。要给他们一个宽度,你需要给他们display: inline-block;

    .fixedwidthlbl {
        width: 320px;
        padding: 2px;   
        display: inline-block;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-18
      • 1970-01-01
      • 2014-12-27
      • 2020-07-20
      • 1970-01-01
      • 2019-02-18
      • 2018-01-15
      相关资源
      最近更新 更多