CSS pseudo-element input-placeholder::after to show with or without value in text box

后端 未结 2 1779
悲&欢浪女
悲&欢浪女 2020-12-11 18:10

I\'m trying to get some UI flagging on form elements for the user after validation to work using the placeholder pseudo elements (starting with text boxes). What I want is t

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 18:15

    Once the user starts typing in the input box, the browser is going to hide the placeholder, and with it, your X.

    Unfortunately, you can't place it next to the input with :after, because that is not currently supported.

    If you're attached to having the X next to the input, I would suggest placing a div next to input, and adding/showing the X when necessary.

    Otherwise, I would move the X like you move the placeholder.

    On focus, you set the placeholder to " " and give the label a color. This makes the label visible to the user and keeps a placeholder present, that you X can be :after. You could instead, set the placeholder to "", which would remove your X from the input box, but add an :after or :before to you label, and display the X there.

    CSS to display X after label

    .input-invalid.input-focused label:after,
    .input-invalid.input-has-value label:after {
        content: "  \2716";
    }
    

提交回复
热议问题