Centering the placeholder caret in contentEditable element
问题 I have the following: http://jsfiddle.net/mb76koj3/. [contentEditable=true]:empty::before{ content:attr(data-ph); color: #CCC; text-align: center; } h1 { text-align: center; } <h1 contenteditable="true" data-ph="Name"></h1> The problem is the <h1> is centered, but the placeholder caret isn't centered (until you start typing). The caret is on the left side, how can I change this? 回答1: Not an ideal solution but we can fake the effect by applying a padding-left of 50% to the :empty element to