将背景图像添加到EJS文件 [英] Adding Background image to EJS file

查看:320
本文介绍了将背景图像添加到EJS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将图像从app.js文件渲染到主ejs文件似乎很好,但是当我将其更改为背景图像时,它不会显示。有什么想法吗?

I seem to be fine getting an image to render from my app.js file to the main ejs file, but when i change it to a background image, it does not display. Any idea whats up?

我的app.js

const express = require("express"),
  app     = express(),
  bodyParser = require("body-parser"),
  jade = require("jade"),
  path = require('path'),
  redis = require('redis');
  images = [{image:"http://nuvotera.com/wp-content/uploads/2013/10/email-protection-banner-2.jpg"}];

app.use(bodyParser.urlencoded({extended:true}));
app.set("view engine", "ejs");

//render email page
app.get("/email", function(req, res){
  res.render("emailMain", {image:images});
});

app.listen(3000, function(){
console.log("Email Server has started");
});

<tr>
<% for(var i=0; i < images.length; i++){ %>

  <td class="vmlHero" background = "<%= images.image %>" style="background-repeat:no-repeat" bgcolor="#000000" width="100%" height="430" valign="top">




推荐答案

ejs文件

将此添加到您的css文件中

add this in your css file

body {
        width: 100%;
        align-items : center;
        height: 100%;
         

        /* Background image is centered vertically and horizontally at all times */
        background-position: center center;

        /* Background image doesn't tile */
        background-repeat: no-repeat;

        /* Background image is fixed in the viewport so that it doesn't move when 
        the content's height is greater than the image's height */
        background-attachment: fixed;

        /* This is what makes the background image rescale based
        on the container's size */
        background-size: cover;

        /* Set a background color that will be displayed
        while the background image is loading */
        background-color: green;
        overflow: hidden;

        /* Location of the image */
        background-image:url('images/introBackGround.jpg') ;
    }  

(删除所有块引用)

路由器文件

您必须添加它。

app.use(express.static(path.join(__dirname, 'public')));

文件夹

public
 └ images  

这篇关于将背景图像添加到EJS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