如果您对LessandBootstrap:如何使用span3和或spanX[任何数字]类作为mixin?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解LessandBootstrap:如何使用
如果您对Less and Bootstrap:如何使用span3和或spanX [任何数字]类作为mixin?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解Less and Bootstrap:如何使用span3的各种细节,并对或spanX [任何数字]类作为mixin?进行深入的分析,此外还有关于android – 使用Spanable String对齐ImageSpan、android 图文结合,使用SpannableString和ImageSpan类、angular – Webpack bootstrap-loader错误:无法解析’./bootstrap-styles’并且无法解析’./bootstrap-scripts’、Bootstrap 3.1如何使用mixin make-grid-columns()?的实用技巧。
本文目录一览:- Less and Bootstrap:如何使用span3(或spanX [任何数字])类作为mixin?(span怎么使用)
- android – 使用Spanable String对齐ImageSpan
- android 图文结合,使用SpannableString和ImageSpan类
- angular – Webpack bootstrap-loader错误:无法解析’./bootstrap-styles’并且无法解析’./bootstrap-scripts’
- Bootstrap 3.1如何使用mixin make-grid-columns()?
Less and Bootstrap:如何使用span3(或spanX [任何数字])类作为mixin?(span怎么使用)
是否可以span3
在mixin中添加类以避免将其放在HTML的每个元素中?就像是:
.myclass { .span3; // other rules...}
编辑
抱歉,我忘记指定一个重要的细节:这span3
是Bootstrap的标准类。我在Bootstrap框架的任何文件中都找不到它的定义。
答案1
小编典典新答案(要求LESS 1.4.0)
您真正想要的是在LESS和SASS术语中_扩展的_
东西。例如,您需要一个HTML元素(仅作为示例)…
<div></div>
......以 充分 行为,如果它有一个span3
从添加到它引导类,但实际上不添加该类的HTML。这可以在LESS
1.4.0中使用来完成:extend()
,但仍然不容易,主要是因为动态类引导的生成不会被拾取:extend()
。
这是一个例子。假定此初始LESS代码( 不像.span3
引导程序那样动态生成的类):
.span3 { width: 150px;}.someClass .span3 { font-size: 12px;}.someOtherClass.span3 { background: blue;}
您在1.4.0中添加以下代码:
.myclass { &:extend(.span3);}
产生此CSS的代码:
.span3,.myclass { width: 150px;}.someClass .span3 { font-size: 12px;}.someOtherClass.span3 { background: blue;}
注意 它 没有 自动扩展的其他实例.span3
。这与SASS不同,但这仅意味着您需要在扩展方面更加明确。这样的好处是避免了过多的CSS代码膨胀。
要完全扩展,只需在中添加all
关键字extend()
(由于我不知道该all
选项,因此它是从我的原始代码更新的):
.myclass { &:extend(.span3 all);}
产生此结果:
.span3,.myclass { width: 150px;}.someClass .span3,.someClass .myclass { font-size: 12px;}.someOtherClass.span3,.someOtherClass.myclass { background: blue;}
这使您.myclass
完全等同
于.span3
该类(在我的示例中)。但是,对于您的情况,这意味着您需要重新定义引导程序的所有动态类,使其成为非动态的。像这样:
.span3 { .span(3);}
这样便:extend(.span3)
可以找到要扩展的硬编码类。对于任何用于动态.span@{index}
添加的选择器字符串,都需要这样做.span3
。
原始答案
该答案假定您希望 从动态生成的类中 混合 属性(这就是我认为的问题所在)。
好的,我相信我发现了您的问题。首先,bootstrap定义了文件中的.spanX
一系列类mixins.less
,因此显然您需要确保将其包含在bootstrap负载中。但是,我想假设您已经包含了这些内容。
主要问题
主要问题是引导程序如何通过循环中的动态类名立即生成那些引导程序。这是定义.spanX
系列的循环:
.spanX (@index) when (@index > 0) { .span@{index} { .span(@index); } .spanX(@index - 1); }.spanX (0) {}
当前, 由于类名称本身是动态生成的
,因此不能用作混合名称。我不知道这是Bug还是LESS的局限性,但我确实知道,在撰写本文时,任何动态生成的类名称都不能用作混合名称。因此,.span3
可能在CSS代码中将其作为类放入HTML中,但出于混合目的而不能直接访问。
修复
但是,由于他们如何构造代码,您仍然可以获得所需的东西,因为如您在循环代码中的上面所看到的那样,它们使用真正的mixin本身来定义.spanX
类的代码。因此,您应该能够执行以下操作:
.myclass { .span(3); // other rules...}
该.span(3)
代码是循环用来填充.span3
类的代码,因此为您的类调用该代码将提供与之相同的代码.span3
。具体来说,引导程序为此mixins.less
混合定义了以下定义:
.span (@columns) { width: (@fluidGridColumnWidth * @columns) + (@fluidGridGutterWidth * (@columns - 1)); *width: (@fluidGridColumnWidth * @columns) + (@fluidGridGutterWidth * (@columns - 1)) - (.5 / @gridRowWidth * 100 * 1%);}
所以,你会得到width
的属性.span3
在你的.myclass
。
android – 使用Spanable String对齐ImageSpan
我知道有很多相同类型的问题可供使用,我尝试了很多解决方案,但所有这些问题都达不到我的要求.
我的问题是我必须在包含Spanable字符串和Imagespan的文本之间添加动态行间距,但是当我添加行间距时,文本和图像的对齐会变形.
我已经尝试了Stackoverflow上几乎所有可用的解决方案,如this,this& this但是一切都在静脉中.
我附上了截图
>添加动态行间距之前的屏幕截图
2.添加动态行间距后的屏幕截图
任何帮助将受到高度赞赏.提前致谢!
解决方法:
在onDraw方法中使用“y”查找文本的基线,然后将drawable与文本视图的基线对齐
public class VerticalImageSpan extends ImageSpan {
public VerticalImageSpan(Drawable drawable) {
super(drawable);
}
/**
* update the text line height
*/
@Override
public int getSize(Paint paint, CharSequence text, int start, int end,
Paint.FontMetricsInt fontMetricsInt) {
Drawable drawable = getDrawable();
Rect rect = drawable.getBounds();
if (fontMetricsInt != null) {
Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
int fontHeight = fmPaint.descent - fmPaint.ascent;
int drHeight = rect.bottom - rect.top;
int centerY = fmPaint.ascent + fontHeight / 2;
fontMetricsInt.ascent = centerY - drHeight / 2;
fontMetricsInt.top = fontMetricsInt.ascent;
fontMetricsInt.bottom = centerY + drHeight / 2;
fontMetricsInt.descent = fontMetricsInt.bottom;
}
return rect.right;
}
/**
* see detail message in android.text.TextLine
*
* @param canvas the canvas, can be null if not rendering
* @param text the text to be draw
* @param start the text start position
* @param end the text end position
* @param x the edge of the replacement closest to the leading margin
* @param top the top of the line
* @param y the baseline
* @param bottom the bottom of the line
* @param paint the work paint
*/
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end,
float x, int top, int y, int bottom, Paint paint) {
Drawable drawable = getDrawable();
canvas.save();
Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
int fontHeight = fmPaint.descent - fmPaint.ascent;
int centerY = y + fmPaint.descent - fontHeight / 2;
int transY = centerY - (drawable.getBounds().bottom - drawable.getBounds().top) / 2;
canvas.translate(x, transY);
drawable.draw(canvas);
canvas.restore();
}
}
android 图文结合,使用SpannableString和ImageSpan类
参考:http://my.oschina.net/sfshine/blog/147701
/**
* 根据文本替换成图片
* @param text
* @return
*/
public CharSequence strToSmiley(CharSequence text) {
SpannableStringBuilder builder = new SpannableStringBuilder(text);
Pattern mPattern = Pattern.compile("( \\[[0-9]{1,3}\\])");
Matcher matcher = mPattern.matcher(text);
String s="";
int resId=0;
while (matcher.find()) {
for (int j = 0; j <FaceTool.facelist.size(); j++) {
s=FaceTool.facelist.get(j).get(matcher.group())+"";
if(!s.equalsIgnoreCase("null"))
resId=Integer.parseInt(s);
}
Drawable drawable = this.getResources().getDrawable(resId);
drawable.setBounds(0, 0, 25, 25);//这里设置图片的大小
ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM);
builder.setSpan(imageSpan, matcher.start(),
matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return builder;
}
Drawable drawable = getResources().getDrawable(id);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
//需要处理的文本,[smile]是需要被替代的文本
SpannableString spannable = new SpannableString(getText().toString()+"[smile]");
//要让图片替代指定的文字就要用ImageSpan
ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
//开始替换,注意第2和第3个参数表示从哪里开始替换到哪里替换结束(start和end)
//最后一个参数类似数学中的集合,[5,12)表示从5到12,包括5但不包括12
spannable.setSpan(span, getText().length(),getText().length()+"[smile]".length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
setText(spannable);
angular – Webpack bootstrap-loader错误:无法解析’./bootstrap-styles’并且无法解析’./bootstrap-scripts’
ERROR in ./~/bootstrap-webpack/index.js Module not found: Error: Can't resolve './bootstrap-styles' in 'd:\web\angular2-webpack-starter\node_modules\bootstrap-webpack' @ ./~/bootstrap-webpack/index.js 1:0-66 @ ./src/vendor.browser.ts @ multi vendor ERROR in ./~/bootstrap-webpack/index.js Module not found: Error: Can't resolve './bootstrap-scripts' in 'd:\web\angular2-webpack-starter\node_modules\bootstrap-webpack' @ ./~/bootstrap-webpack/index.js 2:0-52 @ ./src/vendor.browser.ts @ multi vendor
重现步骤:
>克隆https://github.com/AngularClass/angular2-webpack-starter
> npm安装
> npm install bootstrap-webpack –save
> npm install less-loader less –save-dev
> add line:require(“bootstrap-webpack”);到src / vendor.browser.ts
>从bootstrap-webpack文档中添加一些规则到config / webpack.common.js:
> npm开始
bootstrap-webpack documentation的规则:
// bootstrap-webpack has access to the jQuery object { test: /bootstrap\/js\//,loader: 'imports?jQuery=jquery' },// Needed for the css-loader when [bootstrap-webpack](https://github.com/bline/bootstrap-webpack) // loads bootstrap's css. { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,loader: "url?limit=10000&mimetype=application/font-woff" },{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,loader: "url?limit=10000&mimetype=application/octet-stream" },{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,loader: "file" },{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,loader: "url?limit=10000&mimetype=image/svg+xml" }
解决方法
//packages.json { "dependencies": { "bootstrap-webpack": "^0.0.5","jquery": "^3.1.1",},"main": "js/entry.js","devDependencies": { "babel-core": "^6.22.1","babel-loader": "^6.2.10","babel-preset-es2015": "^6.22.0","bootstrap": "^3.3.7","css-loader": "^0.26.1","exports-loader": "^0.6.3","extract-text-webpack-plugin": "^1.0.1","file-loader": "0.8.1","imports-loader": "^0.7.0","less": "^2.7.2","less-loader": "^2.2.3","style-loader": "^0.13.1","url-loader": "0.5.5","webpack": "1" } } // webpack.config.js module: { loaders: [ {test: /\.jsx?$/,loader: 'babel-loader',exclude: /(node_modules|bower_components)/,query: {presets: ['es2015']}},{test: /\.css$/,loader: 'css-loader'},{test: /\.(woff|woff2)$/,loader: 'url-loader?limit=10000'},{test: /\.ttf$/,loader: 'file-loader'},{test: /\.eot$/,{test: /\.svg$/,loader: 'file-loader'} ] }
然后添加require(“bootstrap-webpack”);并运行webpack,不知何故,它的工作原理!
Bootstrap 3.1如何使用mixin make-grid-columns()?
在这些我的类采用一些引导风格,像这样:
.myClass{ .col-md-3; border: 1px solid #000; [etc,etc] }
它在Bootstrap 3.0中表现很好,因为所有col-md-X类都定义为较少的变量。但是在Bootstrap 3.1中,这似乎是用一个叫做make-grid-columns()的mixin函数来代替。
有人知道如何使用这个混合,以及如何将上面的构建移植到Bootstrap 3.1? : – /
解决方法
.myClass{ .make-md-column(3); /* Replaces .col-md-3; */ border: 1px solid #000; [etc,etc] }
我们今天的关于Less and Bootstrap:如何使用span3和或spanX [任何数字]类作为mixin?的分享已经告一段落,感谢您的关注,如果您想了解更多关于android – 使用Spanable String对齐ImageSpan、android 图文结合,使用SpannableString和ImageSpan类、angular – Webpack bootstrap-loader错误:无法解析’./bootstrap-styles’并且无法解析’./bootstrap-scripts’、Bootstrap 3.1如何使用mixin make-grid-columns()?的相关信息,请在本站查询。
本文标签: