I have a link labeled Get D1 which I need to center in the middle of the page. I tried text-align:center, but that works on the text itself and doesn't actually center the link in the middle of the page. Does anyone know the css trick for this?
<div id="allds">
    <div id="d1">
        <a href="http://someurl.com" id="d1link">Get D1</a>
    </div>
    <div id="d2">
        content of d2
    </div>
</div>
1) Centering links by putting it inside of a text aligned div. Place the HTML link inside of a div. In the styles for the div, apply text-align:center and make the anchor tag an inline-block (display:inline-block).
To center text using HTML, you can use the <center> tag or use a CSS property.
Set “text-align: center” to the parent element's div to center it using a wrapper or container (also known as a container). In this case, the inside div should be set to display inline block.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With