Using CSS to repeat a background image horizontally starting from a specified position

I am currently working on styling an h2 element with a 2px background image. My goal is to have the image start right after the text in the h2 and repeat horizontally for the rest of the space within the h2. However, due to varying word lengths, I cannot simply set a static image in the HTML.

While I have managed to get the background image to repeat along the x-axis, it unfortunately goes behind the text, which is not the desired outcome.

Is there a way to either 1. make the image start repeating immediately after the text, or 2. achieve this task using a different approach?

You can view my current progress on this jsfiddle.

Here is the relevant CSS code:

h2{
    color:#253b74;
    font-size:16px;
    background-image:url('http://s8.postimg.org/ke8tx8jhd/hr_03.png');
    background-repeat:repeat-x;
    background-position:100% 50%;
}

And the HTML code:

<h2>PRODUCT IMAGE</h2>

Answer №1

What do you think of this idea:

<h2><span>PRODUCT IMAGE</span></h2>

h2 {
    color:#253b74;
    font-size:16px;
    background-image:url('http://s8.postimg.org/ke8tx8jhd/hr_03.png');
    background-repeat:repeat-x;
    background-position:100% 50%;
}
h2 span {
    background:white;
}

Check it out on Fiddle: http://jsfiddle.net/eQBgs/

Answer №2

What do you think of this option:

<p><span style="color: blue;">NEW PRODUCT DISPLAY</span></p>

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

Adjusting Classes in JavaScript with jQuery

I need to create a feature that changes the state of a button from active to inactive based on user input, using Bootstrap. Ultimately, I am working towards finding an intuitive way to validate form input so that the submit button can be pressed for PHP pr ...

BOOTSTRAP: changing the layout of panels in various sizes for mobile devices

I'm struggling with how to reorganize my panels on mobile devices. Each panel has a different size. Please refer to the attached screenshot for the page layout on large screens (col-lg): https://i.sstatic.net/xcqaT.png EDIT: The layout on large scre ...

What is the best way to choose a date and time in a custom format within my React application?

I'm currently developing the front-end of my application using React. I am looking for a way to capture the date and time in the specific format shown in this image. Any suggestions or solutions would be greatly appreciated! ...

Troubleshooting issues with the IE flexible box model functionality

Working on incorporating the flexible box model into my website has been a bit challenging. It seems to function well in webkit-based browsers like Chrome and Safari, but I'm running into issues with Mozilla, Opera, and most notably Internet Explorer. ...

Ensure that clicking on various links will result in them opening in a new pop-up window consistently

I am facing an issue with my HTML page where I have Four Links that are supposed to open in separate new windows, each displaying unique content. For instance: Link1 should open in Window 1, Link2 in Window 2, and so on... The problem I'm encounter ...

Issue with Sticky Positioning in Bootstrap Column

Looking for some help with making my form sticky while users scroll past other content on the page. I've used this method successfully before, but for some reason it's not working this time. Can anyone shed some light on why my form won't s ...

Creating an Eye-catching Presentation: Tips for Adding Text to Your CSS3 Slideshow

I am currently in the process of creating a CSS3 slideshow with text for each image. I found inspiration from this example: . However, I made some modifications to make it responsive. Here is the HTML code I have used: <div id="slideshow"> < ...

Angular2: Leveraging click events to manage CSS classes on elements

I am currently developing a web app using Angular 2. I'm facing an issue where the active element should receive an extra CSS class when clicked, but adding the ":active" CSS attribute with a custom class doesn't work as expected. The ":focus" pr ...

Master the Art of Animating Letters in the DOM by Navigating Through Any Array of Characters

I am attempting to implement a typewriter effect animation where a new message is displayed and animated as I type into an input box. Initially, I tried using a global char variable to iterate through each element of the array. However, whenever I passed ...

Generating a div element within another div element

I have been attempting to add a new div inside an existing one using append, after, etc., but so far I have not been successful. The structure of the code is as follows: <div class="row"> <div class="col-xs-12" id="element-container"> &l ...

Encountering an error message stating that the "@font-face declaration does not adhere to the fontspring bulletproof syntax" while attempting to integrate a custom font

I've been struggling to incorporate a unique font into my website, but I keep encountering the same error every time. Despite my efforts, I haven't found much guidance on how to rectify this issue. Below is the code I'm using: @font-face ...

Struggling to perfectly center the NavBar within the wrap container

After working on my navbar and utilizing this site for guidance, I was able to center it using text align. However, there is an odd indent in the navbar that I can't seem to figure out. This indentation throws off the alignment when centered, giving i ...

Incorporating an additional table dynamically based on height considerations – can you provide visuals as guidance?

The visual representation of my question far surpasses my verbal explanation. My intention is to insert a new table once the height of the previous table exceeds a specific HEIGHT limit, not a certain number of rows. This project does not involve creat ...

using JavaScript to send numerous text box values to various views

I have a dilemma with passing values between two views. In View1, there are text boxes for entering basic information. After the customer enters this data and clicks on 'add more details', I want to transfer these details to the text boxes in Vie ...

Avian-themed masking feature for jCarousel

Currently, I have a series of images in constant motion using jCarousel. Only one image is visible fully at any given time, and I am looking to create a "feathering" effect on the edges of the carousel so that the images smoothly fade in and out as they co ...

Unable to transfer HTML code into the TinyMCE editor

I've successfully stored raw HTML content in my database, and now I want to display it in my TinyMCE editor for users to easily edit and submit. Below is the form: <textarea id="postfullOnEditPop" type="text" class="validate" placeholder="Enter f ...

Currently, I am experiencing difficulties with two specific aspects of the website I am working on - the hamburger menu and the slideshow feature

I'm having trouble with the menu on my website. It's not functioning as expected - the dropdown feature isn't working, and two items are not staying in the correct position under the parent ul despite attempts to position them using CSS. Add ...

How can I automatically add and remove the active class to the navigation on a single page layout?

Is there a way to automatically add an active class to the navbar links when a specific navigation section appears as you scroll down a one-page layout? Similarly, can the active class continue to move to the corresponding section in the nav links as you s ...

Using jQuery functions on inputs within a Bootstrap Modal

I've encountered an issue with my jQuery functions that validate input fields based on a regex pattern. Everything works smoothly when the form is displayed on a regular page, but as soon as I try to implement it within a Bootstrap Modal, the validati ...

Align an element at the center of both the x and y axes using CSS

Imagine you have a div in an html document with absolute positioning, like this: <div style="position:absolute">Hello!</div> Now, if you want to set a specific X and Y position for the div (potentially using JQuery), it's pretty straight ...