Do styles operate differently depending on whether they are within the HTML head tags or not?

I am currently working on a project to create a simple website where a div containing text is centered both horizontally and vertically on the page.

Despite thinking this would be a straightforward task, I encountered some strange issues. Let's refer to the working source as Source A.

<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans" rel="stylesheet">

<!DOCTYPE html>
<html>
  <head> 
    <meta charset="utf-8">
    <title>Jacob Garby</title>
  </head>
  <body>
    <div class="wrap">
      <div class="content">Test</div>
    </div>
  </body>
</html>

On the other hand, the non-working source will be referred to as Source B.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Jacob Garby</title>
    <link rel="stylesheet" href="styles.css">
    <link href="https://fonts.googleapis.com/css?family=Josefin+Sans" rel="stylesheet">
  </head>
  <body>
    <div class="wrap">
      <div class="content">Test</div>
    </div>
  </body>
</html>

Both sources utilize the same stylesheet shown below:

* {
  font-family: 'Josefin Sans';
  margin: 0;
  padding: 0;
}

div.wrap {
  display:flex;
  justify-content:center;
  align-items:center;
  width:100%;
  height:100%;
}

div.content {
  border: 1px solid red;
  text-align: center;
  width: 100%;
}

The issue arises when the vertical alignment of div.wrap only works when the stylesheets are linked outside of the head tag. This difference between the two sources has me puzzled.

Traditionally, stylesheets should be included in the head tags. Therefore, it's perplexing that it exclusively functions when done otherwise.

I can't provide examples through jsfiddle due to the restriction on modifying stylesheets. I've tested this on Opera, Firefox, and Chrome, but the problem persists across all browsers.

Could this behavior be an HTML bug? Or have I overlooked something obvious?


Refer to the following screenshots for clarification.

Source A: https://i.sstatic.net/Rt5lk.png

Source B: https://i.sstatic.net/5vIRR.png

Upon inspecting the source in a web browser, even with the stylesheet linked outside the head tag, it appears to automatically move into the head section. In essence, the stylesheet is always placed within the head tag when viewed.

To summarize my query:

Why is this peculiar behavior occurring, and how can I rectify it?

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

Is it possible to customize the arrow on a drop-down menu?

Here is an example of the page I am facing issues with: If you look at the right side of the bottom bar, you will notice a selection option for different themes. I have been attempting to replace the down arrow with an image. Below is the code I have used ...

The Ajax post is only activated on one occasion

Hello there, I am encountering a problem with an ajax function. My goal is to post data to a database and then update a table that displays the database information. Strangely, the process works fine the first time - data is posted and the table is refresh ...

What could be the reason for the Javascript function failing to run?

I need assistance in executing a function called "send()" which includes an AJAX request. This function is located in ajax.js (included in the code snippet) The Ajax success updates the src attribute of my image. The function seems to be working correctly ...

A comprehensive guide on adjusting the height of images dynamically using only CSS

Calling all CSS experts: I'm curious if it's doable to replicate the image scaling effect seen on this website using only CSS? Please note that the images only begin scaling when the height of the browser window changes, not its width. (I menti ...

Setting up Anaconda and debugging Python code in Visual Studio Code

Recently, I updated my Python version from 3.6.x to 3.9 while using VS Code with Anaconda. However, this update seems to have caused some instability in my Anaconda environment. Previously, when launching VS Code, it would automatically run the "conda acti ...

Issue with JQuery Ajax form causing unexpected page refresh in Safari but not in Firefox (working properly)

Currently, I am working on an AJAX form that is housed within a JQUERY UI Dialog. Everything runs smoothly in FireFox; however, there seems to be a glitch in Safari as it refreshes the page to: /? If you notice any discrepancies or errors here, please do ...

What is the best way to remove query string parameters prior to running a function when a button is clicked?

I'm facing an issue trying to implement a button that filters events based on their tags. The problem arises when the tag value in the query string parameter does not clear when other buttons are clicked. Instead, the new filter tag value adds up with ...

Pressing an HTML button can enable and disable the pause and resume functions

Currently, I am working on an audio player where I need to implement functionality to pause and resume the playback. I have already set up the pause() and resume() functions in my script. The issue I am facing is related to the HTML button that triggers th ...

Struggling to make Tumblr Javascript function properly

I have integrated the following code snippet: <script type="text/javascript" src="http://underlineent.tumblr.com/api/read/json"> </script> Unfortunately, my Tumblr blog is not appearing on this site. Can anyone provide assistance? The provid ...

Retrieve the values of each cell in a table row by utilizing jQuery

With the click of a button labeled "save", I aim to extract the data stored in each cell within a selected table row protected by a checkbox. Here's the scenario: When a user triggers the show table button, my page dynamically populates with informati ...

transforming html into json using PHP

I am encountering an issue where I am making a PHP request and receiving the response in HTML format. How do I go about converting this response to JSON format? case 'getzipcode': $CITY= @$_POST['city']; $STREET= @$_POST['street& ...

Issue with :hover pseudo-class in IE8

If you're unsure about my explanation, check out the video for a visual demonstration. Pay close attention to the cursor movements while I attempt to optimize my website for IE8. Hopefully there is a solution to this issue. Thank you in advance! http ...

Tips for assigning dynamic #id(*ngFor) and retrieving its value in Angular2

In my HTML file, I have the following code snippet: <tr *ngFor="let package of packages"> <td *ngFor="let coverage of coverages"> <input type="hidden" #dynamicID [value]="coverage.id"> <-- Include an identifier with the vari ...

I'm looking to display images in a designated React component using create react app. What is the best way to accomplish

Currently in the process of revamping an older website using react. Making progress, but encountering an issue with a new component where images are not displaying. Strangely, the images appear in the main class but not within the component class. Even whe ...

Currently experiencing difficulties while attempting to create a Simon game in JavaScript. Seeking assistance to troubleshoot the issue

var buttonColor = ["red", "blue", "green", "yellow"]; var userClickedPattern = []; var gamePattern = []; var totalKey = []; var level = 0; $("*").on("keydown", function(m) { var key = m.key; totalKey.push(key); var keyLength = totalKey.leng ...

What is the purpose of calling Array.prototype.filter on the 'forms' array with the function(form)?

I'm struggling to grasp the inner workings of this code snippet. It appears to be a piece of form validation code taken from Bootstrap and pasted here. My confusion arises from this line var validation = Array.prototype.filter.call(forms, function(f ...

Converting an HTML <img> tag into a Base64 encoded image file: Step-by-step guide

Recently, I made changes to the appearance of an image by adding CSS filters using the "style" attribute of an <img> tag. <img src="myImage.png" style="filter: grayscale(100%)"> As a result, the image now has a different look and I am looking ...

Enhance Your Highcharts Funnel Presentation with Customized Labels

I am working on creating a guest return funnel that will display the number of guests and the percentage of prior visits for three categories of consumers: 1 Visit, 2 Visits, and 3+ Visits. $(function () { var dataEx = [ ['1 Vis ...

Delete the span element if the password requirements are satisfied

I am implementing password rules using span elements. I aim to dynamically remove each span that displays a rule once the input conditions are met. Currently, I have succeeded in removing the span related to the minimum length requirement but I am unsure h ...

Refresh the Content of a Page Using AJAX by Forcing a Full Reload

I have a webpage that automatically updates a section using jQuery AJAX every 10 seconds. Whenever I modify the CSS or JavaScript of that page, I would like to include a script in the content fetched via AJAX to trigger a full page reload. The page is ac ...