If you are working on custom SharePoint 2013 master pages, designs and/or CSS, these little CSS classes and style statements may give you some grief, or save your tooshie…  This list will continue to be updated as I come across more!

Here is a quick table of contents for easier browsing:

Style statements that suck

Classes that save the day

Style statements that suck

Site background – Class: ms-backgroundImage

First we will check out this style statement, found in corev15.css:

.ms-backgroundImage {
/* [ReplaceBGImage] */ background-image:url();
}

If you have a composed look (theme) applied or background image applied via the composed look (AKA “Change the Look”) it will be plugged in here. Otherwise the background image parameter is still passed through but with a blank value (so it looks just the same as the statement above). When you are applying a background image to a site via CSS, most people would do this:

body {
background: url(insert image file here);
}

But this won’t work in SharePoint because of the ms-backgroundImage class automatically applied to the BODY tag. That is right… I said automatically applied. It doesn’t matter what your HTML or Master Page has, this class will still be added to your BODY tag when the page renders. And because the SharePoint class (ms-backgroundImage) has a higher specificity than using BODY only (specificity score is 10 vs. 1) the blank value for background-image will override what you set in your CSS. No worries, it can be fixed by simply doing this:

body.ms-backgroundImage {
background: url(insert image file here);
}

By adding BODY to the style statement you increase the specificity score to 11 and now your custom CSS will take precedence over the OOTB style statement. If you are scratching your chin over the 10 vs. 1 specificity, check out our post SharePoint CSS and CSS Specificity.

Site background overlay – Class: ms-core-overlay

Take a look over in corev15.css and you will find this:

.ms-core-overlay {
/* [ReplaceColor(themeColor:"BackgroundOverlay")] */ background-color:rgba( 255,255,255,0.85 );
}

This applies an 85% opacity white background to the main content area wrapper in your SharePoint site. Or if a composed look (theme) has been applied, then the background color specified in the color scheme file is applied. No big deal if you are keeping the white background, but as soon as you implement a background color or image on (most typically) the BODY tag in your CSS, everything picks up a nice milky white sheen. Nix this in one of two ways:

  1. Delete the CSS class from the s4-workspace tag in the master page. Change this:

    <div id="s4-workspace" class="ms-core-overlay">

    To this:

    <div id="s4-workspace">

    This will disable the ability to override the background color using a composed look (theme).

  2. Add this to your custom CSS file:
    .ms-core-overlay {
    background-color: transparent;
    }

Style statement for headers

I have to admit I find the inclusion of this next one a bit baffling. But at least it is easy enough to fix. In corev15.css there is this style statement:

h1,h2,h3,h4,h5,h6,.ms-h1,.ms-h2,.ms-h3,.ms-h4,.ms-h5,.ms-h6 {
margin:auto;
font-weight:normal;
}

When you then use a header tag like <H1> in your code, it will automatically be centered within its container. This is because of the margin: auto, which is telling the browser to auto calculate all four margins around the header element which results in equal widths and heights for the four sides, thus centering the content.

This style statement is also removing the default bolding for the headers (font-weight: normal).

You can fix this by resetting the margin for the entire style statement or selectively as your needs arise. And if needed you can reset the bolding as well.

#s4-bodyContainer h1 {
margin: 0;
font-weight: bold;
}

It isn’t necessary to include #s4-bodyContainer but this is an example of using a descendent selector to pinpoint which H1s you want to modify.

Site Logo – Class: ms-siteicon-a & ms-siteicon-img

One of the things you or your users can modify in your site is the site title, logo and description. Setting the site logo file is a simple thing and can be useful if you have different clients, departments, divisions, etc. and you want some site to site customization. If you are sticking with the OOTB layout you will be fine, but if you are using the site logo control in your custom layout, you will more than likely need to modify some styles.

The following two style statements are in corev15.css:

.ms-siteicon-a {
display:inline-block;
max-width:180px;
max-height:64px;
}
.ms-siteicon-img {
display:block;
max-width:180px;
max-height:64px;
}

These statements restrict the height and width of the logo image, no matter the actual dimensions of the logo file that you upload to the site. The first one (ms-siteicon-a) is applied to the wrapping hyperlink and the second (ms-siteicon-img) to the image tag. Having both is actually redundant. So you need add a new statement that allows any dimensions:

.ms-siteicon-img,
.ms-siteicon-a {
max-height: 100%;
max-width: 100%;
}

As an extension of this, you don’t have to use 100% for the values. If you want to restrict the allowed size you can set it to be whatever values you like.

Classes that save the day

Fixed width design – Class: s4-nosetwidth

This class look familiar?   It is a carry-over from SharePoint 2010.  If you want to use a fixed width design (for example restrict the width of your site to 960px), you have to add this CSS class to the s4-workspace container.

<div id="s4-workspace" class="s4-nosetwidth">

Remove from dialog box – Class: ms-dialog

Yet another carry-over from SharePoint 2010 is the class assigned to a parent element wrapped around the contents of the modal window / dialog box that pops up for various actions in SharePoint. Based on what you see in the master page, you could add “s4-notdlg” or “ms-dialogHidden” as a class to every element you don’t want to show in the modal window (for example your custom header or nav). However this is a pretty tedious way to hide things. Instead you can use the ms-dialog as the parent in a descendant selector in a CSS style statement and set the display to none. Our post, An easier way to hide page elements from the SharePoint dialog box, goes into detail about how to do this and still applies for SharePoint 2013.

.ms-dialog .myelement {
display: none;
}

More to come as they are discovered!

PS:

refer to: http://blog.sharepointexperience.com/2013/05/sharepoint-2013-css-classes-that-suck-and-save-the-day/

SharePoint 网站中定义的页面背景图片不起作用的更多相关文章

  1. netbeans中给jpanl添加背景图片制定代码的理解——匿名内部类继承父类

    此测试是为了仿照在netbeans中给jpanl添加背景图片的制定代码的执行过程 在JpDemo中定义了个Car类的数据类型,但在给其赋值对象时使用了匿名内部类,继承了Car类,是其子类,并重写了父类 ...

  2. 将w3cplus网站中的文章页面提取并导出为pdf文档

    最近在看一些关于CSS3方面的知识,主要是平时看到网页中有很多用CSS3实现的很炫的效果,所以就打算系统的学习一下.在网上找到很多的文章,但都没有一个好的整理性,比较凌乱.昨天看到w3cplus网站中 ...

  3. 在Vue项目中,添加的背景图片在服务器上不显示,如何处理

    遇到的问题: 在vue项目开发过程中,我们常常会在页面中添加背景图片.可是当我们在样式中添加了背景图片,编译打包部署到服务器上时,发现图片并不能显示出来,这是为什么呢~~~ 我们一般写的css样式如下 ...

  4. 如何生成报告来枚举出整个sharepoint环境中的每个页面所使用的所有webpart

    背景 我的公司的SharePoint环境中购买了大量的第三方webpart,比如Quick Apps, Telerik RadEditor, Nintex Workflow等等..这样做的好处就是成本 ...

  5. iOS 中 为UIView添加背景图片

    创建UIImage的方法有两种: UIImage *image = [UIImageimageNamed:@"image.jpg"];//这种不释放内存,要缓存 NSString ...

  6. spring MVC中定义异常页面

    如果我们在使用Spring MVC的过程中,想自定义异常页面的话,我们可以使用DispatcherServlet来指定异常页面,具体的做法很简单: 下面看我曾经的一个项目的spring配置文件: 1 ...

  7. VC++MFC对话框程序中给对话添加背景图片

    VC对话框怎么显示背景图片呢.在MFC中实现背景图片,不像C#应用程序那么简单.今天就和朋友们说说如何在VC界面中设置背景图片 ^_^   工具/原料 Visual C++ 2010 方法一:用Pic ...

  8. C#中给RICHTEXTBOX加上背景图片

    在系统自带的RichTextBox中是无法给它设置背景图片,但是我们在某些场合可能需要给RichTextBox设置背景图片.那么怎么实现这一想法呢?经过研究发现通过其它巧妙的途径可以给RichText ...

  9. IE9以下通过css让html页面背景图片铺满整个屏幕

    第一种方法不设为背景图片,通过css来控制样式,可兼容到IE6,代码如下: <!DOCTYPE html> <html lang="en"> <hea ...

随机推荐

  1. CentOS 7 安装 vmware tools 提示The path "" is not a valid path to the 3.10.0-957.el7.x86_64 kernel headers.

    输入“mkdir /mnt/cdrom”在/mnt目录下新建一个名为cdrom的文件夹 mkdir /mnt/cdrom 输入“mount -t iso9660 /dev/cdrom /mnt/cdr ...

  2. nginx 与 Windows 错误

    设置根目录 root "D:/www/app"; proxy_pass 反向代理 404 location php 模块添加 fastcgi_split_path_info ^(( ...

  3. 使用CocoaPods更新第三方库出错的解决办法

    使用CocoaPods更新第三方库出错的解决办法 执行完pod install或pod update之后,控制台抛出以下警告信息: [!] The xx [Debug] target override ...

  4. c# rc4算法,加密解密类

    rc4算法,原理,以密匙生成256位的密匙流,然后以车轮式滚过源数据异或加密. /* * 由SharpDevelop创建. * 用户: YISH * 日期: 04/04/2015 * 时间: 03:0 ...

  5. C/C++函数调用约定与this指针

    关于 C/C++ 函数调用约定,大多数时候并不会影响程序逻辑,但遇到跨语言编程时,了解一下还是有好处的. VC 中默认调用是 __cdecl 方式,Windows API 使用 __stdcall 调 ...

  6. CSS鼠标悬停图片加边框效果,页面布局发生错位的解决办法

    CSS鼠标悬停图片加边框效果,页面布局发生错位的解决办法 .recomend-list{ width:1200px; a{ @extend %fl; margin-right: 30px; width ...

  7. CorelDRAW X6冰点价加推800套燃爆6月

    CorelDRAW是迄今最具创意的图形设计程序,并获得所有行业的公认的知名工具.在刚刚结束的CorelDRAW X6限量活动之后,CorelDRAW官方继续加推800套CorelDRAW X6满足用户 ...

  8. 洛谷P1816 忠诚 分块

    分块真的是很暴力呀… 暴力查询左端,暴力查询又端点,中间整体部分直接 $O(1)$ 求出. 注意编程细节:belong[i]=(i−1)/block+1,这样可以保证序列被分成这样的: Code: # ...

  9. 利用after和before伪类实现chrome浏览器tab选项卡斜边纯css无图制作笔记

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  10. Android开发进度02

    1,今日:目标:创建第一个android项目,创建android虚拟机 2,昨天:完成eclipseandroid环境的搭建 3,收获:修改.xml文件,将出错地方解决 4,问题:版本问题