Custom CSS Styling Takes Precedence

I'm encountering some issues with the styling of a landing page on SharePoint.

SharePoint tends to override HTML with its own, resulting in some odd styling.

While there are table elements that show up with the element selector in the developer tools on the page, I don't think they're causing any conflicts with my custom HTML. The two elements that seem to be interfering with my HTML/CSS are #s4-bodyContainer and #contentRow. It appears that #s4-bodyContainer is not expanding properly even after setting margin to 0 and width to 100%. This prevents the content from covering the entire width/height of the containing div.

Below is the relevant 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>

Check out how they appear on the page: https://i.sstatic.net/CGnwU.jpg https://i.sstatic.net/f1HZX.jpg

Answer №1

It seems that the CSS rules applied to the #s4-bodyContainer element in SharePoint are not inline, but are instead coming from an external file called corev15.css. This means that you can override these rules by adding your own CSS at the end of the master-page body. If this doesn't work, you always have the option of using the !important tag to prioritize your CSS properties. For more information on CSS specificity, check out CSS Specificity.

Answer №2

Simply adding ! important does not always solve the issue. The problem with using ! important is that your styling library may also utilize it, causing conflicts. To troubleshoot, inspect the specific section in question using Google Inspector or another browser inspector to confirm whether the margin and width properties are being applied correctly. Check for a property named max-width as well. If making slight adjustments with ! important does not resolve the issue, consider utilizing inline CSS instead.

Answer №3

There is an issue with spacing if the image is used as an original inline element, like a text element. Here's the solution:

Just add
display:block; to .troopers
See the example below!

(Alternatively: set line-height: 0; font-size: 0 to the wrapper of the image div.tst. This will prevent unwanted space from text effects as well.)

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>

Answer №4

Hours of searching through various resources online led me to a thread on the Microsoft Developer Network that addressed my problem:

The suggested fix involved adding the following code snippet to the stylesheet:

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

Amazingly, it resolved the issue!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When the mouse is moved, display a rectangle on the canvas

I am having an issue with drawing a rectangle on canvas. The code below works fine, except that the path of the rectangle is not visible while the mouse is moving. It only appears when I release the mouse button. Any assistance would be greatly appreciate ...

Learn how to dynamically set the "selected" option in Vue based on object data

I've done some digging on SO but haven't found exactly what I need. So, here's the situation - I've got a sorting function in progress. I have an array of date ranges (PayPeriods) that I want to render into a select with option compone ...

Display a form with hidden input that dynamically updates on any input change

<form id="pricecal"> <input type="text" onchange="calprice()" class="form-control round-corner-fix datepicker" data-provide="datepicker" placeholder="Check in" value="" required /> <input type="text" onchange="calprice()" class="form ...

Interact with elements across multiple SVG files using HTML

I have a website that consists of three SVGs. I am now looking to connect elements in these different SVGs by drawing simple lines between them. My goal is to create a line from element1 (#element1) in svg1 to element6 in svg2. Unfortunately, I am unable ...

The Angular Shepherd Tour Guide is experiencing a bug where it does not scroll when the next page is clicked

I'm facing an issue where scrolling to the next element is not working properly. When I click on the next element, it moves there but does not scroll down automatically. I have tried various solutions but have been unsuccessful so far. If anyone can p ...

"My original CSS styles are being overridden by a template page's CSS code

I am encountering an issue where the fonts in my application are getting changed when I include a template page called template.html with CSS that includes body{ font-family:'Arial'}. The template page is being included using 'ng-include&apo ...

issue with Bootstrap footer causing a horizontal line to appear

Check out this straightforward Bootstrap footer grid example here: <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9I ...

Utilizing checkboxes for toggling the visibility of buttons in Angular

I want to dynamically show or hide buttons based on a checkbox. Here is the HTML code I am using: <input class="form-check-input" [(ngModel)]="switchCase" type="checkbox" id="flexSwitchCheckChecked" (change)=" ...

Manipulate the child elements within a list by altering their IDs with jQuery

I'm currently using jQuery to dynamically add options to a select tag from a dictionary. I now need to set the title attribute of each option based on the keys in the dictionary. Can anyone suggest a solution for this? JQuery function addOptions(){ ...

The mask feature is not functioning properly in Internet Explorer

Hello everyone, I'm attempting to blur the edges of an image from one side only using the mask property so that the background of the body tag blends with the image. Take a look at the example image below. I've tried implementing it as demonstra ...

Prevent the CSS and Jquery Slideshow from endlessly looping

I've just started working with JQuery and I'm having trouble figuring out how to prevent my jquery and css slideshow from continuously looping. Below is the code snippet: HTML: <div id="slideshow"> <div> <img src="Slide1.gi ...

What is the best way to show the current date and time in an Angular template while ensuring it stays up to

I'm looking to showcase the current date and time in my angular template, and have it automatically refresh when the time changes. The desired application LOOKS as follows: This snippet is from my .html template: <div class="top-right pull-right ...

Is it possible for my node.js application to retrieve the version number of npm?

I am currently working on a Node.js web application that relies heavily on version numbers. Whenever I update the version number, I find myself making changes in three different locations: Update in server.js const version = 'v1.2.3' Also Upd ...

Sorting across several lists leads back to the initial list

I currently have multiple lists, with each list and item sharing the same class. For example: <ul class="cat_1"> <li class="cat_1">Item1</li> <li class="cat_1">Item2</li> <li class="cat_1">Item2</li> ...

Designing the child table layout using grid grouping in ExtJS4

I have customized my Extjs4 grid grouping implementation to hide the expand-collapse sign and prevent group header expansion for empty groups. However, I am facing an issue where a white 1px border is being created due to the following CSS class: .x-grid- ...

Learn the process of linking directly to specific tab pages instead of the main page

I am working on a project where I have a page with three tabbed menus - Basics and Pro. What I would like to do is create another page with three links, each of which will hyperlink to a particular tab menu. Is there a way to pass a tabbed menu link to an ...

Error: Trying to access the parent node of an undefined property

After incorporating this script into my webpage for the newsletter sign-up process, I aimed to reveal customized content post user subscription. <script> function insertAfter(referenceNode, newNode) { referenceNode.parentNode.insertBefore(newNode ...

Developing a fixed footer in Angular 7 using the Bootstrap4 framework

I am currently learning angular7 and I have been struggling to create a sticky footer. Despite trying multiple solutions, none seem to work for me. Here are some of the solutions I have attempted: https://getbootstrap.com/docs/4.3/examples/sticky-footer ...

What is the best way to extract the li tag using Selenium in Python when dealing with class name spaces?

<div class="all__BrandsAllListGrid-sc-1410m2d-5 eWrRoU"><li class="all__BrandsAllListItem-sc-1410m2d-6 kLYBAG"><a href="/brands/00-seeds">00 Seeds</a></li><li class="all__BrandsAllListItem ...

Is the search feature in the Bootstrap 4 dual listbox plugin experiencing issues?

Using the filter option in Bootstrap 4 dual listbox, I noticed that when two results appear and I select the second option, the first option is automatically added to the list. https://www.jqueryscript.net/demo/Responsive-jQuery-Dual-Select-Boxes-For-Boot ...