asp.net - 带有 CSS 的 ImageButton 上的文本

标签 asp.net html css imagebutton

我希望在具有背景的按钮上显示一些文本。然而,这不能与绝对位置相关联,因为我将在屏幕的多个部分重复使用此按钮,仅更改我正在显示的文本。

目前我有以下内容:-

<div class="ReportButton">
  <div class="ReportImageButton">
      <asp:Image runat="server" ImageUrl="Images/button_arrow.png" ID="ImgReportButton" ImageAlign="AbsMiddle" Height="40px" />
  </div>
  <div class="ReportImageButtonText">Text Goes Here</div>
</div>

和 CSS:

.ReportButton {
  width: 100px;
  height: 40px;
}

.ReportImageButton {
  height: 40px;
  position: absolute;
}

.ReportImageButtonText {
  height: 40px;
  z-index: 100;
  position: absolute;
  color: white;
  font-size: 12px;
  font-weight: bold;
  left: 330px;
  top: 330px;
}

这很好用,但是我希望尽可能避免使用绝对位置,原因我之前已经说过。

这可能吗?

最佳答案

您不能使用 ReportButton 的 CSS 来做到这一点吗?

.ReportButton {
    width: 100px;
    height: 40px;
    background: url("/images/button-bg.png") no-repeat top left;
    cursor: pointer;
}

然后,只需:

<div class="ReportButton" onclick="doSomething();" >
    Text Goes Here
</div>

关于asp.net - 带有 CSS 的 ImageButton 上的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16415717/

相关文章:

ASP.NET 和 HTML5 视频播放时间

C# 和 ASP.NET 自定义属性特性并确定属性是否已更改

asp.net - Bootstrap 梅辛 Telerik RadGrid

javascript - 使用 jQuery 的 Ajax 结果中的选择器问题

javascript - 如何模拟文本区域中的后退标签

html - 使用最新协议(protocol)的 WebSocket 服务器 (hybi 10)

css - 将 css 变量与 scss 变暗和变亮过滤器一起使用

python - 使用 Python 在 HTML 中显示选项卡式消息

c# - 地址类型的生效日期和到期日期

PHP:将二维数组显示为具有模式形式的表格?