Designing a patterned rectangle filled with stylish text

I am relatively new to the world of HTML and CSS, and I am encountering a specific challenge with CSS.

My goal is to design a section that looks like this:

---Image---

--Text--

---Image---

--Text--

---Image---

--Text--

---Image---

--Text--

The main issue I'm facing is that when I try to set a background color for the rectangle containing the text, it ends up encompassing all the content below it.

.lower-part {
  margin-top: 15%;
}
.lower-part .row .image img {
  height: 80%;
  width: 80%;
}
.lower-part .row .textbox {
  background-color: red;
}
<div class="lower-part">
  <div class="row">
    <div class="image"><img src="images/BadmintonPicture.svg" alt="Badminton Picture"></div>
    <div class="textbox1">
      Sports.
      <p>For me, nothing is better than regular exercise. It keeps me energetic throughout the day.</p>
      <div class="row">
        <div class="image"><img src="images/CookingPicture.svg" alt="Cooking Picture"></div>
        <div class="textbox">
          Cooking.
          <p>I LOVE Food. I try to experiment with new recipes whenever I can. The Food Lab by Kenji Lopéz-Alt helps me be a better cook.</p>
          <div class="row">
            <div class="image"><img src="images/ReadingPicture.svg" alt="Reading Picture"></div>
            <div class="textbox">
              Reading.
              <p> I love self-development books because they help me grow as a person.
                <span>Favorites:</span>
                <br>Slight Edge, Atomic Habits, How to Win Friends & Influence People .
              </p>
              <div class="row">
                <div class="image"><img src="images/GuitarPicture.svg" alt="Guitar Picture"></div>
                <div class="textbox">
                  Music.
                  <p>I grew up playing the violin but the guitar seemed way cooler. So I stuck with that for the most part. Also, I like to sing every few minutes.</p>
                </div>
              </div>
            </div>

Sass

.lower-part {
  margin-top: 15%;
  .row {
    .image {
      img {
        height: 80%;
        width: 80%;
      }
    }
    .textbox {
      background-color: red;
    }
  }
}

Answer №1

Make sure to always close your <div> tags. Properly indenting and using new lines for new tags can help you keep track of open tags more easily.

<div class="lower-part">
    <div class="row">
        <div class="image">
            <img src="images/BadmintonPicture.svg" alt="Badminton Picture">
        </div>
        <div class="textbox1">
            Sports.
            <p>
                Enjoying regular exercise is essential for me.
                It keeps my energy levels up all day long.
            </p>
        </div>
    </div>
</div>

etc.

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

Radio button - arranging the background image and text in alignment

I'm struggling to align my custom radio buttons alongside text. Here is an example image: https://i.sstatic.net/2g5w8.jpg Despite using CSS for styling, I am unable to properly align the radio buttons. Below is a snippet of my HTML: label.item { ...

I am having trouble generating a TikTok page link due to the presence of an @ symbol, although all other links are functioning correctly. Can anyone provide a solution to this issue?

I am currently developing a website using primarily HTML within a Blazor application on Visual Studio. I have encountered an issue with the code where the first two buttons function correctly, but there is an error regarding the @ symbol in the TikTok butt ...

CSS menu LI with horizontal spacing

I'm currently working on aligning the boxes for each <li> tag next to each other without any spaces in between. However, at the moment, there is a significant gap separating each box. How can I eliminate this space? Here is the HTML code snippe ...

Calculate the number of parent nodes and their respective child nodes

