CSS 中的区域像 C# 区域一样吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7519856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 01:42:11  来源:igfitidea点击:

Regions in CSS like C# regions?

cssvisual-studio-2010

提问by Adnan Bhatti

Is there a way to define regions in CSS file just like regions in C#?

有没有办法像 C# 中的区域一样在 CSS 文件中定义区域?

Like in C# you define regions as follows

就像在 C# 中一样,您可以按如下方式定义区域

#region My Region
//your code here
#endregion

My problem is I don't want to use separate CSS files for my asp.net project but I also want to organinze so I can define specific sections like one for Master Page CSS and one for FormUser and so forth so it is easy to troubleshoot when needed. Is it possible?

我的问题是我不想为我的 asp.net 项目使用单独的 CSS 文件,但我也想组织起来,这样我就可以定义特定的部分,例如一个用于母版页 CSS,一个用于 FormUser 等等,以便于排除故障需要的时候。是否可以?

回答by Mulki

You can use this for regions...works well to make collapsible regions

您可以将其用于区域...可以很好地制作可折叠区域

/*#region RegionName*/

/*#endregion RegionName*/

The RegionName is optional in endregion, you can also use

RegionName 在 endregion 中是可选的,你也可以使用

/*#region RegionName*/

/*#endregion */

回答by Andrew Barber

You can't do regions, but you can always just use spacing and comments to add some organization if you like.

你不能做区域,但如果你愿意,你总是可以使用间距和注释来添加一些组织。

/*Layout rules*/
body{}
div{}
etc{}

/*Typography Rules*/
etc{}

etc...

回答by BrokenGlass

No there is no support for regions in CSS.

不,CSS 中不支持区域。

The usual approach is separating into different CSS files and then use a CSS minification tool for production releases that combines and minifies your CSS, i.e. see minifyor YUI Compressor.

通常的做法是分成不同的CSS文件,然后使用产品发布一个CSS压缩工具,它结合和minifies你的CSS,即见缩小锐压缩机

回答by WAQ

Type regionand press tabyou will get the following

输入region并按下tab你会得到以下信息

/*#region name */

/*#endregion */

where you can edit the nameto give the region a name of your choice.

您可以在其中编辑 为name区域指定您选择的名称。

回答by wotney

You can add Regions to your CSS exactly as you describe by using a visual studio plugin called "Web Essentials" (this is the VS2012 link, but earlier versions are available)

您可以使用名为“Web Essentials”的 Visual Studio 插件完全按照您的描述将区域添加到您的 CSS (这是 VS2012 链接,但早期版本可用)

Then you can simply add regions in your CSS by doing this :

然后,您可以通过执行以下操作简单地在 CSS 中添加区域:

/*#region Footer 
---------------------------------------------------- */
.footerHyperlinks{
  decoration:none;
}
/*#endregion*/

In conjunction with the keyboard shortcut (ctrl+M, ctrl+L) this for me is invaluable. as it instantly reduces your huge, long page that you have to scroll through MUCH, MUCH quicker. Hope that helps you out !!

结合键盘快捷键(ctrl+M、ctrl+L),这对我来说是无价的。因为它会立即减少您必须以更快的速度滚动的巨大而长的页面。希望能帮到你!!

回答by thekip

You should use different CSS files and move them into 1 file while building your application. There are special tools for this that do just that as this is the only way.

在构建应用程序时,您应该使用不同的 CSS 文件并将它们移动到 1 个文件中。有专门的工具可以做到这一点,因为这是唯一的方法。

回答by Behseini

Use type of Media Query! this is too late to answer but I did this for grouping my code and it working perfectly for me

使用媒体查询类型!现在回答为时已晚,但我这样做是为了对我的代码进行分组,它对我来说非常有效

@media all /*'Global Settings'*/{
    body {
       background: red;
       padding-bottom: 120px;
    }
}

@media all /*'Header Settings'*/{
  .add-to-cart-header {
     height: 66px;
     background: #f7f7f7;

  }
}