Tips for incorporating unique images into each individual flex box

I am new to the world of coding, having just embarked on this journey less than a week ago. Following a tutorial by a developer on YouTube, I tried to add my own twist to the project in order to differentiate it from the original. However, I've hit a roadblock.

My goal was to assign a unique background image to each flex box within the "Services" section. Despite my efforts to create a separate div for the image, similar to the .icon and the <p>, I encountered issues with the positioning and visibility of the images within the boxes.

Upon inspecting the code, I realized that all the boxes shared the same background image due to the main container setting the background for all elements.

I'm struggling to find a solution that allows me to have distinct background images for each box.

Your assistance would be greatly appreciated!

/* Services Section */

#Services {
  background-color: #f4f6ff;
}

#Services .services {
  flex-direction: column;
  text-align: center;
  max-width: 1500px;
  margin: 0 auto;
  padding: 50px 0;
  background-color: #f4f6ff;
}

.header-title {
  font-size: 3rem;
  font-weight: lighter;
  color: black;
  margin-bottom: 15px;
  text-transform: uppercase;
  letter-spacing: 1rem;
  text-align: center;
}

#Services .section-header p {
  font-size: 1rem;
  font-weight: lighter;
  margin-top: 2px;
  margin-bottom: 20px;
  font-family: sans-serif;
}

#Services .services-cards {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

#Services .services-content {
  flex-basis: 90%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex-direction: column;
  padding: 25px;
  border-radius: 10px;
  background-image: url(./img/customer-support.jpg);
  background-size: cover;
  margin: 10px 5%;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

#Services .services-content::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 100%;
  background-image: linear-gradient(60deg, #0a2647 0%, #584a2a 100%);
  opacity: 80%;
  z-index: -1;
}

#Services .services-cards .icon {
  height: 90px;
  width: 50px;
  margin-bottom: 0;
}

`enter code here` #Services .services-content h2 {
  font-size: 1.2rem;
  color: gold;
  text-transform: uppercase;
}
<! -- Services Section -->
<section id="Services">
  <div class="services container">
    <div class="section-header">
      <h1 class="header-title">Services</h1>
      <p>I have worked with successful businesses over the years, I have helped companies activate their audience through social media marketing, facilitated the on-boarding process for their new customers.<br><br>I also managed projects for 20 plus brand
        ambassadors and led company team members so they can produce quality and engaging content delivered to our social media channels efficiently.</p>
    </div>
    <div class="services-cards">
      <div class="services-content">
        <div class="icon"><img src="" /></div>
        <h2>Customer Support</h2>
        <p>I have worked as a BPO Rep for 3 years. I have the fundamental knowledge in handling customer calls, emails and provide the adequate support, so that you can focus on the important aspect of your business.</p>
      </div>
    </div>
    <div class="services-cards">
      <div class="services-content">
        <div class="icon"><img src="" /></div>
        <h2>Administrative Assistant</h2>
        <p>Data entry, Research, Invoicing, Calendar Management, CRM maintenance, Appointment Setting, Recruitment, and more. I will take charge of the routine back-office tasks and you can keep focus on what matters for your brand.</p>
      </div>
    </div>
    <div class="services-cards">
      <div class="services-content">
        <div class="icon"><img src="" /></div>
        <h2>Porject Management</h2>
        <p>Launching a new product? Do you need help in Content creation and Scheduling? Or are you looking for a point-person to lead your marketing team and start pulling-in audience for your brand? I have 5 years of Social Media management experience,
          supported brands with different products catering to different demographics. I can develop a distinct strategy that will work for you. </p>
      </div>
    </div>
    <div class="services-cards">
      <div class="services-content">
        <div class="icon"><img src="" /></div>
        <h2>Front-End Web Development</h2>
        <p>I can hand-code HTML, CSS with some knowledge in CSS Flexbox, Bootstrap, and Javascript.</p>
      </div>
    </div>
  </div>
</section>

Answer №1

When discussing the topic of

Cascading Style Sheets (CSS)

#Services .services-content {
...
background-image: url(./img/customer-support.jpg); 
...
}
#Services .services-content::after {
...
background-image: linear-gradient(60deg, #0a2647 0%, #584a2a 100%);
...
}

and this specific HTML structure

<div class="services-content">
...
</div>

One solution is to introduce a new class that will modify the background-image property for each instance of .services-content, like so:

CSS

#Services .first-content {
...
background-image: url(different); 
...
}
#Services .first-content::after {
...
background-image: linear-gradient(different);
...
}
#Services .second-content {
...
background-image: url(different); 
...
}
#Services .second-content::after {
...
background-image: linear-gradient(different);
...
}

And then for each corresponding HTML element

<div class="services-content first-content">
...
</div>
<div class="services-content second-content">
...
</div>

This approach allows you to selectively update the background-image while keeping the rest of the CSS intact.

Answer №2

If you are looking to apply a unique gradient for each div.services-content, consider adding the following CSS selectors:

<style>

        #Services {
        background-color: #f4f6ff;
    }
    #Services .services {
        flex-direction: column;
        text-align: center;
        max-width: 1500px;
        margin: 0 auto;


        padding: 50px 0;
        background-color: #f4f6ff;
    }

.header-title {
    font-size: 3rem;
    font-weight: lighter;
    color: black;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1rem;
    text-align: center;
}

#Services .section-header p {
    font-size: 1rem;
    font-weight: lighter;
    margin-top: 2px;
    margin-bottom: 20px;
    font-family: sans-serif;
}
#Services .services-cards {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}
#Services .services-content {
    flex-basis: 90%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    flex-direction: column;
    padding: 25px;
    border-radius: 10px;
    background-image: url(./img/customer-support.jpg);
    background-size: cover;
    margin: 10px 5%;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

#Services .services-content::after {
    content:'';
    position: absolute;
    left: 0;
    top:0;
    height: 100%;
    width: 100%;
    /* background-image: linear-gradient(60deg, #0a2647 0%, #584a2a 100%); */
    opacity: 80%;
    z-index: -1;
}


#Services > div > div:nth-child(2) > div{
background-image: linear-gradient(60deg, #0a2647 0%, #584a2a 100%);
}
#Services > div > div:nth-child(3) > div{
background-image: linear-gradient(60deg, #0a2647 0%, red 100%);
}
#Services > div > div:nth-child(4) > div{
background-image: linear-gradient(60deg, #0a2647 0%, yellow 100%);
}
#Services > div > div:nth-child(5) > div{
background-image: linear-gradient(60deg, #0a2647 0%, blue 100%);
}


#Services .services-cards .icon {
    height: 90px;
    width: 50px;
    margin-bottom: 0;
}
#Services .services-content h2 {
    font-size: 1.2rem;
    color: gold;
    text-transform: uppercase;
    }
</style>

<section id="Services">
    <div class="services container">

        <div class="section-header">
            <h1 class="header-title">Services</h1>
            <p>I have worked with successful businesses over the years, I have helped companies activate their audience through social media marketing, facilitated the on-boarding process for their new customers.<br><br>I also managed projects for 20 plus brand ambassadors and led company team members so they can produce quality and engaging content delivered to our social media channels efficiently.</p>
        </div>
        <div class="services-cards">
            <div class="services-content">
                <div class="icon"><img src=""/></div>
                <h2>Customer Support</h2>
                <p>I have worked as a BPO Rep for 3 years. I have the fundamental knowledge in handling customer calls, emails and provide the adequate support, so that you can focus on the important aspect of your business.</p>
                </div>
            </div>
        <div class="services-cards">
            <div class="services-content">
                <div class="icon"><img src=""/></div>
                <h2>Administrative Assistant</h2>
                <p>Data entry, Research, Invoicing, Calendar Management, CRM maintenance, Appointment Setting, Recruitment, and more. I will take charge of the routine back-office tasks and you can keep focus on what matters for your brand.</p>
            </div>
        </div>
        <div class="services-cards">
            <div class="services-content">
                <div class="icon"><img src=""/></div>
                <h2>Porject Management</h2>
                <p>Launching a new product? Do you need help in Content creation and Scheduling? Or are you looking for a point-person to lead your marketing team and start pulling-in audience for your brand? I have 5 years of Social Media management experience, supported brands with different products catering to different demographics. I can develop a distinct strategy that will work for you. </p>
            </div>
        </div>
        <div class="services-cards">
            <div class="services-content">
                <div class="icon"><img src=""/></div>
                <h2>Front-End Web Development</h2>
                <p>I can hand-code HTML, CSS with some knowledge in CSS Flexbox, Bootstrap, and Javascript.</p>
            </div>
        </div>
    </div>
</section>

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

Using inline CSS to apply conditional styles to a component in React is a great way to customize the

I'm currently working on customizing the styles of some buttons depending on their 'active' status and whether the user is hovering over them. So far, it's partially working but I'm encountering behavior that I can't fully com ...

Customize Cell Styling with Bootstrap Full Calendar CSS

I am attempting to implement a Bootstrap calendar feature where cells are colored green if the timestamp is greater than today's date. This can be achieved by: $checkTime > $today cell.css = green background I came across this code snippet on St ...

