How can I center this link

#d1 { width:whatever; margin:0 auto; }

If you don't want to specify a width, you need to use an alternate technique.


Here ya go:

#link-container {
    text-align: center;
}
#link {
    background: black;
    color: white;
    display: inline-block;
    padding: 10px;
}

<div id="link-container">
    <a href="#" id="link">This is my link!</a>
</div>

That what you need?


As simple as:

#d1link {display:block;text-align:center}

text-align:center doesn't work on inline elements. An anchor is an inline element by default.

Tags:

Css