我有这个HTML代码:
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
<span>Proper format "[email protected]"</span>
</div>
我已经在div上配置了“ text-align:center”,但不幸的span
是,文本也居中(请参见下图)。我需要span
靠近它而不是居中。
您可能应该将父元素居中div
放置,而不是放在表单内部:
.center-form {
text-align: center;
}
.center-form form {
display: inline-block;
text-align: left;
}
<div class="center-form">
<form action="">
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
</div>
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
<span>Proper format "[email protected]"</span>
</div>
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
</div>
<button>Submit</button>
</form>
</div>
或者,如果您不想span
影响表格位置,请使用position: absolute
:
.center-form {
text-align: center;
}
.center-form form {
display: inline-block;
text-align: left;
}
.center-form form div {
position: relative;
}
.center-form form div span {
position: absolute;
left: 100%;
top: 0;
/* for demo */
white-space: nowrap;
}
<div class="center-form">
<form action="">
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
</div>
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
<span>Proper format "[email protected]"</span>
</div>
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
</div>
<button>Submit</button>
</form>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句