MVC - Div类没有在CSS中显示背景图像或颜色

时间:2018-05-09 19:06:35

标签: html css

我尝试使用css样式将背景图像添加到一个并为另一个div类添加颜色。然而,图像根本没有显示,不确定问题是什么..

HTML:

$collection = Mage::getResourceModel('customer/customer_collection')
                ->addAttributeToSelect('email')
                ->addAttributeToSelect('dob_month', 'left')
                ->addAttributeToSelect('dob_day', 'left')
                ->addExpressionAttributeToSelect('dob', "CONCAT({{dob_month}}, '-',{{dob_day}})", array(
                'dob_month', 'dob_day'
                ))
->addAttributeToFilter('dob_month', array(
    array('eq' => '1125')
))
/*->addAttributeToFilter('dob_day', array(
    array('eq' => '08')
))*/
->setPageSize(20)
->setCurPage(1);

这是我的CSS:

@{
  ViewData["Title"] = "Home Page";
  Layout = "~/Views/Shared/_DefaultLayout.cshtml";
}

<div class="parralax">    
</div>

<div class="home-parralax-sub-section">    
</div>

现在,如果我将图像或颜色直接添加到div:

.parralax {
background: url(../../../../images/Resources/MainImage2.jpg);
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

.home-parralax-sub-section{
    height: 100px;
    background-color: red;
}

它会起作用!

任何帮助都会被批评,谢谢:)。

2 个答案:

答案 0 :(得分:0)

你必须为.parallax类添加高度,然后才能工作。

.parralax {
background: url('../../../../images/Resources/MainImage2.jpg');
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
   height:500px;
}

.home-parralax-sub-section{
    height: 100px;
    background-color: red;
}

答案 1 :(得分:0)

试试这个

.parralax {
  background: url(http://via.placeholder.com/350x150);
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  height: 150px;
  /*Add to this div height*/
}

.home-parralax-sub-section {
  height: 100px;
  background-color: red;
}
<div class="parralax">
</div>

<div class="home-parralax-sub-section">
</div>

为包含背景图像的div添加高度