Utilizing numerous 'select' HTML elements with Vue.js and Materializecss

I've been working on creating an HTML multiple select form element with Vue.js and encountered an interesting issue. Everything was functioning perfectly following the guidance provided in this resource. However, when I decided to incorporate the Mate ...

I need to position the CSS vertical scrollbar on the right side of the page

I can't figure out how to move the vertical scrollbar to sit on the right side of my site's work page. Any help would be greatly appreciated. Below is the provided HTML code: <div class="heading"> <h1>PRINT</h1> &l ...

There seems to be a glitch in my programming that is preventing it

Can someone please help me troubleshoot this code? I'm unable to figure out what's going wrong. The concept is to take user input, assign it to a variable, and then display a string. However, nothing appears on the screen after entering a name. ...

Find all the child elements within a specific class using CSS

Looking for a method to effortlessly apply styles to all elements within a specific class without repeating code like this: .element-wrapper .coin-box{ margin: 10px; float: left; } .element-wrapper .platform{ margin: 10px; float: left; } .eleme ...

What is the best way to divide data using [/ -]?

I am trying to split a string that shows a date. The date is shown in the format dd/mm/yyyy or dd-mm-yyyy. This is my code (the current string is formatted as mm/dd/yyyy): <input type="data" id="dat"> ..... var dataString=$('#dat').val(); ...

Designing a slider to display a collection of images

I am currently working on a slider project using HTML, javascript, and CSS. I'm facing an issue where only the first two images (li) are being displayed and it's not transitioning to the other (li) elements. Below is the HTML code snippet: <se ...

Clicking on a React component will result in highlighting

What's the best way to display the selected item after a user clicks on it? <Box py={2}> <Grid container width="330px"> <Grid container direction="column" item xs align="left"> ...

Issues with Toggling Visibility in HTML, CSS, and Javascript

Currently, I am working on a website and following a tutorial called "Creating Slideshow using HTML, CSS, and Javascript" by W3Schools. In the project, I want to hide the thumbnail images located at the bottom and the navigation arrows initially and have t ...

Tips for expanding an input to fit the width of a div without altering the dimensions of a preceding span element

Let me explain, I have a form that includes a span and an input: <form onSubmit={e => handleSubmit(e)}> <Box className='form_box'> <span> <a href="/cd ...

Show the modal content in Bootstrap on mobile and tablet screens

I have exhaustively searched the web for a solution to my issue, but unfortunately, I have come up empty-handed. I am hoping that you can offer some guidance in this matter. I am currently utilizing modals to showcase details on my website. However, when ...

What causes the alignment of text to be overridden by the presence of a floating element?

https://jsfiddle.net/u0Ltgh3e/68/ .text { width: 50%; text-align: justify; } I am currently developing a custom formatting tool for a specific purpose and I am attempting to create a two-column layout similar to the one demonstrated in this Jsfiddle l ...

Pagination CSS may fail to function properly in Chrome after an AJAX call is returned

Having an issue with CSS not getting applied correctly after making an AJAX call with pagination. The problem seems to be specific to Chrome, as it works fine in Firefox. When inspecting the element, the CSS is present but not being applied properly until ...

What could be causing the Bootstrap icon to remain the same size without changing?

Take a look at this piece of code: <div class = "banner-image w-100 vh-100 d-flex justify-content-center align-items- center"> <div class = "content text-center"> <i class="bi-chevron-compact-down bi-7x"&g ...

Tips on configuring a hidden input field to validate a form

I am currently attempting to create a blind input field using PHP that will validate if the input field is empty. If it's not empty, the message set up to be sent will not send. However, I have encountered several issues with the placement and wording ...

Incorporate a JSON file into the Webpack output separately from the bundle.js file

Is there a way for my webpack application to read a JSON file at runtime without including it in the bundle.js after packaging? I want the JSON file to be available in the package folder but not bundled with the rest of the code. How can I achieve this? ...

Establish a variable in XSL to define the tabIndex

My XSL code has been designed to read an XML file and generate input elements of type text for each child node. The XML file structure is as follows: For node c, two input boxes are created in the format: Label(com 1) :input box--------------------- Label ...

What could be the reason my div is not being hidden in jQuery?

Creating a quiz layout for school is my current project, and I'm just getting started. My goal is to have the questions disappear once the 'next question' button is clicked. The issue arises after the second question because instead of the ...

What is the best way to position my image in the center within a blank canvas?

What is the best way to center an image in a white space? I am working with HTML, PHP, and CSS, but I am unsure of how to achieve this. So far, I have tried aligning the image within text on w3schools.com, but my other attempts like: #image { margin- ...