tags:

views:

43

answers:

3

Consider the following markup:

<!DOCTYPE html>
<html>
    <head>
        <title>Test Page</title>
        <link href="screen.css" rel="stylesheet" />
    </head>
    <body>
        <h1>Test</h1>
        <h3>Description</h3>
    </body>
</html>

And the CSS:

h3{
    margin-top: -25px;
}

Now, I want the H3 to have a margin-left of however long H1 is, and it is consistently 20px away. So, if I have a H1 block of 200px long, then H3 would have a margin-left of 220px, and so on and so forth. How would I do this?

+4  A: 

I think what you actually want is:

h1 {
  display: inline;
}

h3 {
  display: inline;
  margin-left: 20px;
}
Dave Ward
Yes, this will work much better, just make sure you put a `<br />` after the line if there is more text below it, or even try using inline-block instead of plain inline.
animuson
Worked, thanks!
Ethan Turkeltaub
A: 

Doesnt this do what you want?

h1 {
   float:left;
}
h3 {
   margin:0 0 0 20px;
   float:left;
}
Greenie
A: 

If the h3 should be in the line below the H1, but still right to the H3 (did you mean that?), then I have a (maybe non optimal) solution, that works for me:

        #title {
            float:left;
        }
        #h3wrapper {
            float:left;
        }
        h3 {
            margin-top: -25px;
        }

HTML:

    <h1 id="title">Test</h1>
    <div id="h3wrapper">
        <h1>&nbsp;</h1>
        <h3>Description</h3>
    </div>
Chris Lercher