开发者

css - way to not have width assume 100%?

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 w开发者_StackOverfloway 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.


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.


You're looking for display: inline.

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


Try using

display:inline


You can float it:

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