1

Simply put the question is - is there a way to align link text within an action link vertically?

I need to make a button-looking Html.ActionLink control. There is a reasonably good example at Html.ActionLink as a button or an image, not a link

I have implemented this approach, however, I need not just an "image" button, but an image button with a text shown on it, and this text depends on view model's state, so that I cannot simply put it on an image.

Here is what I have (Razor):

@Html.ActionLink(@commitee.Name, "CommiteePage", "SecureFolder",
new { commiteeName = commitee.Name, page = 1 },
new { @class = "commiteeButton" })

and CSS:

a.commiteeButton {
background: transparent url("../Images/BlueButton.png") no-repeat top left;
display: block;
width: 304px;
height: 50px;
color: white;
text-decoration: none;
font: normal 14px Arial;
text-align: center;
margin-bottom: 10px;

}

The result is OK, but: the text of a link is located on the top of an image, and not in its middle (vertically). I do not know how to center link text vertically, so that it can be located right in the center of an image.

Of course, there can be another approach (see below) but maybe it is still possible with approach mentioned above?

<a class="nonunderlinedlink" href="@Url.Action("CommiteePage", "SecureFolder", new { commiteeName=commitee.Name, page = 1 }, null)">
    <div class="commiteeButton">
        <p class="pstyle">@commitee.Name</p>
    </div>
</a>
Community
  • 1
  • 1
freeliner
  • 49
  • 3
  • 12

3 Answers3

1

Try the following changes in your css

a.commiteeButton {
background: transparent url("../Images/BlueButton.png") no-repeat top left;
display: block;
width: 304px;
height: 50px;
color: white;
text-decoration: none;
font: normal 14px Arial;
text-align: center;
margin-bottom: 10px;
display: table-cell;
vertical-align: middle;
}
Razib
  • 126
  • 5
0

Rex (see comments to my question above) suggested putting padding-top to CSS, that has resolved issue without causing collateral layout problems.

Thank you all for your quick reply!

freeliner
  • 49
  • 3
  • 12
0

I know it's a bit late but you could also use line-height: 50px; to center your text vertically

HoXa
  • 153
  • 9