0

I am currently in the process of moving a HTML5/CSS3/Javascript site I have been developing over to Node.js using express.js with Jade.

I have a container that holds fluid width, equally spaced divs (the text-justify method) that works great in plain HTML but when generated by Jade it fails to space them out (tested in chrome, firefox & opera). The confusing thing is that the rendered HTML and css properties are identical.

Plain HTML fiddle: http://fiddlesalad.com/html/fluid-column-layout-html-works

Jade Generated HTML fiddle: http://fiddlesalad.com/less/fluid-column-layout-jade-not-working/

It looks like text-align: justify; isn't working.... though I have no idea why.

I am new to Node.js, Express.js and Jade, so is it possible that my app.js or route handlers haven't been configured correctly (I used express --session test and npm install after updating my package.json to handle my depencies)?

Is there an alternative method of getting equally spaced, fluid divs that I can use (I have also tried this similar method: Fluid width with equally spaced DIVs)?

app.js:

    /**
     * Module dependencies.
     */

    var express = require('express');
    var routes = require('./routes');
    var user = require('./routes/user');
    var http = require('http');
    var path = require('path');

    var app = express();

    // all environments
    app.set('port', process.env.PORT || 3000);
    app.set('views', path.join(__dirname, 'views'));
    app.set('view engine', 'jade');
    app.use(express.favicon());
    app.use(express.logger('dev'));
    app.use(express.json());
    app.use(express.urlencoded());
    app.use(express.methodOverride());
    app.use(express.cookieParser('your secret here'));
    app.use(express.session());
    app.use(app.router);
    app.use(express.static(path.join(__dirname, 'public')));

    // development only
    if ('development' == app.get('env')) {
      app.use(express.errorHandler());
    }

    app.get('/', routes.index);

    http.createServer(app).listen(app.get('port'), function(){
      console.log('Express server listening on port ' + app.get('port'));
    });

routes.js /* * GET home page. */

    exports.index = function(req, res){
      res.render('index', { title: 'Express' });
    };
Community
  • 1
  • 1
schanq
  • 864
  • 1
  • 15
  • 25

2 Answers2

2

Wow. It turns out that the whitespace the pure HTML version has is the difference. Your Jade gets rendered like so:

<div class="grid"><div class="column">Item 1</div><div class="column">Item 2</div><div class="column">Item 3</div><div class="column">Item 4</div><div class="column">Item 5</div></div>

but when you write it out manually, you get:

<div class="grid">
  <div class="column">Item 1</div>
  <div class="column">Item 2</div>
  <div class="column">Item 3</div>
  <div class="column">Item 4</div>
  <div class="column">Item 5</div>
</div>

You could try setting pretty mode to true with something like app.locals({pretty:true}) in your configuration, but then you lose the benefit of not having pretty set to true in production.

As to another method of achieving the same end, I don't have an answer for that at this time.

juanpaco
  • 6,303
  • 2
  • 29
  • 22
1

It looks like so long as there is at least one character between the divs in the raw markup, the spacing is correct. This workaround worked for me:

div.grid
  div.column Item 1
  .
  div.column Item 2
  .
  div.column Item 3
  .
  div.column Item 4
  .
  div.column Item 5

Since the font-size of .grid is 0, the periods are not visible.

pixatebob
  • 63
  • 4