将字段集图例对齐在中心

时间:2014-04-29 04:38:35

标签: html css

HTML

<fieldset class="Fieldset">
    <legend class="Legend" id="Legend">Add</legend>
    ...

CSS

.Fieldset
{
    border: 1px solid #CCC;
    border-radius: 5px;
    padding: 10px;
}

.Legend
{
    border: medium none;
    left: 40%;
    margin: 0 auto;
    padding: 0 10px;
    position: relative;
    text-align: center;
    width: auto;
    color: #3C6EAC;
    font-size: 18px;
    font-weight: bold;
}

Firefox传奇中,在中心对齐。但是在Chrome它没有。

4 个答案:

答案 0 :(得分:2)

只需从left:40%删除.Legendtext-align即可完成剩下的工作。

.Legend
{
    border: medium none;
    margin: 0 auto;
    padding: 0 10px;
    position: relative;
    text-align: center;
    width: auto;
    color: #3C6EAC;
    font-size: 18px;
    font-weight: bold;
}

Demo Here

答案 1 :(得分:1)

添加此CSS,删除margin :auto&amp; left:40%然后添加margin-left:40%

Demo Here

.Fieldset
{
    border: 1px solid #CCC;
    border-radius: 5px;
    padding: 10px;
}

.Legend
{
    border: medium none;
    margin-left: 40%;
    padding: 0 10px;
    position: relative;
    text-align: center;
    width: auto;
    color: #3C6EAC;
    font-size: 18px;
    font-weight: bold;
}

答案 2 :(得分:0)

  • margin:auto;正在完成所有工作
  • text-align:center;不执行任何操作
  • left:40%;干扰margin:auto;

运行此示例:

fieldset {
  border: 1px solid #CCC;
  border-radius: 5px;
  padding: 10px;
}

legend {
  margin: auto;
  padding: 0 10px;
  color: #3C6EAC;
  font-size: 18px;
  font-weight: bold;
}
<fieldset>
  <legend>Long title long title long title long title </legend>
</fieldset>

答案 3 :(得分:0)

这篇文章很有用。但是,我设法仅通过text-align:center将图例与中心对齐,如下所示。

legend {
  text-align:center;
}

相同的StackBlitz示例在这里:https://stackblitz.com/edit/angular-nzmpzi