How come CSS behaves differently when applied through an external stylesheet versus an internal one?

Currently in the process of redoing my personal website from scratch, starting with a fixed bottom navbar. Strange issue arises when trying to style it using an external stylesheet versus an internal one. Specifically, the problem lies with this rule:

.nav li {
      margin: -5px;
}

When applied internally, it functions as expected by eliminating unwanted whitespace between list items on my stacked bottom navbar. However, when placed in the external sheet, the whitespace remains and strange behavior occurs when commenting out parts of the rule. Any insight would be greatly appreciated. Thanks!

UPDATE: The odd thing is that besides linking bootstrap and jquery, there isn't much HTML or CSS present. Just a simple navbar.

Here's the snippet of HTML within the body:

<div class="container-fluid">
  <nav class="navbar navbar-fixed-bottom">
          <ul class="nav nav-pills nav-stacked">
              <li><a class="about" href="about.html"><div class="navTileContent"><i class="glyphicon glyphicon-user" aria-hidden="true"></i><p>about</p></div></a></li>
              <li><a class="portfolio" href="portfolio.html"><div class="navTileContent"><i class="glyphicon glyphicon-briefcase" aria-hidden="true"></i><p>portfolio</p></div></a></li>
              <li><a class="art" href="art.html"><div class="navTileContent"><i class="glyphicon glyphicon-edit" aria-hidden="true"></i><p>art</p></div></a></li>
              <li><a class="contact" href="contact.html"><div class="navTileContent"><i class="glyphicon glyphicon-envelope" aria-   hidden="true"></i><p>contact</p></div></a></li>
          </ul>
      </nav>  

  </div>

And here's the lone CSS code:

<style>

    .nav li {
        margin: -5px;
    }

    .nav li .navTileContent {
        color: #e1e8f4; 
        text-align: center; 
        padding: 1%;    
    } 

    .nav li .navTileContent p {
        padding-left: 20px;
        display: inline;
    }

    .about {
        background-color: #6ad8d1;
    }

    .portfolio {
        background-color: #12d132;
    }

    .art {
        background-color: #12466b;
   }

    .contact {
        background-color: #0d336d;
    }

</style>

Answer №1

In this straightforward example, the styles might not align with yours, but I hope you grasp the concept.

<style>
  li {
    color: orange;
  }
  li.active {
    color: blue;
  }
  li.muted {
    color: red;
  }
</style>
<style>
  li {
    color: blue;
  }
  li.active {
    color: orange;
  }
</style>
<ul>
  <li>This text is not orange</li>
  <li class="active">This text is orange</li>
  <li class="muted">this text is red because its style definition has not been overridden</li>
</ul>

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

Ensure that the footer remains at the bottom of the page without being fixed to the bottom

I am currently working on configuring the footer placement on pages of my website that contain the main body content class ".interior-health-main". My goal is to have a sticky footer positioned at the very bottom of these pages in order to eliminate any wh ...

Can you explain the variance between using @media (max-width: 1000px) and @media and screen (max-width: 1000px) in CSS?

