【问题标题】:How to display text on image using MVC approach如何使用 MVC 方法在图像上显示文本
【发布时间】:2015-05-04 14:15:33
【问题描述】:

我是 mvc5 的新手,我必须在图像上显示标签(不在内部,如果可能的话,请告诉我这样做的方法)。

我的标签包含一个文本,我想在该图像上显示该文本。 请看下面(我的尝试):

<li class="odd">
    <a class="dropdown-toggle" id="btn_dashboard" onclick="return BackToHome();">
        <span><label class="LabelCSSTop">@DateTime.Now.Day  </label>  </span> //This is my text which dislay above the image (not on the image, I also want to increase its defaut size)
        <span class="head-icon head-dashboard" style="margin-top: -15px;"></span> //This displays the image below the text displayed in line above.
    </a>
</li>

是的,当然它会在文本下方显示图像(我的意思是 DateTime.Now.Day),因为编写的代码是这样做的。但是有什么办法可以让我能够在图像的中心显示该文本? (尺寸大于默认尺寸)

【问题讨论】:

  • 我不明白。你的形象在哪里?由 CSS 提供?在那种情况下,您可以将图像设置为 div 的背景并写入 div 吗?还是你在说水印?
  • @rism 不,它与水印无关。是的,我通过 css 提供。您能否解释一下将图像设置为 div 的背景并写入 div 是什么意思。在下面详细说明,以便我通过正确理解将其标记为答案?谢谢

标签: css asp.net asp.net-mvc razor asp.net-mvc-5


【解决方案1】:

所以假设我们在同一个页面上,你的内容可以有一个 div:

<div class="divination"> 
   <span><label class="LabelCSSTop">@DateTime.Now.Day  </label>  </span>
</div>

然后在你的 CSS 中有一个 divination 类:

.divination{
  height: 50px; // height of div
  display: table-cell; // makes the div behave like a table cell for text content
  vertical-align: middle; // vertically aligns the text content not the image
  background-image: url(../images/divbg.png) // sets the background image. Note: path  is relative to the css file
}

您需要确保 LabelCSSTop 类不会覆盖 div 内容设置。

【讨论】:

  • 感谢它对我有用,但我也想增加文本的大小(正如我在问题中所讨论的那样)我正在使用标签显示。但我找不到任何字体大小属性。你能帮帮我吗
  • 更改 LabelCSSTop 类的 CSS 以设置 font-size:16px 等
  • 我已经尝试过了,但是不行。请看 = .LabelCSSTop {font-size:16px; } 它仍然显示相同的大小。
  • 右键单击 Chrome 中的元素并选择检查元素。然后在样式选项卡上查看并查看正在应用的样式以及从何处应用并根据需要进行更改。如果这没有帮助,那么您需要打开另一个问题。
猜你喜欢
  • 1970-01-01
  • 2013-04-15
  • 2020-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多