简体   繁体   English

我如何一起使用Twitter Bootstrap,MVC和Visual Studio?

[英]How can I use Twitter Bootstrap, MVC and Visual Studio together?

I am starting to try out Bootstrap. 我开始试用Bootstrap。 I have already downloaded the dotless extension but I am confused as to what to do next. 我已经下载了无网点扩展,但我对下一步做什么很困惑。 Looking at the bootstrap files I see a lot of .less files. 看一下bootstrap文件,我看到很多.less文件。 Can someone explain where I should put these within the MVC folder structure and how can I set up the application so that when I make a change to a color variable then my .css files get updated. 有人可以解释我应该将它们放在MVC文件夹结构中的位置,以及如何设置应用程序,以便在我对颜色变量进行更改时,我的.css文件会更新。

Update 更新

As suggested I placed all the .less files in the same directory as my css. 按照建议,我将所有.less文件放在与我的css相同的目录中。

However what should I do next? 但是接下来我该怎么办? I tried to view the URL 我试图查看URL

http://127.255.0.0:82/Content/Stylesheets/bootstrap.less

in my browser but got the following message: 在我的浏览器中但收到以下消息:

( 

Expected '}' but found '~' on line 522 in file 'mixins.less':
[521]:     .spanX (@index) when (@index > 0) {
[522]:       (~".span@{index}") { .span(@index); }
       ------^
[523]:       .spanX(@index - 1);

I currently compile the less files on build with nodejs. 我目前使用nodejs在build上编译较少的文件。

You need to install node.js . 您需要安装node.js.

Once installed, in command prompt type: "npm install less -g" this installs the latest less globally (-g on the end for global). 安装完成后,在命令提示符下键入:“npm install less -g”,这将全局安装最新的(全局为-g)。

In visual studio, go to Build Events in the websites properties page and put in a "pre-build event command line" like the following: 在visual studio中,转到网站属性页面中的构建事件,并输入如下所示的“预构建事件命令行”:

lessc $(SolutionDir)path-to-main-less-file.less > $(SolutionDir)path-to-where-css-is-output.css -x lessc $(SolutionDir)path-to-main-less-file.less> $(SolutionDir)path-to-where-css-is-output.css -x

EDIT: Bootstrap now uses Recess and npm command has changed as seen here . 编辑:Bootstrap现在使用Recess和npm命令已更改,如此处所示

Go easy on me, It's my first post! 对我这么轻松,这是我的第一篇文章! :) :)

This is a known issue in Dotless: 这是Dotless的一个已知问题:
https://github.com/dotless/dotless/issues/155 https://github.com/dotless/dotless/issues/155

Basically the Bootstrap source code is using LESS features that are not yet supported in the version of Dotless that you use. 基本上,Bootstrap源代码使用的是您使用的Dotless版本尚不支持的LESS功能。 Apparently support has been added in the latest source though, so you should be able to resolve this by compiling Dotless from the latest source. 显然,在最新的源代码中添加了支持,因此您应该能够通过从最新的源代码编译Dotless来解决这个问题。

It is not enough to download and reference dotless.Core.dll, because the binary files aren't up-to-date enough, ie they do not contain the latest features that you need for Bootstrap. 下载和引用dotless.Core.dll是不够的,因为二进制文件不是最新的,即它们不包含Bootstrap所需的最新功能。 Only the source files contain the latest changes, so you have to produce the dotless.Core.dll by compiling the latest source with Visual Studio. 只有源文件包含最新的更改,因此您必须通过使用Visual Studio编译最新的源来生成dotless.Core.dll。 Of course these features will be included in the .dll download when they next decide to update it. 当然,这些功能将在下次决定更新时包含在.dll下载中。

Dotless produces the result file bootstrap.css "on the fly". Dotless在运行中生成结果文件bootstrap.css。 You never see that file on the disk, as it is produced by compiling the .less files when they are requested via HTTP. 您永远不会在磁盘上看到该文件,因为它是通过在通过HTTP请求时编译.less文件而生成的。 The CSS that is produced is only cached in memory. 生成的CSS仅缓存在内存中。 However you could always request the .less file in your browser and save what you see to a .css file. 但是,您始终可以在浏览器中请求.less文件并将您看到的内容保存到.css文件中。 That would work but there isn't much point in doing it if your Dotless installation is working properly. 如果你的Dotless安装工作正常,那就没有用了。

However, if all you want is a bootstrap.css file with your customized values, you can also use this online tool on the Bootstrap website. 但是,如果您想要的是带有自定义值的bootstrap.css文件,您也可以在Bootstrap网站上使用此在线工具 It will let you change the variable values and download the resulting CSS. 它将允许您更改变量值并下载生成的CSS。

Have you tried Mindscap Web Workbench ? 你有没有尝试过Mindscap Web Workbench

They have an article on how to set it up for use with Twitter Bootstrap . 他们有一篇关于如何设置它以用于Twitter Bootstrap的文章

You can use Combres to with my dotless plugin here . 你可以在这里使用Combres和我的无点插件。 All you need to do is reference bootstrap.less and all the imports will work out of the box with clean Bootstrap less files. 您需要做的就是引用bootstrap.less并且所有导入都可以使用干净的Bootstrap less文件。 Combres will build and cache the bootstrap file and even compress it with other non-Bootstrap css files. Combres将构建并缓存引导文件,甚至用其他非Bootstrap css文件压缩它。 This is the ideal setup. 这是理想的设置。

http://pknopf.com/blog/using-less-correctly-with-combres http://pknopf.com/blog/using-less-correctly-with-combres

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Ext JS与ASP.NET MVC 5和Visual Studio 2015一起使用 - How do I use Ext JS together with ASP.NET MVC 5 and Visual Studio 2015 如何将Expression Web 2和Visual Studio asp.net mvc一起使用? - how do you use Expression Web 2 and Visual Studio asp.net mvc together? 如何使用本地iis和mvc一起工作? - How can I use my local iis and mvc to work together? 如果我使用ASP .NET MVC 3,我可以安全地从Visual Studio中删除ASP .NET MVC 2吗? - Can I safely remove ASP .NET MVC 2 from Visual Studio if I use ASP .NET MVC 3? 如何在Visual Studio中使用MVC 3智能剃须刀 - how to use MVC 3 intellisense for razor in Visual studio 无法在MVC 3,Visual Studio 2010中使用PagedList.Mvc - Can't use PagedList.Mvc in MVC 3, Visual Studio 2010 如何在MVC视图中使用Bootstrap按钮插件 - How can I use Bootstrap button addons in my MVC view 如何在MVC Razor中使用Bootstrap Badge类? - How can I use the Bootstrap Badge class within MVC Razor? 我可以同时使用 ReactJs、EmberJs 和 ASP.NET MVC 吗? - Can I use ReactJs, EmberJs and ASP.NET MVC together? 在使用ASP.NET MVC时,如何有效地使用Visual Studio中的“添加视图”对话框? - How can one use the “Add view” dialog in Visual Studio efficiently when working with ASP.NET MVC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM