Skip to main content

twitter bootstrap won"t work with less.js


I have broken it down to it simplest form but still cannot find out why this is not working. All files resolve and the imports in bootstrap are loaded yet, the styles aren't loaded.



bootstrap 1.4.0 less 1.1.3




<html>
<head>
<title>ahhhhhh...</title>

<link rel="stylesheet/less" href="/less/bootstrap/1.4.0/bootstrap.less">
<script src="/less/less-1.1.3.min.js"></script>

</head>
<body>

<h1>WTF!!!</h1>

</body>
</html>



I made a simple style.less which works fine! Am I missing something glaringly obvious ?



Update:



style.less as requested by Todd :




@primary_color: green;

h1 {
color: @primary_color;
}


Source: Tips4allCCNA FINAL EXAM

Comments

  1. Update 3/5/2012: The Bootstrap guys have fixed this problem in version 2.0.2 of Bootstrap (not yet released). See this commit.

    The underlying bug is that the present version of less.js doesn't allow you to use a variable for for the url() value directly (e.g. url(@iconWhiteSpritePath)) -- instead you have to use string interpolation (e.g. url("@{iconWhiteSpritePath}")), which accomplishes the same thing. The bootstrap guys just updated their syntax to take this quirk into account.

    Original Answer

    I ran into the exact problem today and figured out the cause of it. Since your stack is a few versions before mine (I'm using Bootstrap 2.0 and less.js 1.2.2) I can't be sure it's the same issue, but it's possibly related.

    Anyhow, the problem for me was that Twitter Bootstrap is defining some variables:

    @iconSpritePath: "../img/glyphicons-halflings.png";
    @iconWhiteSpritePath: "../img/glyphicons-halflings-white.png";


    And then using them directly in the url() value for a background-image in sprites.less:

    [class^="icon-"],
    [class*=" icon-"] {
    display: inline-block;
    width: 14px;
    height: 14px;
    line-height: 14px;
    vertical-align: text-top;
    background-image: url(@iconSpritePath);
    background-position: 14px 14px;
    background-repeat: no-repeat;

    .ie7-restore-right-whitespace();
    }
    .icon-white {
    background-image: url(@iconWhiteSpritePath);


    }

    Per the discussion in this Github issue that's causing a major problem. When less.js chokes on this value, the whole compilation fails.

    The good news is there is a fix in that issue, provided by csnover. Just change this line in tree.URL:

    if (typeof(window) !== 'undefined' && !/^(?:https?:\/\/|file:\/\/|data:|\/)/.test(val.value) && paths.length > 0) {


    to

    if (typeof(window) !== 'undefined' && typeof(val.value) !== 'undefined' && !/^(?:https?:\/\/|file:\/\/|data:|\/)/.test(val.value) && paths.length > 0) {


    and you should be set. In other words, we just ensure that val.value is set so that that charAt() doesn't choke on an undefined.

    Hopefully this fix will be committed to the project soon and Bootstrap will work with less.js in the browser environment out of the box.

    ReplyDelete
  2. for me worked

    [class^="icon-"],
    [class*=" icon-"] {
    display: inline-block;
    width: 14px;
    height: 14px;
    line-height: 14px;
    vertical-align: text-top;
    background-image: url(../img/glyphicons-halflings.png);
    background-position: 14px 14px;
    background-repeat: no-repeat;

    .ie7-restore-right-whitespace();
    }
    .icon-white {
    background-image: url(../img/glyphicons-halflings-white.png);
    }


    so replace

    url(@iconSpritePath);


    with

    url(../img/glyphicons-halflings.png);


    on less.js v1.2.1 and Bootstrap v2.0.1

    ReplyDelete
  3. If you are developing this locally, make sure that the browser is using the correct protocol. It should display http: in the address bar, not file:.

    On my Windows 7 machine using Chrome (with a XAMPP setup), I was having the same CSS problem using less.js with Bootstrap when accessing the .html file at:

    file:///C:/xampp/htdocs/index.html


    However, it did render properly via http at:

    http://localhost/index.html


    Not certain why, but I imagine that less.js relies on HTTP headers.

    ReplyDelete
  4. Is it the problem with your file structure?
    /less/bootstrap/1.4.0/bootstrap.less will point to the root of your domain regardless of your html file.

    If you are hosting with apache and you have the following project structure:

    www/
    your project/
    less/
    index.html
    another project/
    others/


    When you access index.html from http://localhost, it will look up the less file from the domain root which is www/. Thus as no less folder is under this root directory, it will returned as 404 (not found).

    So, the solution is to use relative url for your less files. If you have the above structure, remove the '/' and use less/bootstrap/1.4.0/bootstrap.less instead.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex