CSS files in DotNetNuke: Which CSS file should I use?

FROM Location: BlogsAnthony Glenwright’s Blog

Some tips for choosing which CSS file to use in DNN for your custom CSS elements.
I get a lot of posts asking about which of DotNetNuke’s CSS files that a portal administrator or web designer should put their custom CSS styles in – especially when end users are customizing the appearance of our SideMenu and TopMenu modules.

DotNetNuke (with a little help from HTML and CSS, of course) gives you a huge amount of flexibility in the layout and design of your website, web portal or web-based application. You can do anything from tweaking a font size or colour here and there to starting a “skin" design from scratch – and DNN implements what I call a “5-tier" model for CSS, where CSS elements for different purposes belong in different CSS files.

Some technical background
The five tiers discussed in this blog are an abstraction – a way of thinking about where to put your CSS to structure it best. Technically, it doesn’t matter which .css file you use – when you have references to multiple CSS files in HTML, they all get counted when the browser renders your output.

The 5 Tiers
module.css:
module.css files exist in the /DesktopModules/[modulename] folder. If there isn’t one already there, you can create the file and it will automatically get used.
Generally I leave the module.css files alone, and reserve them for CSS that the module developer wants to include. If a module developer includes a module.css, it will get overwritten when you next upgrade the module, so it’s a bad place to put your custom css.

portal.css:
portal.css is located in the /portals/[portalid] folder – there’s one for each portal running in your DNN installation. Use portal.css for styles that are intended to be portal-wide. That is, the CSS in portal.css should be intended to affect all skins & pages in your portal. portal.css doesn’t get overwritten when you upgrade modules (or the DNN core), so it’s a safe place to put your custom CSS. I generally create my own skins for each portal, so I tend to use skin.css in favour or portal.css. But if you are using purchased or downloaded skins, this is the best place to put your custom CSS because your skin.css file would be overwritten if you upgrade the skin.

skin.css:
skin.css files are created as part of the skin package – for more detailed information about creating skins, refer to the DNN documentation.
If you control the skin you are using (that is, if you created it yourself instead of purchasing one or using one of the skins that comes with DNN), skin.css is the best place to put your custom CSS elements. The elements in skin.css only affect the skin that the skin.css is for (and all the containers and modules, of course).

container.css:
container.css files are created as part of the container package – for more detailed information about creating containers, refer to the DNN documentation.
container.css should be used for elements that are intended to affect a specific container or group of containers and the modules within them.
portals/_default/default.css:

The default.css file contains CSS defined by the DNN core. This could get overwritten in a DNN upgrade, so it’s safest to leave it alone. However, it contains some non W3C-compliant CSS, so I usually edit it to make it pass the W3C validator.

Summary
The short answer: For custom CSS, if you are designing your own skin, use skin.css. If you are using pre-packaged skins, use portal.css.
The way DNN structures it’s CSS files make CSS seem modular (which is a good thing), but every CSS file referenced within the HTML page that DotNetNuke generates can affect your entire page. There’s no technical reason you can’t put a BODY {background-color: red} in a module.css file, which would affect your entire page, not just the module.

If you exercise some discipline over where you add your own CSS, then the modular nature of the DNN CSS classes works well. If you don’t, it can be very confusing.

DNN Skinning – style-sheets & testing

Kewley on Kode spent some time this weekend on a personal project, trying to fit a web site template that I purchased from TemplateMonster.com into a DotNetNuke portal. The template that I was trying to adapt appeared to me to be a good candidate for a portal-type framework, and an opportunity to try out some of the portal and container skinning features.

The first thing I did was read the skinning documentation that came with DotNetNuke. It’s decent documentation, but the problem is that it touches on so many items that it tends to leave a number of unanswered questions about specifics. I hacked around the generated HTML for a portal page and eventually came up with a better understanding of a few things:

Don’t include references to your style-sheets in your skin and container skin pages. I included these references while building the individual HTML files, and ended up leaving them in during publish. This isn’t necessary. as DotNetNuke will put the css files in known locations and include {link} tags that make reference to them in the appropriate locations. Including a style-sheet reference in your container template will result in a style-sheet reference per container on your rendered portal page, which screws up the by-design hierarchy of styles.

