HTML DOCTYPE causing havoc with my CSS styling

When using the materialize framework, I've noticed that adding <!DOCTYPE html> causes my CSS to not be recognized. However, everything works fine without <!DOCTYPE html>. Any suggestions on how to resolve this issue?

Update :

    <?php 
    session_start();
?>
<!DOCTYPE html>
<html>
<head>
    <title>Material</title>
    <meta name="robots" content="index, follow">
    <meta name="googlebot" content="index, follow">
    <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!--Import Google Icon Font-->
        <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type="text/css">
        <!-- Compiled and minified CSS -->
        <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css">
        <!--Import jQuery before materialize.js-->
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <!-- Compiled and minified JavaScript -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/js/materialize.min.js"></script>
        <script>
            $( document ).ready(function(){
                $(".button-collapse").sideNav();
            });
        </script>

        <style>
            body{background-color:#fcfcfc;}

            .logo{
                height:70%;
                margin-top:10px;
                margin-left:10px;
            }
            @media only screen and (max-width: 992px){
                .logo{          
                    margin-left:0px;
                }
            }
            .button-collapse{
                margin-left:5px;
            }
        </style>
</head>
<body>
            <div class="navbar-fixed">
                <nav class="blue lighten-1">
                    <div class="nav-wrapper">
                      <a href="index.php" class="brand-logo"><img src="images/logo.png" class="logo" /></a>
                      <a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
                      <ul class="right hide-on-med-and-down">
                        <li><a href="index.php" class="waves-effect waves-light">Home</a></li>                          
                        <li><a href="#" class="waves-effect waves-light">Login</a></li>
                        <li><a href="#" class="waves-effect waves-light">Signup</a></li>
                        <li><a href="#" class="waves-effect waves-light">Contact Us</a></li>
                      </ul>
                      <ul class="side-nav" id="mobile-demo">
                        <li><a href="index.php" class="waves-effect waves-light">Home</a></li>
                        <li><a href="#" class="waves-effect waves-light">Login</a></li>
                        <li><a href="#" class="waves-effect waves-light">Signup</a></li>
                        <li><a href="#" class="waves-effect waves-light">Contact Us</a></li>
                      </ul>
                    </div>
                  </nav>
            </div>

    <div class="row header-img">

    </div>

</body>
</html> 

Answer №1

One possible explanation is that browsers automatically switch to a more accurate rendering engine mode once they encounter a doctype declaration in the file.

If the inclusion of a doctype is leading to issues, it's likely that there are underlying problems in your code that are being masked by chance or trial and error. It's also plausible that any issues could stem from bugs introduced in the more standards-compliant rendering mode.

In the absence of a doctype, your page will be rendered in quirks mode, meaning the browser will apply outdated rules established by older browsers to both your HTML and CSS. Having a valid doctype is crucial for proper HTML structure, and using a correct and up-to-date doctype ensures your document is displayed in Standards Compliant mode. Additionally, your stylesheets should have a media type of text/css.

To better pinpoint the issue at hand, providing your CSS code could aid in diagnosing the exact problem.

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

What could be causing the slider to have a choppy transition between images?

The Issue: Looking at this GIF, you can see that the image transitions are not seamless. The slider is built on Bootstrap. I am also trying to ensure that the slider's body does not always adjust to the new image but maintains a minimum size. I have ...

Rapache and R team up for dynamic leaflet design

I'm currently working on creating a webpage using Rapache and "Leaflet for R". My main goal is to integrate R into an html page using brew. However, I am facing difficulties in displaying my map within the html page without having to save it as an ext ...

What is the process for modifying information within a text document?

What I am trying to achieve is a ticker with two buttons that can increment or decrement the value by one each time they are clicked. In addition, I want this value to be synced with a number stored in a text file. For instance, if both the counter and t ...

How can I delete a CSS class from an element?

Is there a way to remove the "ui-widget-content" class from the code below? It appears in multiple places throughout my code. Here is an example snippet: <pre> <form id="clientForm"> <div id="clientData"> <div id="gbox_grid_1" class=" ...

Utilizing ng-class with Boolean values in AngularJS

On my page, I have a pair of buttons that control the visibility of elements using ng-hide and ng-show. <a ng-click="showimage=true" ng-class="{ 'activated': showimage}" class="button">Images</a> <a ng-click="showimage=false" ng-c ...

How can one use Selenium to verify the existence of an element on a webpage?

Currently, I am developing a program in Selenium with Python and facing an issue. During the test execution, there is a possibility that a button may or may not appear on the webpage based on an unknown parameter. The relevant HTML tag for this button is ...

Navigating the World of CSS Selectors - Balancing Style Control Without Excessive Class Usage

I recently stumbled upon a responsive menu that I wanted to incorporate into my webpage design. However, as I delved deeper into the implementation process, I realized that the CSS code associated with the menu was targeting all ul, li, a elements on the e ...

Struggling with transitioning from table layout to CSS, specifically encountering difficulty in aligning all elements properly

Back in the "good old days," we used to simply put everything into td cells and it would all line up perfectly. Now, with CSS, things are a bit more complicated. I'm struggling with how to achieve a specific layout. What I want is to have text on the ...

How can I create multiple divs that look alike?

I've taken on the challenge of developing our own interpretation of Conway's "Game of Life" for a project. To represent my 20x20 grid, I decided to create nested divs - the whole grid is one div, each row is a div, and every cell within that is a ...

The jspdf function is not displaying any images in the PDF file

I am new to coding and encountered an issue when trying to download images in reactjs. After clicking the download button, I only receive a blank pdf file. https://i.stack.imgur.com/0XJcC.png The function in my react code that attempts to generate the p ...

Do we really require a mime type to play videos in HTML5?

I recently stumbled upon an interesting observation while coding a video player using HTML5. Surprisingly, I found that my code runs smoothly even without specifying the type attribute (which defines the mime type) in the source element as shown below. Co ...

Modifying Class Background Image with AngularJS

I have a class called "tp-cont" that is loaded from a separate .css file. I was able to update the background image using jQuery with the following code. HTML: <li ng-click="changeTemplateBackgroundImage()"></li> Controller: $scope.changeTe ...

The appearance of Google charts' X-axis leaves something to be desired

I used the google charts API to create a chart, but I am facing an issue with the X-axis labels. When I have multiple strings on the X-axis, the labels do not look good. I suspect that the problem lies in the X column type being a string instead of DATETIM ...

Template Function Problem Detected in AngularJS Formatting

I'm struggling to incorporate my scope attributes into a template function within my custom directive. The formatting for the return section in my template is not working as expected. This is how it currently looks: angular .module(' ...

What is the best way to display text outside of the current div container?

When I include the "Y" in the code snippet below, $title1 and $title2 are positioned outside of the div and centered against the width of the page. However, without the "Y", the text shifts up and aligns with the address class instead. It's puzzling w ...

HTML code for positioning an image after resizing

Within an HTML page, I have an image that has been resized to a width of 400px using CSS. .cropbox { width: 400px; height : auto; } Additionally, there is a JavaScript function associated with the image that allows users to select a point on the image. T ...

What is the most efficient method for tallying the occurrences of the character "." in a webpage?

I am looking to analyze the content of an html page and tally up the occurrences of "." (period). Below is a snippet of code that accomplishes this task by reading the html and displaying the desired results. While considering modifying the existing code, ...

Choose an item from my unordered list to automatically set the value of a form input

Hello, I am looking for a way to make a long Unordered list always visible on my website. I want users to be able to click on one of the List Items and have that item appear as the value in my Form type=text. I believe using Jquery would be the best way ...

What is a method to raise the height when scrolling down without reducing it when scrolling up?

For my One Page project, I want a DIV element to increase in height when scrolling down, but maintain that increased height when scrolling up. Currently, I am utilizing JQuery with the code snippet below: $(function(){ $(window).scroll(function() { ...

Is it possible to eliminate the background color by double clicking on a row within an HTML table?

I am currently working on an HTML table with jQuery functionality that allows for highlighting a row when selected, and double-clicking to remove the highlight. Additionally, I would like to ensure that only one row is selected at a time. The code below s ...