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

Exploring Nested CSS Grids and Resizing Images on the Web

Having an issue resizing images in CSS Grid. I set up a main layout with 2 columns, and within the first column is another grid where I intended to place an image and some text. Please remove the html comment so you can see the image. The problem lies i ...

How can I make a DIV grow taller without impacting neighboring DIVs?

I am working on expanding a specific DIV within a series of DIVs for an image gallery. However, I am facing an issue where when I expand the particular DIV, it affects all the following ones and causes them to shift positions, leaving a large blank space t ...

Avoid page refreshing when retrieving data using PHP and AJAX

In my current program, I am able to add data and insert it into the database. However, I am looking for a way to automatically send this data to another page or browser without refreshing. I have two browsers open, so how can I submit the data to the other ...

The list countdown for loop only appears in the initial iteration

Hey there, I'm currently facing an issue with duplicating my JavaScript countdowns and displaying images of cards on each loop iteration. Strangely, the countdown only appears in the first instance even though it's within the loop. I'm seeki ...

Should servlet response be HTML for use in AJAX calls?

I am currently in the process of developing a web application with multiple pages, including index.html which serves as the main page and contains various <a> tabs linking to different Servlet pages. As part of my design, I have a consistent CSS lay ...

`Can you teach me how to dynamically load HTML elements using input JSON data?`

What is the best way to iterate through an input array of objects? I currently have data for only 2 people included. However, there are more than 50 people's information in the input and I need to loop through all of them. Here is a sample code snip ...

Tips for Accessing a New Website Using the Floating Layer Close Button

How can I trigger the opening of a new browser window when a visitor clicks the close "x" on my floating layer ad? The close button is within an HTML link code ("a href"), but simply putting a URL in there does not seem to work. <script language=" ...

Get the large data file in sections

I ran a test script that looks like this: async function testDownload() { try{ var urls = ['https://localhost:54373/analyzer/test1','https://localhost:54373/analyzer/test2'] var fullFile = new Blob(); for (le ...

Utilizing values from .properties files in Java with Spring for internationalization: A straightforward approach to handle Strings

Here is the code snippet I am using: @Value("${app.user.root}") private String userRoot; This code helps me to fetch a constant value from my application.properties file. Within my GetMapping method, I need to redirect to the error page and pass a S ...

Shorten the content while preserving the HTML using JavaScript

When printing a string containing HTML links, I need to truncate the visible text while preserving the link structure. Simply using a substring method would disrupt the HTML tags in the string. I aim to display only 100 characters but also remove any inc ...

View complex response objects in Postman as easily digestible tables

I am interested in displaying the data provided below as a table using Postman Tests. The table should have columns for product, price, and quantity, with Items listed in rows. It's important to note that there may be multiple shippingGroups within th ...

Develop a distinctive JavaScript solution that enables an image to appear in fullscreen upon loading the page, and then smoothly fade away after precisely

I have been trying to incorporate a feature on my Shopify frontage website where our logo appears fullscreen and then fades away or disappears after a few seconds, allowing people to access the rest of the website. However, I am facing difficulty in making ...

Chrome is experiencing compatibility issues with Datatable

I'm encountering an issue with Datatables and I'm at a loss on how to resolve it. In my custom cms, Datatables functions perfectly on my Mac (Safari, Chrome, Firefox) and also works seamlessly for my colleagues on Windows machines. However, we ...

Choose from a variety of video play options

Being new to javascript, I've successfully combined two functions that control video playback, but they seem to be conflicting with each other. The first function is designed to offer custom pause and play controls for the video // VIDEO CONTROLS STA ...

The image is failing to animate according to the PNG sequence function

Enhanced Functionality: Upon clicking the "Tap Here" image button, a function called "GameStart()" is triggered. This function ensures that the main image "Star" descends down the page from the top through an animated sequence using png logic. The propose ...

How to Retrieve the Value of the First Drop Down that is Linked to a Second Drop Down Using Angular JS

How can I use AngularJS to retrieve the second select drop-down value based on the selection made in the first select drop-down? Hello, I have set up two dropdown fields in MyPlunker and within the ng-option, I am applying a filter "| filter:flterWithKp" ...

Unable to add data to an Array once subscribed to BehaviorSubject

Hello everyone, this is my first time asking a question here. I hope it's clear enough for you to understand :) Let's dive straight into the issue at hand. I have a query regarding a behaviorSubject variable in TypeScript that is not allowing me ...

Miscalculation in PHP MySQL: Incorrect output when adding field 1 and multiplying field 2 by

In my MySQL table, there are 4 fields: product price cost, selling price, stock of products, and earnings per unit. For example: If the cost of our product is $100, we sell it for $120, and we have a stock of 10 units, the following code calculates the e ...

Concealing a form after submission using JavaScript

After submitting the form, I am attempting to hide it and display a loading GIF. I've experimented with various methods, including changing ClassName to Id, but haven't had success. This is for a school project, and I've spent a significant ...

The renderToString function in Material UI's sx property doesn't seem to have

Every time I apply sx to a component that is rendered as a string and then displayed using dangerouslySetInnerHtml, the styles within the sx prop do not work. Here is an example showcasing the issue: Codesandbox: https://codesandbox.io/p/sandbox/wonderfu ...