CSS Display Lag

As someone who is just dipping their toes into the world of coding, I've been experimenting with code in my free time. However, I've encountered an issue with a certain code where the CSS seems to have a noticeable delay. Upon initial loading, the background turns solid pink for a moment, the font changes, and the social media icons at the bottom of the screen don't show up. Despite searching for solutions, I couldn't quite grasp the answers provided as I'm relatively new to coding, only having started about 3 weeks ago.

Below you will find both my HTML and CSS code:

/* BODY */

body {
    background-image: url('https://i.ibb.co/vPn6tqR/clouds.jpg');
  }
  
.cover-body {
    background-color: #ffd5cd;
    font-family: 'Libre Baskerville', serif;
    color: #8675a9;
    position: relative;
    text-align: center;
    height: 100%;
}

.cover-btn {
    font-size: 80%;
    font-weight: bold;
    color: #8675a9;
    letter-spacing: 1.5px;
    border-width: medium;
}

.cover-btn:hover {
    color: #2e2933;
}

.cover-header {
    font-family: 'Great Vibes', cursive;
    font-size: 6rem;
}

.cover-p {
    margin-top: 15%;
    margin-left: 20%;
    font-size: 1.5rem;
}

.pc-cover-logo {
    height: 6rem;
    width: 7rem;
    position: absolute;
    right: 63%;
    bottom:84%;
}



/* FOOTER */

a {
    color: #8675a9;
}

a:hover {
    color: #c3aed6;
}

.footer {
    font-size: 80%;
    margin-top: 6%;
    margin-bottom: 0;
}

.social-media-icons {
    word-spacing: 1.5rem;
    padding-bottom: 2rem;
    
}
<!DOCTYPE html>
<html lang="en>

   <!-- HEAD -->
   <head>
       ...
        
        <!-- Font Awesome -->
      

   </head>


   <!-- BODY -->
 
    ...


    <!-- FOOTER -->
    

If you have any suggestions or guidance, they would be greatly appreciated!

Answer №1

One way to improve performance is by applying an inline style directly like this:

<body class="custom-body" style="background-color: #f3d9a8;">

This can help speed up loading times and prevent any flickering.

Don't forget to update your CSS as well:

.custom-body {
    font-family: 'Montserrat', sans-serif;
    color: #4fa7ff;
    position: absolute;
    text-align: center;
    height: 100%;
}

https://jsfiddle.net/a63hfn29/

Answer №2

When it comes to how pages typically load, the process usually goes like this:

  • First, HTML is rendered and then css is called. This means that your image is loaded later (during the few seconds delay between html render and css). One hack I've used is to have a hidden image tag with the background source so that the image source used in the background image will be loaded during the html render, making it faster and causing no delay until css is loaded.

It's also worth noting that one reason for the delay could be the large size of the image, so reducing the image size can help decrease loading time as well.

body {
    background-image: url('https://i.ibb.co/vPn6tqR/clouds.jpg');
  }
  
.cover-body {
    background-color: #ffd5cd;
    font-family: 'Libre Baskerville', serif;
    color: #8675a9;
    position: relative;
    text-align: center;
    height: 100%;
}

.cover-btn {
    font-size: 80%;
    font-weight: bold;
    color: #8675a9;
    letter-spacing: 1.5px;
    border-width: medium;
}

.cover-btn:hover {
    color: #2e2933;
}

.cover-header {
    font-family: 'Great Vibes', cursive;
    font-size: 6rem;
}

.cover-p {
    margin-top: 15%;
    margin-left: 20%;
    font-size: 1.5rem;
}

.pc-cover-logo {
    height: 6rem;
    width: 7rem;
    position: absolute;
    right: 63%;
    bottom:84%;
}

img {
  display: none; //Added Code
}
<!DOCTYPE html>
<html lang="en">

    <!-- HEAD -->
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content ="width=device-width, initial-scale=1">
        <title>Palette Clouds</title>

        <!-- Google Fonts-->
        <link href="https://fonts.googleapis.com/css2?family=Great+Vibes&family=Libre+Baskerville&display=swap" rel="stylesheet">

        <!-- CSS Stylesheets -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ddbfb2b2a9aea9afbcad9de9f3e8f3ee">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
        <link rel="stylesheet" href="css/styles.css" />

        <!-- Bootstrap Scripts -->
        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16667966667364387c6556273827203827">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e88a87879c9b9c9a8998a8dcc6ddc6db">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
        
        <!-- Font Awesome -->
        <script src="https://kit.fontawesome.com/8346f7b19f.js" crossorigin="anonymous"></script>


    </head>


    <!-- BODY -->
 
    <body class="cover-body">

        <img alt="photo of clouds" class="pc-cover-logo" src="https://i.ibb.co/KrXCrp2/PC-Logo.png">
        <p class="cover-p">welcome to</p>
        <h1 class="cover-header">Palette Clouds</h1>
        <button type="button" class="btn btn-outline-light cover-btn">coming soon</button>

    
        <!-- FOOTER -->
        <footer class="footer">
            <div class="social-media-icons">
                <a class="fab fa-twitter fa-2x" href="https://twitter.com/paletteclouds" target="_blank"></a>
                <a class="fab fa-facebook-f fa-2x" href="https://www.facebook.com/PaletteClouds/" target="_blank"></a>
                <a class="fab fa-instagram fa-2x" href="https://www.instagram.com/paletteclouds/" target="_blank"></a>
                <a class="fas fa-envelope fa-2x" href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5b1bcbabbbbb495a5b4b9b0a1a1b0b6b9baa0b1a6fbb6bab8">[email protected]</a>"></a>
            </div>
            <p>© 2020 Palette Clouds</p>
        </footer>


