How to flip vertically all the letter at even positions in input element?

微笑、不失礼 提交于 2019-12-11 09:57:02

问题


I need to flip vertically all the letter at even positions while keeping the letters at the odd positions intact in element. Now I'm using this css style: -webkit-transform: rotateX(180deg). But it flips the whole text in input element.

What should I do else? Or maybe it's possible in another element, not an input?


回答1:


At this time, there is no way to select the letters within an element (or within the value of an element). Theoretically, a :nth-letter() pseudo-element would do the trick, but this doesn't exist.

You can however use JavaScript to take the value of the input, explode the string by character, wrap span elements around each character, put these elements into some other container, and do the transformation on span:nth-of-type(even).

CSS

#container > span {
    display: inline-block;
}
#container > span:nth-of-type(even) {
    color: purple;
    -webkit-transform: rotate(180deg);
    -moz-transform: rotate(180deg);
    -ms-transform: rotate(180deg);
    transform: rotate(180deg);
}

JavaScript

$('#name').keyup(function () {
    'use strict';

    $('#container').empty();
    $(this).val().split('').forEach(function (v) {
        $('#container').append('<span>' + v + '</span>');
    });

});

I've made a jsFiddle to demonstrate this.



来源:https://stackoverflow.com/questions/17817878/how-to-flip-vertically-all-the-letter-at-even-positions-in-input-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!