1

So when you put a <div> within a <div>, it assumes it should be all the way wide.

I have an <a> element, and the only way to get it to display correctly is to give it display: block. However, giving it this attribute makes it behave like the <div> does by default. It makes it all the way wide.

I don't have a specific width I want it (just so the text and padding fit) but I don't want it to be all the way wide.

Is there an attribute/workaround for this?

I would post some code but it's a simple enough idea - just say so if you'd like to see some code.

2
  • 2
    Please show some code, your question is also kind of ambiguous. Commented Nov 18, 2010 at 0:57
  • "and the only way to get it to display correctly" - you need to elaborate on this. what is going wrong? Commented Nov 18, 2010 at 1:04

4 Answers 4

1

One way is to use display: inline-block;, but there are only a few times when that is really necessary.

Post some code so we can tell what is causing your anchors to disappear or do whatever undesirable behavior it is.

Oh, it would be helpful to know what you want them to look like.

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

1 Comment

I'm sure inline-block is what he wants -- +1.If anyone still cares about IE6, then make sure the element is inline by default. <div>s won't work with inline block in IE6, but if you use a <span> instead it will.
0

You're looking for display: inline.

If you really need display: block, you can make it "shrink-wrap" by setting float: left.

Comments

0

Try using

display:inline

Comments

0

You can float it:

div { overflow:auto; }
a { float:left; }


<div>
    <a> Link </a>
</div>

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.