tags:

views:

458

answers:

3

For some basic layout work I'm doing, I'd like links that immediately follow a price to always be shown on the same line as the price. The price text is wrapped in a <span class="price"> tag while the link uses the buy-link class as in <a href="/buy" class="buy-link">Buy Now</a>.

I'm looking for CSS that will automatically prevent line breaking between the span and a tag but I'm either missing something or it can't be done. I can easily prevent line breaks within the two tags - but not between them.

I want to avoid wrapping both tags in a span with a white-space: nowrap manually and use pure CSS if possible.

Update: The HTML looks something like the following. It's not the real code but very similar.

<style>
    .price{ font-weight: bold; }
    .buy-link{ color: green; }
</style>

<span class="price">$50</span> <a href="/buy" class="buy-link">Buy Now</a>

If the link happens to be near the page edge - or block edge in a <div> or <table> browsers will wrap the Buy Now link to the next line. Separating the two elements.

+1  A: 

As <span> element is meant for inline grouping by default, the price and link should be on same line.

I guess some CSS is over-riding it.

N 1.1
A: 

Can't you nest the anchor inside the span, like

<span class="price"><a href="/buy" class="guy-link">Buy Now</a>&nbsp;Only $19.95!</span>

then set the span to white-space: nowrap?

Robusto
how can it be nested? price should be in `span` and buy-link in `a`.
N 1.1
@nvl: just look at it. Both those requirements are met. Correct CSS can handle the styling of both. I will edit to show span text.
Robusto
@Robusto: This **is** possible. But we cannot force our solution to OP :D. This is OP's preference (to make price hyperlink too).
N 1.1
@nvl: That's not how I read it. He says the price is in a span and the item is in an anchor tag.
Robusto
+1  A: 
<span class="price">$50</span>&nbsp;<a href="/buy" class="buy-link">Buy Now</a>
graphicdivine