tags:

views:

88

answers:

4

Consider the following:

<p>
    <b>
        <div style="color:rgb(81,33,244)">Player1</div>
    </b> 
    to overtake 
    <b>
        <div style="color:rgb(187,4,0)">Player2</div>
    </b>
     in 1 hour 20 minutes
</p>

In this Player 1 and Player 2 are shown in different colors, however the 'div' breaks the line and it looks something like:

Player1

to overtake

Player2

in 1 hour 20 minutes

How can I color the players and yet keep them on the same line?

+3  A: 

Use span instead of div

SelflessCoder
+1  A: 

Change your div to span

Also, consider adding class attributes and putting your style information in an external CSS file.

mabwi
+1 for class attributes. The style doesn't need to be in a separate file. Using class names instead of inline styling will help to describe the intent, making the code easier to comprehend. It will provide a centralized definition, which prevents shotgun surgery later, when you decide to change the colors. It also reduces the need for the "b" tags, because you can attach font weight specifications to the class definitions.
Ewan Todd
+7  A: 

Style the b elements.

David Dorward
+1 for noticing that adding extra elements is totally redundant in the example given
Ben James
+11  A: 

Use an inline element such as span rather than a block element such as div. In fact, given that the purpose of the styling seems to be to emphasize player names, I would say em is the most appropriate tag to use:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style type="text/css">
    .status em { font-weight:bold; font-style:normal }
    .player1 { color:rgb(81,33,244) }
    .player2 { color:rgb(187,4,0) }
</style>
</head>
<body>

    <p class="status"><em class="player1">Player1</em> to overtake <em
        class="player2">Player2</em> in 1 hour 20 minutes</p>

</body>
</html>
Sinan Ünür