0

I have a relativly straightforward setup in that I have a form with a label next to a text box. I also have an image that is hidden unless a validation check is failed. This is what it looks like before the validation check:

enter image description here

Here is what it looks like if the validation check is failed:

enter image description here

As you can see in the first image the label and text box are nicely aligned. However, in the second one the text box appears to get pushed down by around 10px.

This is where the problem lies. I have tried a whole host of fixes to sort this issue out but I just can get everything to stay where it is (and be in line).

Here is the HTML code:

<ol class="forms">
    <li>
        <label for="Name">Name*</label>
        <input type="text" name="name" id="Name" />
        <img src="/Graphics/Other/Name-Alert.png" class="validateImage" id="Name-Image-Validation">
    </li>
...
...

Here is the corresponding CSS code:

form ol { list-style-type:none; }

form    { text-align:left; margin:0px;  }

label   { 
        float: left; width: 85px; margin-top:5px;
        text-align:left; display:block; background:none;
        }

input   { 
        width: 250px; margin:0 0 16px 10px;
        border:1px #bbb solid; padding:5px; background:none; color:#FFF;
        }

select { margin-bottom:20px; }

.clear  { clear:both; }

.validateImage  { display:none; }

Finally here is the small piece of javascript that I use to validate the form:

var x=document.forms["email_form"]["name"].value;
if (x==null || x=="")
{
    document.getElementById('Name-Image-Validation').style.display='inline';
    return false;
}
else
{
    document.getElementById('Name-Image-Validation').style.display='none';
}

Please can someone help me fix this issue?

4

2 回答 2

3

这是因为默认情况下 img 标签是顶部对齐的,试试这个:

.validateImage  { display:none; vertical-align: middle; }
于 2012-05-25T10:42:36.433 回答
0

只是为了让你有一些可以接受的东西:

您是否尝试过添加#Name-Image-Validation { position:relative; top:10px }

于 2012-05-25T10:32:28.820 回答