2

My problem is styling a server generated validation message, the padding displays the background color before the message is generated, when the padding is removed, the background-color is no longer visible.

I want to have the padding in the code for styling purposes, but without showing any content or background color as this is a validation message, here is the code as follows:

<div class="validate">@Html.ValidationMessageFor(m => m.Email)</div>

css:

.validate {color:#ecf0f1;font-size:.9em;background-color:#e74c3c;padding:10px;}

Before validation:

before

What occurs after the validation shows up:

after

What I want before validation:

what i want

3
  • 2
    In site.css change the .field-validation-error to your required style. You do not need to create a new class. Doing so you won't need to worry about your problem Commented Apr 2, 2014 at 5:01
  • ok thank you for that, I did this but now the background color does not span the whole div, as seen in the screenshot. Commented Apr 2, 2014 at 5:07
  • added a demo fiddle for your reference. Please share the rendered HTML of your code if still not works! Commented Apr 2, 2014 at 5:41

2 Answers 2

1

that's because of the Div that you've ValidationMessage inside and CSS applied on that div.

try this CSS:

.validate:not(:empty)
 {
   color:#ecf0f1;
   font-size:.9em;
   background-color:#e74c3c;
   padding:10px;
 }

DEMO FIDDLE

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

2 Comments

:not :empty, did not do anything visually, is there something missing?
oops... please note: it's :not(:empty) and not :not :empty
0

Solved with modifying the class:

.field-validation-error

By adding:

{display: inline-block;  width:100%;
color:#ecf0f1;
font-size:.9em;
background-color:#e74c3c;
padding:10px;}

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.