Frage

I am creating a error tooltip, which will be visible if the user hovers on the input field. This tooltip is almost completed now I just need to make it vertically aligned with respect to the input field. I tried many ways but I failed to accomplish.

Fiddle

input {
    height: 30px;
    width: 278px;
}
/* Error Validations css */
.error-field {
    position: relative;
    overflow: visible;
    display: inline-block;
}
.error-field > input:focus {
    background-color: white;
    outline: none;
}
.error-field > input {
    background-color: #ffdedf;
    border: 1px solid red !important;
    border-radius: 3px;
}
.error-field:hover {
    /* IE Fix */
}
.error-field:hover:after {
    content: attr(data-error);
    display: inline-block;
    vertical-align: middle;
    padding: 3px;
    position: absolute;
    top: 50%;
    margin-top: -10px;
    z-index: 1;
    display: block;
    background-color: #ffdd67;
    left:100%;
    width: 200px;
    line-height: 15px;
    border: 1px solid #b07317;
    margin-left: 15px;
    border-radius: 3px;
    -ms-border-radius: 3px;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
}

I am trying to avoid javascript (or prototype) but if it is impossible using just css then I am good to go with this.

The browsers I am supporting are IE9, chrome and firefox.

Any help will be appreciated.

War es hilfreich?

Lösung

Instead of a negative margin-top use a negative translateY (supported also on IE9)
http://jsfiddle.net/x9uW5/1/

.error-field:hover:after {
    ...
    position: absolute;
    top: 50%;
    -webkit-transform: translate(0, -50%);
    -moz-transform: translate(0, -50%);
    -ms-transform: translate(0, -50%);
    transform: translate(0, -50%);
}

This will always ensure a middle alignment, no matter how much text is contained in the tooltip

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top