CSS 样式被覆盖

CSS Styling Overridden

我在 SharePoint 上的着陆页样式方面遇到问题。

SharePoint 喜欢用自己的东西覆盖 HTML,这使得样式有点时髦。

有几个 table 元素与页面上开发人员工具中的元素选择器一起出现,但我认为这些元素不会干扰我的自定义 HTML。出现了两个 s,我相信是在搞乱我的 HTML/CSS。他们都是 #s4-bodyContainer & #contentRow。我看得越多,它似乎不会填充#s4-bodyContainer。我已将其边距更改为 0,宽度也更改为 100%,但内容仍然无法覆盖包含 div?

的整个 width/height

这是我的相关 HTML/CSS:

header {
    text-align:center;
    background: #104723;
    overflow:auto;
}
.flexbox-container {
    display:flex;
    align-items:center;
    background:#f2f2f2;
    width: 100%;
}
#s4-bodyContainer {
    margin: 0;
    width: 100%;
}
#s4-workspace{
    overflow: hidden;
    margin: 0;
}
footer {
    background: #104723;
    color: #104723;
    height: 85px;
    width: 100%;
}
.headhead {
    color: white;
}  
.flexbox-container > * {
    flex:1;
    min-width:0;
    margin:0;
}
.tst{
    position: relative;
}
.troopers {
    max-width:100%;
    filter: drop-shadow(2px 2px 5px #000);
}
button {
    display:block;
    margin-top:50px; 
}
.black {
    font-size:25px;
    color: #104723;
    font-weight: bold;
}
.logo {
    float: right;
    margin-top: 5px;
    margin-bottom: 5px;
    margin-right: 5px;
}
.gold {
    font-size: 35px;
    color: #b3ab7d;
    font-weight: bolder;
    margin-top: -15px;
}
.btn-group .button {
    background-color: #104723;
    border: 1px solid;
    color: #b3ab7d;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
}
.selector {
    float: left;
    overflow: hidden;
  }
  
  .selector .btnselect {
    background-color: #104723;
    border: 1px solid;
    color: #b3ab7d;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
}
  .item-select {
    display: none;
    position: absolute;
    background-color: #e7e7e7;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
  }
  .item-select a {
    float: none;
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
  }
  
  .item-select a:hover {
    background-color: #ddd;
    color: black;
  }
  
  .selector:hover .item-select {
    display: block;
  }
  #sideNavBox { DISPLAY: none }
  #contentBox { margin-left: 0 }
  
.flexbox-container {
    margin-top: 0px;
    width: 100%;
}
html, body {margin: 0; height: 100%; overflow: hidden}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta charset="UTF-8">
        <title>Example Landing Page</title>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        </head>
    <body>
        <!--<header>
            <h1 class="headhead">Active Projects</h1>
        </header>-->
        <div class="flexbox-container">
            <div class="tst">
                <img class="troopers" src="https://www.usxjobs.com/wp-content/uploads/2016/05/TROOPERS-2a.png" alt="troopers"/>
            </div>
            <div>
                <h1 class="black">Welcome to the Projects Site</h1>
                <h1 class="gold">Insert Sample Text</h1>
                <div class="selector">
                    <a href="" target="_blank"><button class="btnselect">Site 1
                     <i class="fa fa-caret-down"></i>
                   </button></a>
                   <div class="item-select">
                       <a href="" target="_blank">Sub 1</a>
                       <a href="" target="_blank">Sub 2</a>
                       <a href="" target="_blank">Sub 3</a>
                   </div>
                   </div>
                   <div class="selector">
                    <a href="" target="_blank"><button class="btnselect">Site 2 
                        <i class="fa fa-caret-down"></i>
                      </button></a>
                      <div class="item-select">
                          <a href="" target="_blank">Sub 1</a>
                          <a href="" target="_blank">Sub 2</a>
                          <a href="" target="_blank">Sub 3</a>
                          <a href="" target="_blank">Sub 4</a>
                          <a href="" target="_blank">Sub 5</a>
                      </div>
                      </div>
            </div>
        </div>
        <footer>
            <img src="" class="logo"/>
        </footer>
    </body>
</html>

这是它们在页面上的样子:

如果我没记错的话,SharePoint 上 #s4-bodyContainer 的 CSS 规则不是内联的(来自外部文件:corev15.css)。这意味着如果您将 CSS 附加到母版页主体的末尾,您应该能够覆盖它们。如果它不起作用,您可以求助于 !important 标记来为您的 CSS 属性赋予优先级。结帐 CSS Specificity.

正在使用! important 并不总能解决问题。问题基本上与!重要的是你的样式库可能也在使用它。因此,请尝试通过 Google 检查器或任何其他浏览器检查器检查您的边距和宽度 属性 是否应用于该特定部分。尝试检查您的样式软件是否创建了一个名为 max-width 的 属性 以及是否正在应用它。最重要的是,如果稍作修改和摆弄!重要的是不起作用。去内联 css..

如果将图像用作原始内联元素(如文本元素),则 space 会出现问题。解决方案:

只需添加
display:block;.troopers
请参阅示例!

(备选方案:将 line-height: 0; font-size: 0 设置为图像 div.tst 的包装器。这也避免了文本效果中的意外 space。)

header {
    text-align:center;
    background: #104723;
    overflow:auto;
}
.flexbox-container {
    display:flex;
    align-items:center;
    background:#f2f2f2;
    width: 100%;
}
#s4-bodyContainer {
    margin: 0;
    width: 100%;
}
#s4-workspace{
    overflow: hidden;
    margin: 0;
}
footer {
    background: #104723;
    color: #104723;
    height: 85px;
    width: 100%;
}
.headhead {
    color: white;
}  
.flexbox-container > * {
    flex:1;
    min-width:0;
    margin:0;
}
.tst{
    position: relative;
}
.troopers {
    /* ADD ... */
    display: block;
    max-width:100%;
    filter: drop-shadow(2px 2px 5px #000);
}
button {
    display:block;
    margin-top:50px; 
}
.black {
    font-size:25px;
    color: #104723;
    font-weight: bold;
}
.logo {
    float: right;
    margin-top: 5px;
    margin-bottom: 5px;
    margin-right: 5px;
}
.gold {
    font-size: 35px;
    color: #b3ab7d;
    font-weight: bolder;
    margin-top: -15px;
}
.btn-group .button {
    background-color: #104723;
    border: 1px solid;
    color: #b3ab7d;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
}
.selector {
    float: left;
    overflow: hidden;
  }
  
  .selector .btnselect {
    background-color: #104723;
    border: 1px solid;
    color: #b3ab7d;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
}
  .item-select {
    display: none;
    position: absolute;
    background-color: #e7e7e7;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
  }
  .item-select a {
    float: none;
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
  }
  
  .item-select a:hover {
    background-color: #ddd;
    color: black;
  }
  
  .selector:hover .item-select {
    display: block;
  }
  #sideNavBox { DISPLAY: none }
  #contentBox { margin-left: 0 }
  
.flexbox-container {
    margin-top: 0px;
    width: 100%;
}
html, body {margin: 0; height: 100%; overflow: hidden}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta charset="UTF-8">
        <title>Example Landing Page</title>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        </head>
    <body>
        <!--<header>
            <h1 class="headhead">Active Projects</h1>
        </header>-->
        <div class="flexbox-container">
            <div class="tst">
                <img class="troopers" src="https://www.usxjobs.com/wp-content/uploads/2016/05/TROOPERS-2a.png" alt="troopers"/>
            </div>
            <div>
                <h1 class="black">Welcome to the Projects Site</h1>
                <h1 class="gold">Insert Sample Text</h1>
                <div class="selector">
                    <a href="" target="_blank"><button class="btnselect">Site 1
                     <i class="fa fa-caret-down"></i>
                   </button></a>
                   <div class="item-select">
                       <a href="" target="_blank">Sub 1</a>
                       <a href="" target="_blank">Sub 2</a>
                       <a href="" target="_blank">Sub 3</a>
                   </div>
                   </div>
                   <div class="selector">
                    <a href="" target="_blank"><button class="btnselect">Site 2 
                        <i class="fa fa-caret-down"></i>
                      </button></a>
                      <div class="item-select">
                          <a href="" target="_blank">Sub 1</a>
                          <a href="" target="_blank">Sub 2</a>
                          <a href="" target="_blank">Sub 3</a>
                          <a href="" target="_blank">Sub 4</a>
                          <a href="" target="_blank">Sub 5</a>
                      </div>
                      </div>
            </div>
        </div>
        <footer>
            <img src="" class="logo"/>
        </footer>
    </body>
</html>

在深入了解互联网上任何可能对这个问题有远程帮助的内容后,我终于在 MSDN 上遇到了一个类似的主题:

解决方案说要实现这个:

  .ms-webpartPage-root{
border-spacing:0px!important;
}

而且有效!