<img src='https://i.ibb.co/vPn6tqR/clouds.jpg'/> //Added Code
    </body>

</html>

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

"Troubleshooting: My PHP script is not displaying CKEditor content stored in the database as HTML –

As I work on the blog section of a project, I encountered an issue with displaying HTML content saved from CKEditor in PHP. Instead of rendering the HTML tags, it shows plain text. I have attempted various solutions but haven't been able to fix the pr ...

Cells within a table are equivalent

I am attempting to ensure that all table cells match the size of the image, but for some reason, they are not aligning properly. Visit this link for reference. Here is a condensed version of the HTML code: <table> <tr> <td> ...

Script tag causing browser to send unwanted request

Recently, I received some code from a third-party supplier to implement on certain web pages. This code utilizes the jQuery plugin for jTemplates and looks something like this: <script type="text/html" id="item_template"> {#foreach $T.search.results ...

Form tag definitions are missing on the login page

Here is a snippet of code I am using: <%= form_tag :action => 'process_login'%> Username: <%= text_field "user", "fullname" %>&#x00A; Password: <%= password_field "user", "password" %>&#x00A; <%= submit_t ...

Angular and Bootstrap work hand in hand to provide a seamless user experience, especially

I have been exploring ways to easily close the modal that appears after clicking on an image. My setup involves using bootstrap in conjunction with Angular. <img id="1" data-toggle="modal" data-target="#myModal" src='assets/barrel.jpg' alt=&a ...

Keep the HTML video link out of sight in the Control Center on iOS devices

Looking for a way to conceal the video URL from appearing in the iOS Control Center, can anyone provide a JavaScript or HTML code solution? https://i.sstatic.net/NI79O.png ...

A line that shines brightest in its center, dimming slightly towards both ends

Recently, I stumbled upon some 80's retro design elements that featured glowing effects, such as this one: https://i.sstatic.net/aaJPR.png Would it be possible to recreate this glowing effect using just CSS? I'm thinking of creating a line with ...

Personalized cursor that blinks while utilizing window.history.replaceState

While navigating between sub-pages, I utilize the window.history.replaceState method to replace URLs in my web application. However, I have noticed that my custom cursor briefly blinks (replaced by cursor: default) when the current URL is replaced with a n ...

Unable to display a custom image as a check mark on a checkbox

I tried to add some custom CSS to style the images on my checkmark boxes. The goal was to display an image with a checkmark when clicked, but unfortunately, it's not working as expected during testing. For this task, I utilized CSS and HTML from a he ...

In Visual Studio Code, beautification feature splits HTML attributes onto separate lines, improving readability and code organization. Unfortunately, the print width setting does not apply

I have done extensive research and tried numerous solutions, When using Angular and formatting HTML with Prettier, it appears quite messy as it wraps each attribute to a new line, for example: <button pButton class="btn" ...

Creating a background image with linear gradients in Rails 5

Does anyone know how to implement a background image with linear gradients in CSS? Here is the code snippet I have: .main-bg-back-1{ background:linear-gradient(180deg,#22263f,rgba(33,41,94,.96)),url(../img/app/download-bg.jpg) no-repeat; backgroun ...

Problem with automatic saving of workspaces in DBeaver

Currently using DBeaver with Oracle server and encountering a recurring error related to workspace save. I have searched online for a solution, but all results seem to focus on meta data explanations. As someone new to DBeaver, I would greatly appreciate ...

Discover the unique value in Angular if it is not present in the list

I have a question about handling values in a list and displaying the "create value" component to the user when needed. How can I efficiently compare search input values with those in the list and determine if a match exists? If no match is found, the "cr ...

Modify only a designated grid-item in vue-grid-layout

We are currently undertaking a major project at our company where our clients have the ability to create and remove their personalized dashboards. These dashboards can contain various types of analyses that we offer. To facilitate this project, we are uti ...

The jQuery functions properly offline, but fails to load when connected to the

I am encountering an issue with the following script: <script type="text/javascript"> $.getJSON("http://api.twitter.com/1/statuses/user_timeline/koawatea.json?count=1&include_rts=1&callback=?", function(data) { $("#headertweet") ...

What causes the difference in behavior between absolute positioning in <button> and <div>?

I am noticing that the code below is not positioning my span to the top-left corner of the button as I expected. Can anyone explain why? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> &l ...

Develop a C# application that scans for specific HTML links and saves the extracted results into an Excel spreadsheet

One day, the professor approached me with a project idea for a website that required a significant amount of data. He requested that I copy and paste links' content into Excel, which seemed like a daunting task. As a result, I decided to create a pro ...

struggling to align menu items on both sides of a navbar

I am currently facing an issue with positioning elements in my HTML code. I have a File drop-down that I want to display on the left side, while the rest of the drop-downs should appear on the right side. It seems like my CSS files might be causing some in ...

Adjust the width of a box-shadow using percentage values in CSS

As we work on developing our tool according to the provided design, we are facing a challenge in drawing a line within a table row using box-shadow. The requirement is to have the line cover only 30% of the row width, rather than spanning across the entire ...

Relocate a table beside an image

Check out the layout of my webpage: ------------- ------------- Image here ------------- ------------- Table1 here Table2 here Table3 here My goal is to redesign it to look like this: ------------- ------------- Image here Table1 here - ...