我正在使用svg图像和设置max-width属性,但IE只使用原始高度,并不会尝试保持纵横比,即使height: auto明确设置.在这里小提琴
HTML
<img src="http://dauntless.herokuapp.com/assets/images/who-we-are-nav-f35af64a3b.svg">
Run Code Online (Sandbox Code Playgroud)
CSS
img {
max-width: 50px;
height: auto;
}
Run Code Online (Sandbox Code Playgroud)
UPDATE1
实际上这个问题特别适用于我的svgs,其他一些svg文件与IE正常工作.但是我不知道它们有什么问题,它们可以和其他浏览器一起使用.
UPDATE2
提供的答案解决了我的问题,但出现了一个新问题:(
现在,当max-width正确使用图像缩放时,但将其包装在div该包装中时,会获取图像的原始全高.小提琴
我有一个基本设置,每个应用程序都在一个单独的目录中,我使用自定义服务器使用webpack-dev-middleware/编译它们webpack-hot-middleware。一切正常,只是我无法让 HMR 为第二个应用程序工作(我正在使用react-hot-loader)。
这是说明问题的最小回购: https //github.com/AmrN/multi-react-app-hmr
我的主要代码文件:
webpack.config.js
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = function (appName) {
return {
devtool: 'cheap-module-eval-source-map',
entry: [
'react-hot-loader/patch',
'webpack-hot-middleware/client',
path.join(__dirname, appName, 'index'),
],
output: {
path: path.join(__dirname, 'dist', appName),
filename: 'bundle.js',
publicPath: '/'+appName+'/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, appName, 'index.html'),
}),
],
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['babel-loader'],
exclude: /node_modules/, …Run Code Online (Sandbox Code Playgroud) webpack react-hot-loader webpack-hot-middleware webpack-dev-middleware
我试图了解 Rails 如何在/public下提供静态文件,如果我理解正确,则ActionDispatch::Static中间件负责此操作。
但是,我注意到它仅在开发环境中可用:
$ rake middleware
use Rack::Sendfile
use ActionDispatch::Static
use Rack::Lock
.
.
Run Code Online (Sandbox Code Playgroud)
并在生产中:
$ RAILS_ENV=production rake middleware
use Rack::Sendfile
use Rack::Lock
.
.
Run Code Online (Sandbox Code Playgroud)
那么静态文件在生产中是如何提供的呢?我的猜测是,这是由 Web 服务器本身(apache、puma...等)处理的,以提高性能,这是正确的吗?
如果是这样的话,那么为什么要在开发中为这个任务创建一个专用的中间件呢?
谢谢。
所以我users在我的路线中定义了一个简单的资源。
resources :users
Run Code Online (Sandbox Code Playgroud)
我需要提供一条路线,以便登录的用户可以在前端获取他的信息。我想过这样做:
resources :users do
get 'current' , on: :collection
end
Run Code Online (Sandbox Code Playgroud)
但这在语义上意味着该路由给出当前用户的列表,而不是当前用户。事实上,如果我这样做rake routes,它会将路径前缀显示为:current_users
我可以通过执行以下操作来解决路径前缀:
get '/users/current' => 'users#current', as: 'current_user'
Run Code Online (Sandbox Code Playgroud)
但这看起来仍然提供了用户列表。所以,我想知道是否有一种“正确的方法”来做这种事情以及如何在 Rails 中做到这一点?还是我想太多了,我拥有的一切都很好?
如果我想获得对Component中投影的所有元素的引用,我该怎么办?
假设我AppComponent将一些链接和图像投影到TestComponent:
@Component({
selector: 'test',
template: '<ng-content></ng-content>'
})
class TestComponent {}
@Component({
selector: 'app',
template: `
<test>
<img src="http://example.org/1.jpg">
<a href="http://example.org">Some Link</a>
</test>
`,
directives: [ TestComponent ]
})
export class AppComponent {}
Run Code Online (Sandbox Code Playgroud)
现在,我如何在我的内部获得对这些链接和图像(以及可能的其他元素类型)的引用TestComponent?
阅读这篇文章建议如下:
解决方案:带有li选择器的ContentChildren +指令
一个很好的解决方案是利用@Directive装饰器中的选择器.您只需定义,用于选择<LI>元素指令,然后用@ContentChildren查询过滤所有<LI>元素降到只有那些组件的子内容.
但这只有在我想获得单个元素类型时才有效,但是如果我想获得多个类型,这意味着我必须为我想要的每种类型创建一个指令(如果我想要所有类型,那该怎么办?)......这不是一种实用的方法.
还有另外一种方法吗?或直接DOM操作是这种情况下唯一的解决方案?
我有以下型号:
问题:[标题,user_id]
回复:[正文、问题 ID、用户 ID]
用户名]
可以看到,一个问题有很多条回复,一条回复属于一个用户。
我已向问题模型添加了贡献者关系,该模型检索已添加回复的所有用户(使用回复作为联接表):
public function contributors()
{
return $this->belongsToMany(User::class, 'replies')->distinct('user_id');
}
Run Code Online (Sandbox Code Playgroud)
我必须使用distinct()删除重复项,因为用户可能会针对一个问题发布许多回复,而这效果很好。
现在,当我这样做时,问题就发生了:
Question::withCount('contributors')->get()
Run Code Online (Sandbox Code Playgroud)
它会忽略对的调用distinct(),并提供已添加回复(包括重复项)的用户总数。
知道我该如何解决这个问题吗?