Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用“角度”添加背景图像时出错_Javascript_Angularjs - Fatal编程技术网

Javascript 使用“角度”添加背景图像时出错

Javascript 使用“角度”添加背景图像时出错,javascript,angularjs,Javascript,Angularjs,我尝试添加背景图像,并使用封面让浏览者调整图像大小。但是,图像非常小,不能覆盖整个背景 我对angular是个新手,所以我对它的工作原理有一个很小的了解 此外,尽管使用ZURB为我管理间隔,搜索栏不在中间。 下面是页面的外观 代码如下: <div > <!-- Above fold --> <div class="row"> <div id = "backgroundImage" class="large-12 sma

我尝试添加背景图像,并使用封面让浏览者调整图像大小。但是,图像非常小,不能覆盖整个背景

我对angular是个新手,所以我对它的工作原理有一个很小的了解

此外,尽管使用ZURB为我管理间隔,搜索栏不在中间。

下面是页面的外观

代码如下:

<div >

    <!-- Above fold -->
    <div class="row">

        <div id = "backgroundImage" class="large-12 small-12 columns" ng-style="{'background-image':'url(img/mainBackground.png)','background-size' : 'cover'}">

            <!-- search bar -->
            <div class="row">

                <!--empty -->
                <div class="large-3 small-3 columns">
                    &nbsp;
                </div>

                <div class="large-6 small-6 columns">
                    <input type="text" id="searchBar" ng-style="{'width': '50%'}">
                </div>

                <!--empty -->
                <div class="large-3 small-3 columns">
                    &nbsp;
                </div>

            </div>

        </div>
    </div>

</div> 

除了@Marko的响应之外,您正在使用Angular设置属性的样式,但您提供的样式只是静态的。Angular的
ng style
属性用于在运行时基于给定条件应用动态样式时使用。你没有那样做。您只是提供了您想要应用的静态样式,内联。这并不是一个真正的最佳实践。最好只使用静态css样式表来完成您想要的工作

也就是说,你所面临的问题纯粹是一个CSS问题,而不是一个特定角度的问题。您只需在
#backgroundImage
div上调试样式,就可以消除使用
ng样式所涉及的许多复杂性


这里有一个关于使用整版css背景图像的好教程:

根据您提供的代码,通过AngularJS设置div的样式绝对没有任何好处。使用样式表。感谢您的详细说明,我很懒:)