Can someone explain the difference between using @media (max-width: 1000px) and @media and screen (max-width: 1000px) in CSS? When I tested them separately in my code, they seemed to have the same outcome. @media and screen (max-width: 1000px) { .grid ...

Incorporate HTML elements within an Angular component

Looking to dynamically add an Angular HTML element to a component at runtime. Imagine the HTML element is an H1 tag with an Angular expression: <h1>{{testHeading}}</h1> The goal is to insert this tag into a component while preserving its dy ...

Effortlessly aligning icons in social media buttons using Bootstrap

I am encountering an issue with my social media icons that are using font-awesome icons from Bootstrap. The problem is that the icons are not centered. Here is the code I am using, most of which was copied and pasted from an online source: #HTML <!-- ...

Customize the focus color of mat-label within a mat-form-field in Angular

Within my mat-form-field, I have a mat-chip-list set up similar to the example provided in this link. When I click inside the field, the mat-label and what appears to be the border-bottom (not entirely sure) change color when focused. How can I customize t ...

What is the best way to conceal half of a div at the top within another div?

Can someone provide guidance on how to achieve the following effect in CSS? I have attempted setting the outer div with position: relative and the inner div with position: absolute, but it did not work as expected. Your advice is greatly appreciated. Tha ...

What is the best way to showcase HTML content in columns with a horizontal scrolling feature?

I am trying to showcase a list of basic HTML elements such as divs, paragraphs, etc. within a fixed height container, arranged in columns with consistent width. I want them to be horizontally scrollable, similar to the layout displayed in this image. Thi ...

Utilize the power of Nuxt and Vue 3 to create sortable columns in a table, with the ability to only change the icons on the sorted column

I am facing a challenge with my sortable table icons. Whenever I click on an icon to sort a column, all the other icons also change direction. I understand that this is happening because I am toggling the visibility of icons based on the currentSortDir sta ...

I am having trouble adjusting the font size within a <textarea> element in bootstrap 4

After customizing source code for an AJAX chat application and implementing it on a Bootstrap page, I'm looking to modify the font size within the textarea where messages are posted. Below is the HTML code snippet: <textarea class="form-contr ...

Which is Better: Data-URIs or Embedding Fonts for Icons?

Currently, I am in possession of a set of approximately 10 monotone icons all sized at 25x25 or smaller. I am contemplating between two options for better performance: 1) Incorporating them into CSS using data URIs 2) Utilizing them as a font (for exampl ...

Arrangement of 3 columns on the left and 1 column on the right using flex-box layout

My goal is to utilize flexbox in conjunction with bootstrap 4 to produce a design featuring 3 vertically stacked columns on the left, accompanied by a single column on the right that matches the height of the left columns. Following that, there will be som ...

Is there a way to rigorously validate my HTML, CSS, and JavaScript files against specific standards?

Can modern browsers suppress errors in HTML, CSS, and JS sources? Is there a method to uncover all mistakes, no matter how small they may be? ...

Tips for ensuring that your modal functions properly with an image tag within a figure tag

I'm facing an issue with getting a modal to display on my image gallery. The problem arises when the images are enclosed within figure tags, necessary for my hover effect, causing the modal to malfunction. I suspect that the problem lies within the f ...

The fixed table header is misaligned with the body columns' width

I was looking for a way to add a vertical scrollbar to my table, and I ended up wrapping the entire table in a div. The result was that the table head was fixed in position. Is there a simpler method to include a scrollbar in a table without affecting the ...

How can I place a Pure CSS Menu within a Div Container?

I've been experimenting with the Pure CSS menu found on this site: http://csswizardry.com/2011/02/creating-a-pure-css-dropdown-menu/ It's working well, but I'm facing an issue where I want to place this menu inside another div container. H ...

Maximizing Efficiency: Utilizing a Single jQuery Function to Retrieve Specific Values

I have a webpage with select menus for choosing user type, minimum age, and maximum age. I want to select options and send values as an object array to ajax. Initially, the getAjax function is working when the page loads. However, it stops working when I c ...

Are there any jQuery Context Menu plugins clever enough to handle window borders seamlessly?

After reviewing UIkit, as well as some other jQuery Context Menu plugins, I have noticed that they all tend to exhibit a similar behavior: The actual menu div renders outside the window, causing valuable content to be hidden from view. Is there a way to ...

Align a span vertically within a div

I need help aligning the content "ABC Company" vertically within a div using Bootstrap 4's alignment helper classes. Despite my efforts, I have not been successful. Here is the code I am using: <div class="container" style="width: 740px;"> < ...

Including emoticons in text without impacting the 'line-height'

Is there a way to add an emoticon within a paragraph without altering the line-height, regardless of the size of the emoticon? For example: I've tried using position: absolute or vertical-align: text-top, but neither seems to work. p img { hei ...

Creating HTML and CSS templates for rendering with Google App Engine

Currently revamping my website hosted on GAE after a long hiatus. Excited to give it a fresh look :D Implementing the MVC model with Python, WSGI, WebAPP2, and Render.Template to make it happen. All is going smoothly, except for the CSS integration. Str ...