简体   繁体   English

Visual Studio(2012及更低版本)删除CSS属性

[英]Visual Studio (2012 and lower) deletes CSS properties

I have a really strange problem with Visual Studio 2010. When I add CSS properties for a gradient to my stylesheet, Visual Studio is going to delete it after some times of debugging. 我在Visual Studio 2010中遇到了一个非常奇怪的问题。当我在样式表中添加渐变的CSS属性时,Visual Studio将在调试几次后将其删除。

Example of the code I add to my stylesheet: 我添加到样式表中的代码示例:

.button
{
    /* Firefox */
    background-image: -moz-linear-gradient(top, #fff, #efefef);
    /* Chrome, Safari */
    background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #fff),color-stop(1, #efefef));
    /* Modern Browsers*/
    background-image: linear-gradient(top, #fff, #efefef);
    /* IE */
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffffff', EndColorStr='#efefef'); 
}

Sometimes when I start debug, Visual Studio edits the CSS: 有时,当我开始调试时,Visual Studio会编辑CSS:

.button
{
    /* Firefox */
    background-image: linear-gradient(top, #fff, #efefef);
    /* Chrome, Safari */
    /* Modern Browsers*/
    }

So Visual Studio seems to delete some attributes it doesn't know. 因此,Visual Studio似乎删除了一些未知的属性。 That's really annoying. 真烦人。 Any idea how I could stop that? 知道我该如何阻止吗?

It's not a problem of CSS comments. 这不是CSS注释的问题。 It also happen without the comments. 没有评论也可能发生。

Update 更新资料

It seems that it happens by saving of files that included the css file. 似乎是通过保存包含css文件的文件来实现的。 When I edit my Master Layout and save it, Visual Studio is gonna delete this properties I mentioned above in the linked css file. 当我编辑主版面并将其保存时,Visual Studio将删除上面在链接的CSS文件中提到的该属性。

And its NOT a CSS3 problem because it doesn't touch my border-radius classes and ids. 而且这不是 CSS3问题,因为它不涉及我的border-radius类和id。 So maybe it's the filter property. 所以也许是filter属性。 However I want stop Visual Studio changing my things in the css file without permissions. 但是我想停止Visual Studio未经许可而更改css文件中的内容。

Update 27. June 2014 更新27.2014年6月

Problem solved in Visual Studio 2013 https://connect.microsoft.com/VisualStudio/feedback/details/782677/visual-studio-is-deleting-css 在Visual Studio 2013中解决的问题https://connect.microsoft.com/VisualStudio/feedback/details/782677/visual-studio-is-deleting-css

Okay I found a temporary workaround for this: 好的,我为此找到了一个临时解决方法:

The existence of the "filter:" style is what's causing all of the "background-image:" styles to disappear except the last one listed. “ filter:”样式的存在是导致所有“ background-image:”样式消失的原因,除了最后列出的一种。 It's not that it's removing what it doesn't know, it's just removing all but the last "background-image" style listed. 不是删除了不知道的内容,而是删除了除最后列出的“背景图像”样式以外的所有样式。 Must be Microsoft (intended) way of making filter and an MS specific background-image style play nicely together, however they didn't code it up very well. 必须是使过滤器和特定于MS的背景图像样式完美配合的Microsoft(预期)方式,但是他们并没有很好地编写代码。 Definitely a MS VS defect. 绝对是MS VS缺陷。 To repro, just right click in the CSS class that has code similar to this: 要进行复制,只需右键单击具有类似于以下代码的CSS类:

background-color: #EBEBEB; /* Fallback background color for non supported browsers */  
background-image: -webkit-gradient(linear, left top, right top, from(#FFFFFF), to(#DAD6E7));  
background-image: -webkit-linear-gradient(left, #FFFFFF, #DAD6E7);  
background-image: -moz-linear-gradient(left, #FFFFFF, #DAD6E7);  
background-image: -ms-linear-gradient(left, #FFFFFF, #DAD6E7);  
background-image: -o-linear-gradient(left, #FFFFFF, #DAD6E7);  
background-image: linear-gradient(left, #FFFFFF, #DAD6E7);  
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#FFFFFF', EndColorStr='#DAD6E7', gradientType='1'); /* IE6 - IE9 */

and then select "Build Style...". 然后选择“构建样式...”。 Then click "OK" without changing anything and watch it remove all but the last background-image left. 然后,单击“确定”,不进行任何更改,然后将其删除,除去最后一个背景图像。 Try changing the order of the "background-image styles and leave webkit last and then see for yourself. 尝试更改“背景图像样式”的顺序,最后保留webkit,然后亲自查看。

You'll notice that if you remove the "filter:" style the problem goes away, however we need that (for this example) so the solution seems to be moving the "filter:" style above all the "background-image:" lines. 您会注意到,如果删除了“ filter:”样式,问题就消失了,但是(在此示例中)我们需要这样做,因此解决方案似乎是将“ filter:”样式移至所有“ background-image:”之上。线。 Once you do that, it leaves them alone and the problem goes away. 一旦执行此操作,就让他们独自一人,问题就消失了。

Changing the above CSS to this seems to aleviate the problem: 将上述CSS更改为此似乎可以缓解问题:

filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#FFFFFF', EndColorStr='#DAD6E7', gradientType='1'); /* IE6 - IE9 */
background-color: #EBEBEB; /* Fallback background color for non supported browsers */  
background-image: -webkit-gradient(linear, left top, right top, from(#FFFFFF), to(#DAD6E7));  
background-image: -webkit-linear-gradient(left, #FFFFFF, #DAD6E7);  
background-image: -moz-linear-gradient(left, #FFFFFF, #DAD6E7);  
background-image: -ms-linear-gradient(left, #FFFFFF, #DAD6E7);  
background-image: -o-linear-gradient(left, #FFFFFF, #DAD6E7);  
background-image: linear-gradient(left, #FFFFFF, #DAD6E7);  

UPDATE: The workaround above only works for when VS applies formatting when you're using the "Build Style..." --> "Modify Style" dialog because I just saw it again with the fix above in place so it must be from somthing else. 更新:以上解决方法仅适用于当您使用“构建样式...”->“修改样式”对话框时VS应用格式时的情况,因为我刚刚在上面的修复中再次看到它,因此它一定来自别的。

Gradients are CSS3 Properties. 渐变是CSS3属性。

Visual Studio do not support CSS3 and HTML5 and that might be the problem here. Visual Studio不支持CSS3和HTML5,这可能是这里的问题。
But there is support for HTML5 & CSS3 in Visual Studio 2010 SP1 但是Visual Studio 2010 SP1中支持HTML5和CSS3
So, why don't you download Visual Studio 2010 SP1 and try? 那么,为什么不下载Visual Studio 2010 SP1并尝试呢?

I have experienced this same issue as well in VS2010, and can confirm that the problem does not affect CSS3 styles. 我在VS2010中也遇到了相同的问题,可以确认该问题不会影响CSS3样式。 The only work around I can suggest is to place a copy of the disappearing line above itself in a comment so at least it is easy to copy back again. 我可以建议的唯一解决方法是,将消失的行的副本放在其自身上方的注释中,这样至少可以轻松地再次将其复制回来。

/* filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffffff', EndColorStr='#efefef'); */
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffffff', EndColorStr='#efefef');

In Visual Studio try: Tools > Options > Text Editor > CSS > Miscellaneous switch off Detect Errors. 在Visual Studio中,尝试:工具>选项>文本编辑器> CSS>其他关闭检测错误。 I did this and using a file with your sample above, ran the solution, closed the file, closed the solution and my code is still there :-) 我这样做了,并在上面的示例中使用了文件,运行了解决方案,关闭了文件,关闭了解决方案,我的代码仍然存在:-)

I do not have Visual Studio to test this, but reading the information from other comments and answers, it seems like you might try separating the filter out completely into a repeated selector definition . 我没有Visual Studio对此进行测试,但是从其他注释和答案中读取信息,似乎您可以尝试将filter完全分离为重复的选择器定义 Like so: 像这样:

.someClass {
  background-color: #EBEBEB; /* Fallback background color for non supported browsers */  
  background-image: -webkit-gradient(linear, left top, right top, from(#FFFFFF), to(#DAD6E7));  
  background-image: -webkit-linear-gradient(left, #FFFFFF, #DAD6E7);  
  background-image: -moz-linear-gradient(left, #FFFFFF, #DAD6E7);  
  background-image: -ms-linear-gradient(left, #FFFFFF, #DAD6E7);  
  background-image: -o-linear-gradient(left, #FFFFFF, #DAD6E7);  
  background-image: linear-gradient(left, #FFFFFF, #DAD6E7);  
}

.someClass { /* repeated to isolate filter */
  filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#FFFFFF', EndColorStr='#DAD6E7', gradientType='1'); /* IE6 - IE9 */
}

That is a real pain, but if it solves your problem until MS gets the bug worked out... 那确实是很痛苦的,但是如果它能解决您的问题,直到MS解决了该错误……

I realize this is an older thread, but I still have the same problem 我意识到这是一个较旧的线程,但是我仍然遇到相同的问题

I haven't yet found how to prevent it, but there is a much easier way to correct the CSS mess-up: 我还没有找到预防方法,但是有一种更简单的方法来纠正CSS混乱:

As soon as you notice VS2010 has messed up the CSS code, stop the debug, go to the CSS file tab and press the undo button. 一旦您注意到VS2010弄乱了CSS代码,请停止调试,转到CSS文件选项卡,然后按undo按钮。 Your Css code is back to before VS2010 messed it up. 您的Css代码回到VS2010搞砸之前。 Compile and it works. 编译即可。

I'm going to try out VS2012 soon, anyone know if it has been solved there? 我将很快尝试VS2012,有人知道它在那里是否已解决?

I've just had the exact same issue! 我刚遇到了完全相同的问题!

I had the DevX IDE tools installed, and uninstalling that seems to have resolved the issue for me. 我已经安装了DevX IDE工具,并且卸载似乎已经为我解决了这个问题。 I did that a few days ago, and the issue hasn't recurred. 我是在几天前这样做的,问题一直没有发生。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM