0

i'm trying to achieve the following (for building a form):

Name: [        ] *

my markup is:

<label>Name:</label>
<input type=text name=name>
<span class=validate></span>

my css is:

label
{
    display:block;
    width:50px;
    float:left;
}
input
{
    float:left;
}
span.validate
{
    display:block;
    background-image:url(img/required.png);
    width:16px;
    height:16px;
}

the problem: the validate-span is positioned to the very left border instead of right to the textbox. what is wrong?

thanks

3
  • wouldnt you want to use display:inline? Commented Jun 10, 2011 at 22:13
  • unquoted attribute values are disgusting - even though html5 allows them Commented Jun 10, 2011 at 22:27
  • @anirudh4444 No, then you cannot set the width and height anymore. Commented Jun 10, 2011 at 23:00

5 Answers 5

3

You are using display: block on your span, so it will automatically go to a new line. You can change it to inline-block or float it as well.

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

2 Comments

Unless he really needs to have the block display, this is over-complicating things.
@DanMan Personally I would add the background image to the parent element, which in my case would probably be li, but I haven´t seen the rest of the code.
1

You need to also add float: left to your span.validate.

See: http://jsfiddle.net/8jDjq/

But, that won't look right if you add another set of the elements underneath: http://jsfiddle.net/8jDjq/2/

To fix that, you need to add clear: both to label: http://jsfiddle.net/8jDjq/3/

Comments

1

You need to float:left the validate span (or reconsider those display:blocks, but I guess they're there for a good reason).

Comments

1

Give the span a float:left too.

Comments

1
span.validate
{
    display:block;
    background-image:url(img/required.png);
    width:16px;
    height:16px;
    float:left;
}

U need float:left; for your span

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.