Is there a way to set the background of a HTML5 page as an image with a clickable link?

Lately, I've been working on a webpage dedicated to educating people about Mars. I wanted to spice things up by using an image as the background for my HTML5 page instead of the usual plain white color. However, just inserting a .jpg link didn't quite cut it for me. Here's the code snippet I experimented with:

<!DOCTYPE HTML>
    <html>
        <head>
            <title>My Webpage</title>
            <style>
                body {
                background: url(https://phys.org/news/2020-05-astrobiologists-mars-rover-life-detecting-equipment.html);
                }
            </style>
        </head>
        <body>
            Insert your text here...
        </body>
   </html>

I must admit, I'm not the most skilled programmer, as evident from this attempt. Any guidance or tips (no matter how small) would be greatly appreciated. Thank you for taking the time to read this and have a fantastic day ahead!

--

isharief

Answer №1

Instead of using the HTML link in the src attribute, incorporate the jpg file link directly,

<style>
                body {
                    background: url(https://scx1.b-cdn.net/csz/news/800/2020/astrobiologi.jpg);
                    background-repeat: no-repeat;
                    background-size: cover;
                    background-position: center;
                    height: 100vh;
                    width: 100vw;
                    overflow: hidden
                }
            </style>

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 arrange JSON Objects vertically on a webpage using tables, flexboxes, divs, and Javascript?

Within my JSON data, I have multiple products defined. My goal is to loop through this JSON and display these products side by side on a web page for easy comparison. Initially, I envision structuring them in columns and then rows: https://i.sstatic.net/K ...

Choose items in a particular order based on the class name of their category

How can I dynamically select and manipulate groups of elements? My intention is to select and modify the msgpvtstyleme elements, then select the msgpvtstyle elements separately and work with them as well. The ultimate goal is to apply classes to these grou ...

Tips for adjusting the height of the NextJS Image tag based on the width of the screen

I'm leveraging next/image to display my image in the following way: <Image src={imageLink} width="1920" height="512" alt="Hero Image" /> Everything works well for screen widths larger than 750px. Is there ...

What makes the transparent border colors on <tr> appear too dark?

For instance, take a look at this code: http://jsfiddle.net/WaJy7/ In my attempt to apply a semi-transparent border to every <tr> element, I've encountered an issue where the color of the border appears darker than intended for all rows except ...

Replacing hyperlinks based on the user agent of a mobile device can be done using a few

I am struggling with the following HTML code that checks for a useragent from a Blackberry device. I want to customize the download URL based on the specific device, such as redirecting a user with a 9800 device to a designated download link. Can anyone ...

Express backend not receiving form data from post request

I recently created a form to submit a file to an express backend, but I'm encountering an issue where the data is not being received on the backend when the form is submitted. Upon using console.log, I noticed that req.body returns {}, and sampleFile ...

Is there a way to automatically load data whenever a specific inner div on an HTML page is modified?

On my website, I have created a main page with three divs: header, footer, and main. The header div contains buttons that change the content of the main div when clicked. Rather than reloading the entire page, only the main div is updated with a new HTML p ...

Display a list of personalized post types and emphasize the item that is currently being viewed

I've created a unique type of post called 'product'. Every product page has a sidebar listing all products, with the current product displayed in bold text. For instance, when viewing product 3, it should appear like this: Sidebar Pr ...

Adding a gradient overlay to an image that has a see-through background

I am trying to achieve a unique effect where a gradient appears on the text instead of the background of an image. An example I created can be found here: https://codepen.io/BenSagiStuff/pen/BaYKbNj body{ background: black; } img{ padding: 30px; ...

Continuously spinning loading icon appears when submission button is triggered

We are currently experiencing some issues with our mobile forms. Our users utilize a mobile form to submit contact requests, but the problem arises when they hit 'submit' - the loading icon continues to spin even after the form has been successf ...

The changes made in the CSS file are not reflected in the browser

Recently, I encountered a strange issue with my new server where the CSS changes were not reflecting in the browser. Despite trying to refresh and clear the cache, the problem persisted. To investigate further, I used FileZilla to check if the updated CSS ...

Why is it that styling <div> and <img> with a URL doesn't seem to work, even when applying the same styles?

In the example I have, I apply the same styling to an image and a div. Interestingly, the styling on the div makes the image look significantly better, while on the image itself it appears distorted. What could be causing this discrepancy? Both elements a ...

Is there a way to dynamically add <td> based on the quantity of values in a JSON object?

I have developed a program that retrieves values from JSON and I aim to display these values in a table. Currently, only the last array value is being displayed in the table even though all values are available in the console. The objective now is to dynam ...

What is the best way to incorporate quotes within inline CSS code?

Can anyone help me with inserting the following CSS into HTML? Here is the CSS snippet that needs to be converted to HTML: .group .circular-progress::before { ... content: "10%"; ... } This is what I have attempted so far: <div class="group"&g ...

What is the best method for eliminating the initial character in every line of a textarea?

The desired output should display as LUNG,KIDNEY,SKELETON>J169>U and E, CREATININE:no instead of >LUNG,KIDNEY,SKELETON>J169>U and E, CREATININE:no. Is there a way to achieve this using JavaScript? Specifically, the ">" character at the be ...

AngularJS fails to fetch data from API queries

Currently facing a challenge with retrieving API data in my AngularJS project. The code below successfully fetches the data and logs it on the console as an array, but I am unable to access and utilize it in the front-end. Please note that the placeholder ...

Expanding the flexbox container to accommodate additional divs when they are added

I'm encountering an issue with a div not extending properly, causing two other divs to overlap. I've managed to position the divs correctly, but now I need the "100% all beef weenies" text to appear below the items. Any suggestions on how to achi ...

Show or hide the right element when clicked using ng-show in AngularJS

My goal is to toggle elements based on which one is clicked, not all at once. For instance, if I have 3 form elements and 3 buttons, when I click on button 1, I only want to toggle the corresponding form element. Here is my current code snippet: In Angu ...

Leveraging jQuery, Ajax, and PHP for generating and organizing HTML blocks - requiring sound logic

I am in the process of developing a website that compares different products. I have implemented code that retrieves and scrapes data for comparison when a user performs a search. Right now, I am using an ajax request for each company (currently 6 compani ...

Include a picture and a division element within the dropdown element

I've encountered a few challenges while trying to personalize a profile dropdown component using Semantic and React. First, I am facing an issue where my application crashes when I attempt to place a div inside the Dropdown.Menu with the error message ...