【问题标题】:javascript div background image not showingjavascript div背景图像不显示
【发布时间】:2017-01-31 18:27:19
【问题描述】:

我试图在我的 aspx 页面中显示一个带有图像的 div。图像的名称是“PathFindingMap”(一个 png 文件),位于“images”文件夹中。 “图像”文件夹与 aspx 页面位于同一目录中。但是,页面上没有显示任何内容。

在.aspx页面的客户端,我有以下代码sn-p:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="floorPlan.aspx.cs" Inherits="ipsWebs.floorPlan" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"  runat="server">
                        <div class="ClsdrawArea" id="draw_area" style="width: 100%; height:100%; background-image: url('images/PathFindingMap.png'); background-repeat: no-repeat; background-size:cover">
                            </div>

</asp:Content>

在 chrome 浏览器中,我按下 f5 并检查网络,它显示图像“PathFindingMap”已加载。但是,我在网页上看不到任何内容。我试图复制并粘贴类似的代码“

【问题讨论】:

    标签: javascript html css asp.net


    【解决方案1】:

    当您将背景图像设置为 div 时,宽度和高度不起作用。 以像素为单位给出高度和宽度或使用引导程序。

    style="width: 100px; height:100px; 
    

    example plnkr here

    【讨论】:

      【解决方案2】:

      您正在将背景图像设置为块元素。默认情况下它的宽度为 100%。但高度为 0px。所以您需要设置一些像素来显示背景。

      【讨论】:

        【解决方案3】:

        您是否尝试将图像的Build Action 更改为ContentCopy to Output Directory 属性为Copy if newer

        【讨论】:

          猜你喜欢
          • 2010-12-19
          • 2015-12-04
          • 2019-02-11
          • 2013-09-19
          • 2014-02-11
          • 1970-01-01
          • 2017-01-02
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多