在平常的开发过程中,对于text-align一般用到的是left,center,right,这三个属性都不会陌生。然而,对于justify的使用我却是很陌生。首先有个比较简单的例子。
如下代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> span{ width: 60px; text-align: justify; float: left; } span:after{ content:\'.\'; width: 100%; display: inline-block; overflow: hidden; height: 0; } input{ width: 100px; } </style> </head> <body> <div class="demo"> <span>昵称</span>:<input type="text" style = \'width: 100px\'><br><br> <span>电子邮箱</span>:<input type="email" style = \'width: 100px;\'> </div> </body> </html>
效果图如下:
此处注意冒号“:”必须在<span>的外面。否则不生效。