I have forms on a webpage that have a great style issue.
One of the requirements for forms is that whenever a form contains an error, an error message should appear between the label and the input field. Whenever there is no error, there should only be a label and an input field. See the picture below:

The problem is that whenever an error message appears, the input field is shifted down, and the input fields on the same line are no longer aligned with each other. I need to enter the fields horizontally apart for alignment. In other words, it should look like this (ignore the silly watermark):

Here are the basic things I need to find out:
- Correct display of the error message between the label and the input field.
- Always keep input fields in a straight line
- Keep the label, error message and input field in the same div with each other (they cannot be on separate lines)
- Perform all three of the above actions at the same time.
This is HTML:
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap@3.3.5" data-semver="3.3.5" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="row">
<div class="col-xs-4">
<div>Label for first input field!</div>
<div class="error">Label for first error message!</div>
<input type="text"/>
</div>
<div class="col-xs-4">
<div>Label for second input field!</div>
<div class="error">Label for second error message!</div>
<input type="text"/>
</div>
<div class="col-xs-4">
<div>Label for third input field!</div>
<input type="text"/>
</div>
</div>
</body>
</html>
This is CSS:
.error{
color:red;
}
This is a link to the plunker: http://plnkr.co/edit/i0RR3XXeevh03TtoBP1M?p=preview
EDIT
This question only concerns the style of these input fields. This is not the code I'm trying to modify, but rather a minimal example that reflects the problem I'm trying to solve. No need to think about the mechanisms by which error messages appear, but rather about style.
source
share