Repeating background images in CSS

Hey there! I'm having a little trouble with my background image in HTML. It's showing up multiple times in a row and despite searching online, I can't seem to find the right solution. Here is the code snippet from my file:

<!DOCTYPE html>
<html>
    <head>
        <title>'Cyclone development'</title>
        <link href="styles/main.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
<hl>Cyclone development</hl>   <img src="cyclone.jpeg" alt="Italian Trulli">
<p>Who are we ?<br></p>
   <ans> We are a development team dedicated towards coding we make coding videos on youtube 
    for our users to learn and develop.
</ans>
    </body>
</html>

Additionally, here is a snippet from my main CSS file:

hl{
    color: rgb(0, 0, 0);
    padding: 10px 10px;
font-size: 80px;
background: url(macoswall.jpeg);
background-size: 120px 120px;
}

body{
    background: #999;
    font-family: arial;
}

p{
    color:rgb(255, 0, 0);
    font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
    font-style: italic, bold;
    background-color: rgb(0, 60, 255);
    background-size: 300px 100px;
}
ans{
    color:rgb(255, 0, 0);
    font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
    font-style: italic;
}

My issue is that the background image for hl is repeating multiple times causing it to display like this. Can anyone guide me on how to fix this? Thanks!

Answer №1

Here is an example:

body {
  background-image: url("image.jpg");
  background-repeat: no-repeat;
}

For more information, you can refer to the MDN documentation. Additionally, you have the option to use a shorthand notation.

Answer №2

To resolve this issue, consider utilizing the background-repeat property.

background-repeat: no-repeat;

Experiment with using 'cover' or 'contain' for your background-size property as well.

Consider simplifying color codes by using hex values:

rgb(0,0,0) => #000
rgb(255,0,0) => #f00
rgb(255,255,255) => #fff

Furthermore, when setting properties like padding and margin, you can specify a single value if all dimensions are uniform.

padding: 10px 10px => padding: 10px

Additionally, establish a base font size and utilize relative units for element fonts. This facilitates making global font adjustments, particularly for accessibility features.

:root { font-size: 10px; }
h1 { font-size: 8rem; //== 80px}

Answer №3

When aiming for a specific look with your h1 heading, consider adding some background:

h1{
    color: rgb(0, 0, 0);
    padding: 10px 10px;
    font-size: 80px;
    background: url(macoswall.jpeg);
    background-size: 120px 120px;
    background-repeat: no-repeat;
}

It is recommended to use the h1 tag instead of hl for better semantic structure.

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

Are desktop values taking precedence over the mobile media query?

Currently, I am facing an issue with aligning icons (images) under each title on a page that lists various classes. The icon needs to be centered below the title on both desktop and mobile versions of the site. However, I have encountered a problem where u ...

Hiding overflow when navigating back a page in Safari

I need help finding a solution to this issue. On my website, the results page works perfectly fine until I navigate to a product's details page and then return to the results using the "page before" button. At that point, the overflow becomes hidden, ...

Iterating over a table and selecting a specific button on the rows that meet a specific condition

I'm having a bit of trouble and would really appreciate your help. I'm attempting to write a script that will scan through this table and delete any row that contains the word "active". The script needs to check every row in the table. The code ...

I am looking for a way to display multiple images when the user clicks a button. It needs to be done

After successfully implementing a draggable single circle image when clicking a button, I am now looking to add multiple circle images each time the button is clicked. I'm considering using the append function with the canvas tag for this purpose. Ca ...

Ways to implement schema.org and JSON-LD for data labeling on a homepage of a website

After reading extensively on utilizing schema.org to mark structured data, I have a couple of questions. Firstly, is it advisable to use json-ld considering that it's relatively new and not fully supported yet? Secondly, how can I implement schema.org ...

Creating a function that uses setInterval to continuously update the input with a specific value

I am looking to use the setInterval function to continuously update the value of #test1. Additionally, I want the value of #test1 to be cleared and reset to 1 second after the user clicks a button. Example output can be found here: http://jsfiddle.net/eK ...

Show an image based on a query parameter

Currently, I am developing a PHP project and I am facing an issue with loading an image from a query string. Here is the code snippet I am using: <img src="load_image.php?name=Profile_Photo_Small" /> Is there anyone who can help me out with this pro ...

Is it possible to pass a function as an argument to another function in jQuery?

My function accepts a JSON object as a parameter containing User id, password, success callback, and error callback. The goal is to authenticate the user using an AJAX service. If the service response is successful, I want to call the success callback fun ...

Customize the background color of a particular select element within an array of dynamically created select elements

I've been experimenting with jQuery to dynamically adjust the background color of a select element based on the chosen option. The select elements are being generated using the following code: while ($qrow = $qquery->fetch(PDO::FETCH_ASSOC)) { ...

Navigate to the editing page with Thymeleaf in the spring framework, where the model attribute is passed

My goal is to redirect the request to the edit page if the server response status is failed. The updated code below provides more clarity with changed variable names and IDs for security reasons. Controller: @Controller @RequestMapping("abc") public clas ...

Using jQuery to create a dynamic fullscreen background image that responds to mouse movement

I am currently working on creating a dynamic full screen background that responds to the movement of the mouse. The idea is that as you move the mouse around, the background image will shift accordingly. For instance, if you were to move the mouse to the ...

What is the correct way to add "itemCondition" and "logo" schema tags to schema.org product snippets?

I'm in the process of enhancing my product page with schema.org snippets. My client has specifically requested the inclusion of certain schema.org tags on the product's individual page. 1) itemCondition 2) logo (displaying only the brand image ...

Trick for adjusting padding on top and bottom for responsive blocks of varying widths

Hello there, I've been working on a project where I need to create a responsive grid of cards, like news articles, that maintain their proportions even when the browser's width changes. To achieve this, I decided to use an aspect-ratio hack by s ...

Update Personal Information with PHP and MySQL

i have two files named edit.php and update.php. The content of edit.php is as follows: <?php session_start(); $_SESSION['id'] = '9'; $id = $_SESSION["id"]; $username = $_POST["username"]; $fname = $_POST["fname"]; $password = $_POST ...

Troubleshooting problem with AngularJS ng-repeat

Seeking assistance with an angularjs issue as a newcomer to the platform. Building a photo gallery where the initial page displays thumbnail photos from twitter and instagram using ng-repeat loop. Hovering over an image fades it out, revealing a button f ...

Center an image vertically in an AdminLte content-wrapper division

I am currently utilizing an AdminLte template as the framework for my design. In the designated area where I need to insert the main content, it is structured in the following manner: <div class="content-wrapper"> <se ...

What is the best way to apply styling to an image that is contained within the document.write function?

I'm looking to customize the design of this cat image, but I'm struggling to locate where to incorporate the div class. It's likely a basic step, but as a beginner in JavaScript, I'm hoping that someone can assist me. document.write(&ap ...

Personalize the hover effect and underline style of links in material-ui

I am currently delving into the world of material-ui custom styles and came across this helpful resource. However, I find myself a bit lost in how to properly override the classes using withStyles. <Breadcrumbs aria-label="breadcrumb" separator=" ...

How can you master the art of PHP templating like a pro?

Years ago, I started a small PHP website that has since grown into quite a mess. Despite having a separate template for the final HTML output, I still find myself handling a lot of HTML within the 'business logic' part of the code. My main issue ...

The appearance of CSS can vary depending on the screen resolutions in which it is

I am encountering an issue with my HTML component that utilizes a booking engine. The parent width of the component is set, and the children elements inherit this width. There are three input fields and a search button within the component. The problem ari ...