5

I am styling a page where I have only been given access to the CSS files.

I am looking to alter the style of an input element if it's value is not blank.

Here's what I have so far...

<input id="myInput" type="text" name="myInput" autocomplete="off" placeholder="Enter your Card Number">

and

input {
    font-style:italic;  
}

input:not([value='']) {
    font-style:normal;  
}

This doesn't work though as the text is never italicised.

Is it even possible to achieve this taking into consideration I can only edit the CSS file.?

2
  • About the only solution you have here is to change it on :focus. But of course that won't be styled as soon as the input is blurred. You'll need to use JavaScript to achieve what you're trying to do. Commented Apr 9, 2013 at 15:15
  • Your code works (in Chrome at least) but only works if the value is set when the page loads since there's no change event to bind to. Commented Apr 9, 2013 at 15:16

3 Answers 3

4

Looks like you're using HTML5...if so just edit your PLACEHOLDER tag

::-webkit-input-placeholder {font-style: italic} /*Chrome */
:-moz-placeholder {font-style: italic} /*ff*/
:-ms-input-placeholder {font-style: italic} /*ie latest */

JSFIDDLE:

http://jsfiddle.net/Riskbreaker/wCff9/

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe you want this:

input::-webkit-input-placeholder {
    font-style: italic;
}
input[type=text] {   
    font-style:normal;  
}

http://jsfiddle.net/Le6XM/1/

Comments

0

I think that what you looking to do is style the place holder. Give this a try!

        input {
            font-style:italic;  
        }

        ::-webkit-input-placeholder {
            font-style:normal;  
        }

        :-moz-placeholder { /* Firefox 18- */
           font-style:normal;   
        }

        ::-moz-placeholder {  /* Firefox 19+ */
           font-style:normal;  
        }

        :-ms-input-placeholder {  
           font-style:normal;   
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.