Don’t include {body} or {head} references in your skin HTML files. Again, I had inserted them during the testing phase of my HTML build out. Leaving them in resulted in multiple {body} tags in the rendered portal page. You can (should) achieve the same results that you seek from this type of approach if you:

Learn the built in CSS entities. The portal and containers render with pre-determined class names in various places. You must learn what they are in order to accurately build out your site. Rather than combing through the rendered HTML for class references that are not your own, instead refer to {install point}\Portals\_default\portal.css and {install point}\Portals\_default\Skins\DNN\skin.css. Some notes:

Each portal page renders the style-sheets in the following order:
{install point}\Portals\_default\default.css – the default install template. If you’re trying to figure out there are still dark backgrounds on your portal, it’s probably because you didn’t override a property in this style-sheet.
{install point}\Portals\{active portal}\skins{\active skin}\skin.css. This is the skin.css that you uploaded with your skin package
{install point}\Portals\{active portal}\containers\{active portal container}\container.css. This is the style-sheet of the default container assigned to the portal
{install point}\Portals\{active portal}\portal.css – Set n portal admin / Site Settings from an available skin’s style-sheet

The style that is defined closest to the bottom of the list above will be the style that renders. For instance, if you define .Head (the style for the header bar on a container) in your container or skin, it will override the default setting that is defined in the default.css file.

The SolPartMenu global menu has a large number of settings that you can override in the .XML file that accompanies your skin or container package. That process is a pain – the quick approach for simply trying to get it to look right is to override the Menu settings in your skin css file. Refer to the css class names at the bottom of the {install point}\Portals\_default\Skins\DNN\skin.css file

My approach was to upload the skin and container, then open the four files referenced above and edit/save/refresh to see how the site was affected by css tweaks. When I got to a point where I felt comfortable with the rendered page, I’d update the container package with the new css file and re-upload it.

In order to help target specific page locations, I assigned IDs to some of the table rows in my container HTML file. This let me do things like define a style for a generic HTML entity such as a within a specific page area, like one named #GreenContainerContent

Handle the spacing between your portal elements at the skin level. One-off nudging of space between containers with borders on the container.

All in all the framework that supports skinning is pretty good. I think I’ll post some more in the near future about how the styles on the SolPartMenu work.

「設定大綱階層」與「套用標題樣式」,有何不同點?在樣式中選項「標題」與「目錄」及「內文」與「本文」又有何區別?

取自於公務人員資訊訓練入口網 怡文老師的回覆

有關「設定大綱階層」與「套用標題樣式」的不同點在於:1. 使用段落功能的『大綱階層』設定階層時,僅單純設定各段落階層,至於其他格式設定,可依據各段落需求自行安排。2. 使用樣式設定,會同步設定樣式內所包含的多種格式,不僅是設定大綱階層;若是設定的段落需要同步製作相同格式,則建議採用此法。

其次,「標題」與「目錄」及「內文」與「本文」的樣式區別為:1. 各樣式的名稱不同樣式名稱是由 Word 事先規劃安排的名稱。若對於名稱不滿意,可採用修改樣式的方式設定名稱,但須留意的是:原始名稱仍會被保留,僅是加入新的樣式名稱。2. 各樣式的格式設定條件不同每個樣式皆已事先規劃格式,因此各樣式的格式不同,可使用修改樣式的方式變更樣式內容。3. 預設使用時機各樣式其實都可隨意套用,只是這四個樣式有預設使用時機,因此較常看到。

A.「標題」預設為搭配大綱使用;B.「目錄」預設為搭配插入目錄時的目錄文字所用,在插入目錄時修改目錄樣式;C.「內文」預設為文件的基本格式;D.「本文」是由『內文』複製而出的,是為了避免變更內文格式後,會影響到後續的文件而設計的,因此『本文』的樣式是可以刪除的。因為您的問題大多屬於功能說明或功能比較的部份,因此,僅能簡單比較各功能之間的明顯差異,與主要定義差別;若有時間,建議您可以參閱相關書籍,做進一步的了解。

2006/7/24 14:40