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

Steps for resetting the HTML5 meter element

I have implemented the meter element to rate between 0 and 5, but I want to display a specific image for each value instead of the default meter style: <meter min="0" max="5" value="5"> <img width="80" height="20" alt="5 out of 5 stars" src=" ...

What is the inner workings of CSS?

I'm curious about the inner workings of CSS. Does the HTML get interpreted before CSS, or vice versa? Or does it all apply as soon as the browser has constructed the DOM? I would appreciate a detailed explanation on this topic. ...

How can one retrieve the ID value within a function using jQuery?

I am trying to implement an upload picture function along with cropper js function. However, I am facing an issue with displaying the file name even though I have declared the variable and set the input value. But when I attempt to pass and display the nam ...

What are the steps to modify data within the root component?

I am currently working on a Vue project with vue-cli and routes. In my App.vue file, the template structure is as follows: <template> <div id="app"> {{Main}} <router-view></router-view> </div> </template&g ...

Issues with CSS selectors in Internet Explorer causing problems with Selenium Webdriver C#

When automating a website with Selenium C#, I encountered a NoSuchElementException when trying to click an element using a CSS selector. However, the issue was resolved when using xpath instead. Can someone shed light on why this discrepancy between CSS an ...

Client request: receive a daily update detailing the differences between two databases

Today, a customer requested that I provide daily reports on the changes between two tables in our database. I am currently contemplating the most efficient and intelligent way to fulfill this request. Should I create a SQL procedure? Or perhaps an HTML p ...

Aligning columns to the right in Bootstrap, featuring an unordered list without any text wrapping

I am trying to prevent the lines from overflowing onto the next line. The details should all be on the same line. I have attempted a solution, but it's not working as expected. https://i.sstatic.net/MYgv5.png <div class="container"> <div cla ...

Elements featured in the header: logo, tagline, graphics, and more

I'm interested in designing a schema with the following elements: I'm contemplating whether it would be beneficial to have a separate container for the logo and slogan. Additionally, I am considering if it is advantageous to create a container f ...

Scrolling to an id within dynamically loaded content using jQuery after an ajax request

After loading content via ajax, I am unable to scroll to the item, as the page remains at the top. Strangely, when I refresh the page dynamically with content caching enabled, the page scrolls to the desired target. var startPageLoader = function( pid, si ...

Resize the tab header in primefaces to fit your needs

Is there a way to change the height of the tabView's header specifically in primefaces? Take for instance the tabs with headers like "God Father I", "God Father II" on this link, I only want to adjust the height of the header and not the entire tab. ...

Resolution of JSP/HTML Pages

Looking for guidance on adjusting the height and width of JSP/HTML pages to accommodate various monitor resolutions. How can I ensure that my page looks good and fits properly on all types of monitors? Any tips on setting height and width in a JSP would ...

Images and CSS are functioning properly when viewed locally, but are not displaying as expected on GitHub pages

There seems to be some issues with transferring my website from a custom domain on Hover. When I try to import it to anthematics.github.io, only the HTML loads while images and CSS are missing. <link rel="stylesheet" href="theme.css" type="text/css"> ...

Is it possible to transmit both HTML and PHP files using express.js?

Is it possible to serve HTML files for one page and PHP files for another with an express.js app? Here's a theoretical example: var express = require('express.js') var app = express() app.get('/php', function (req, res) { res.se ...

Customize the appearance of the submit button by using CSS to replace

Currently, I am working on a CSS userstyle project. The issue that I am facing is the inability to make modifications to images in buttons coded within the html of a web page: <button type="submit" class="btn btn-default"><img alt="Ico-plus" src= ...

Are checkboxes embedded within labels?

There are two common ways that people code checkboxes on the web, and I'm wondering which one is considered correct. <input id="a" type="checkbox"/><label for="a">checkbox</label> <label for="b"><input id="b" type="checkbo ...

Exploring shader file content within three.js with the help of jQuery

I am trying to retrieve the content of a string that I have imported using HTML from within another script. To include the text file in question in the html file: <script src="shaders/fragmentshader.fs" id=fragmentshader></script> After impo ...

Customize the text color of select list options in Angular 5

Is there a way to style the foreground colors of select list options differently in this dropdown code? <select id="tier" class="form-control" [(ngModel)]="tierId"> <option *ngFor="let m of tierList" value="{{m.tier}}" > {{m.option ...

Adjust the size of h1 headings to be smaller than 768px within the

My goal is to have an h1 header within a row, with font awesome mark quotes displayed on the left and right. I am attempting to resize it once the screen width goes below 768px. Here's what I have so far: @media screen and (max-width: 768px) { h1 ...

Run a Javascript function two seconds after initiating

My goal is to implement a delay in JavaScript using either setInterval or setTimeout, but I am facing an issue where the primary element is getting removed. Code that works fine without Javascript delay: const selectAllWithAttributeAdStatus = document. ...

Adjusting the height in AngularJS based on the number of items in a table

I've developed a straightforward AngularJS application with multiple tables on one page. In order to add scrolling functionality, I initially used a basic CSS code snippet like: tbody { overflow: auto; } I also experimented with the https://github. ...