I use below css to align text in the middle and left when multi-line, but how to align text in the center and center when one line?
.my-text { border: 1px solid black; width: 400px; height: 160px; vertical-align: middle; display: table-cell; overflow: hidden; line-height: 20px; padding: 20px; }
<div class="my-text"> carpe diem </div> <div class="my-text"> carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem </div>
<span>
inline-block
left
.my-text { border: 1px solid black; width: 400px; height: 160px; vertical-align: middle; display: table-cell; overflow: hidden; line-height: 20px; text-align: center; padding: 10px; } .my-text span { display: inline-block; vertical-align: top; text-align: left; }
<div class="my-text"> <span>carpe diem</span> </div> <div class="my-text"> <span>carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem carpe diem</span> </div>
I would recommend using a jQuery solution:
$(".my-text").keypress(function() { if($(this).val().length >= 50) { $(this).css("text-align", "left"); } else { $(this).css("text-align", "center"); } });
, , , , .
Source: https://habr.com/ru/post/1675676/More articles:How to select row-based columns with dplyr - rHow to add everything using java threads? - javaHow to delete all "Values" in RStudio? - delete-filePowerShell displays strange characters after updating Creators - powershellng-change does not work after clicking on each switch in the list - javascriptVuejs 2: how to make string data - javascriptFlutter: Переместите диалог вверх, чтобы освободить место для мягкой клавиатуры? - flutterSonar maven module: does the same project key for all modules not work? - mavenChanging the font size in the source data in an angular2 project - cssИдентификация имени пользователя и пароля для службы WCF за брандмауэром DMZ - authenticationAll Articles