user776676
user776676

Reputation: 4385

ASP.NET: How do I right align an image in aspx?

I have an image that links to my homepage. Is there an attribute that I can specify to right align the image within its column (my code below)? I don't want to use anything more complicated than using just an attribute. Thanks.

Please note: I just want to right align ONLY this image. Not the whole div.

<div class="leftCol">
<asp:HyperLink ID="HyperLink" runat="server" ImageUrl="~/home.jpg" NavigateUrl="http://myhomepage.edu">HyperLink</asp:HyperLink>
</div>

Upvotes: 2

Views: 12396

Answers (3)

afaf12
afaf12

Reputation: 5436

<style type="text/css">
.link
{
 float: right;   
}
</style>

<div>
    <asp:HyperLink ID="HyperLink1" runat="server" ImageUrl="~/logo.png" CssClass="link">HyperLink</asp:HyperLink>
</div>
</form>

Upvotes: 1

Dennis Traub
Dennis Traub

Reputation: 51684

<div class="leftCol">
    <div>
        Stuff that should align left
    </div>
    <div style="float:right; display:inline;">
        <asp:HyperLink ID="HyperLink" runat="server" ImageUrl="~/home.jpg"
                   NavigateUrl="http://myhomepage.edu">HyperLink</asp:HyperLink>
    </div>
</div>

Upvotes: 4

Kyle Trauberman
Kyle Trauberman

Reputation: 25694

Use CSS:

<style type="text/css">
    .leftCol a img { float: right; }
</style>
<div class="leftCol">
    some text here <asp:HyperLink ID="HyperLink" runat="server" ImageUrl="~/home.jpg" NavigateUrl="http://myhomepage.edu">HyperLink</asp:HyperLink>
</div>

or (better)

<style type="text/css">
    .rightAlign { float: right; }
</style>
<div class="leftCol">
    some text here <asp:HyperLink CssClass="rightAlign" ID="HyperLink" runat="server" ImageUrl="~/home.jpg" NavigateUrl="http://myhomepage.edu">HyperLink</asp:HyperLink>
</div>

Its recommended to place the CSS in your stylesheet file, but for demonstration purposes, I included the style inline here.

Upvotes: 4

Related Questions