I am curious about how I can determine the number of children nested within parent-child relationships. For example: const parent = document.querySelectorAll('.parent'); parent.forEach(el => { const ul = el.querySelector('.child3-chi ...

Is there a way to clear a @font-face downloaded font from the browser cache?

Recently, I realized that I made an error in my webapp release by using a limited version of "Droid Sans" with @font-face for Latin characters. The font files are hosted on my server. To rectify this issue, I have now updated the font to the full version s ...

Creating an .htaccess configuration for managing case-sensitive file names

Today marked the official launch of my new website, but I've encountered some unexpected issues with the .htaccess file. Despite my best efforts to address them prior to going live, it appears that there are still unresolved problems. You can visit t ...

Achieve a seamless transition for the AppBar to extend beyond the bounds of its container in Material

I am finalizing my app structure by enclosing it within an MUI Container with maxWidth set to false. The issue I'm facing is that the AppBar inside the container doesn't span the full width of the screen due to paddingX property enforced by the c ...

Utilize CountUp.js to generate a dynamic timer for tracking days and hours

I am looking to create a unique counter similar to the one featured on this website https://inorganik.github.io/countUp.js/ that counts up to a specific number representing hours. My goal is to display it in a format such as 3d13h, indicating days and hour ...

Having trouble with the alignment of the product grid on Woocommerce with the Wootique theme?

Hey there, I've been facing an issue with the woocommerce product display grid layout. The items keep getting misaligned, with one on a line and the others right next to each other. I attempted to fix it by adding some custom CSS code: .woocommerce ...

Sidebar Masonry - Use Bootstrap for a Unique Layout

My goal is to have the page divided into 4 rows, with Masonry aligning the posts within 3 rows and a sidebar displayed on the right. However, I am facing an issue where Masonry mixes everything up and does not allow me to have a sidebar at the right. HTML ...

Using jQuery to animate a div when clicked by the mouse

Here's the scenario: I have 3 block elements arranged in a specific order: Image Hidden Text Block (.hidden) Footer Block (.blockimage) When the page loads, the image is displayed over the hidden text block (which contains further infor ...

What is the best way to implement dragging functionality for an image within a specific area?

Here's a snippet of the code I'm working with: link This is the HTML code: <div class="border"> <div id="i-choose"> <input type="file" name="file" id="file" class="inputfile"> <label for="file"& ...

Using a personalized function in JQuery

I need to execute a JavaScript function I created after a JQuery event has been triggered. The function in question is called scrambleDot, and I defined it previously like so:var scrambleDot = new function() { //my code }. Here's the attempted implem ...

Is it not possible to collapse in webkit?

Check out this jsfiddle link for a visual example: http://jsfiddle.net/qrbhb/ If you use the following HTML markup: <div>There should be no gap between us</div> <br /> <div>There should be no gap between us</div> along with ...

Adding rows to a database can be done by utilizing a dynamic form that consists of both repeatable and unique fields

Here is my follow-up post addressing the issue I previously encountered. Initially, I erroneously used mysql instead of mysqli, but I have now made the necessary updates based on recommendations. I have a form that contains variable sets of fields (rangin ...

Can <option> tags be arranged side by side using CSS?

Here is a form I am working with: <form action="file.php" method="GET"> <input type="hidden" name="page"> <select> <option>Text 1</option> <option>Text 2</option> <option>Text 3 ...

Responsive Design and the Importance of Setting Min-Width in Bootstrap 3

After doing some research on Stack Overflow about defining a minimum width for a responsive layout in Bootstrap3, I encountered conflicting answers related to "media queries." My goal is to make my layout responsive up to a certain point. Once it reaches, ...

What is the best way to center align a card using Bootstrap 4?

<div class="container"> <div class="row align-items-center h-100"> <div class="col-6 mx-auto"> <div class="card bg-white mx-auto" id="maincard"> <div class="card-body"> ...

Rotation of the SVG coordinate system distorts angles

My comprehension of SVG, particularly the viewport, viewBox, and the user coordinate system, seemed fairly solid. In the initial example provided below, we utilized a viewBox with a matching aspect ratio as the viewport. As expected, there was no distorti ...

Setting the child elements of a CSS div to have the same width and be larger than the

Welcome everyone to my inaugural post! I hope I've followed the right steps. I'm encountering an issue where I have child divs that need to have equal widths. The #content can sometimes exceed the browser window's width (hence the 3000px), ...