When I input text into each div, the grouped DIVs remain in place and do not shift downwards

Looking at the snippet provided, the div with the class divSection is organized in groups. These divs should remain below the text (text 1, text 2, text 3) that are within the div with the class divSection. Adding a margin to divSection is an option, but I prefer it to have a margin of 0 when there's no content inside the div.

.divSection3, .divSection7{
  height: 38px;
  background-color: rgba( 26, 26, 26, 0.7);
}
.section{
  text-align: center;
  padding-top: 13px;
  display: flex;
  flex-basis: 100%;
  align-items: center;
  text-transform: uppercase;
}
.section::before,
.section::after {
  content: "";
  flex-grow: 1;
  background: rgba(255,255,255, 0.35);
  height: 1px;
  font-size: 0px;
  line-height: 0px;
  margin: 0px 8px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

<div class="container mt-5">
  <div class="row">

    <div class="col-12" style="background-color: red;">

      <div class="row">

        <div class="divSection3 col-lg-12">
          <div>
            <h6 class="section text-white ml-2 mr-2 ml-lg-0 mr-lg-0">Title 1</h6>
            <div>
              <h5>texto 1</h5>
            </div>
          </div>
        </div>

        <div class="divSection7 col-lg-12">
          <div>
            <h6 class="section text-white ml-2 mr-2 ml-lg-0 mr-lg-0">Title 2</h6>
            <div>
              <h5>texto 2</h5>
            </div>
          </div>
        </div>

        <div class="divSection3 col-lg-12">
          <div>
            <h6 class="section text-white ml-2 mr-2 ml-lg-0 mr-lg-0">Title 3</h6>
            <div>
              <h5>texto 3</h5>
            </div>
          </div>
        </div>

      </div>
    
    </div>

  </div>
</div>

This is how it should appear:

https://i.sstatic.net/XViwF.jpg

Answer №1

Kindly consider removing the height: 38px; attribute from the selectors .sectionThree, .sectionSeven as it serves no functional purpose.

Additionally, it is best practice to use consistent names for classes in order for them to be easily targetable with CSS rules. For individual and unique elements, it is advisable to utilize IDs instead of classes.

I trust this information proves valuable to you!

Answer №2

What do you think of this design?

CSS:

.divSection {
  background-color: rgba(26, 26, 26, 0.7);
}

h5 {
  background-color: red;
}

.u-padding-top {
  padding-top: 5px;
}

.section{
  text-align: center;
  display: flex;
  flex-basis: 100%;
  align-items: center;
  text-transform: uppercase;
}

.section::before,
.section::after {
  content: "";
  flex-grow: 1;
  background: rgba(255,255,255, 0.35);
  height: 1px;
}

HTML:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

<div class="container mt-5">
  <div class="row">

    <div class="col-12" style="background-color: red;">

      <div class="row">

        <div class="divSection col-lg-12 u-padding-top">
          <div>
            <h6 class="section text-white ml-2 mr-2 ml-lg-0 mr-lg-0">Title 1</h6>
            <div>
              <h5>texto 1</h5>
            </div>
          </div>
        </div>

        <div class="divSection col-lg-12">
          <div>
            <h6 class="section text-white ml-2 mr-2 ml-lg-0 mr-lg-0">Title 2</h6>
            <div>
              <h5>texto 2</h5>
            </div>
          </div>
        </div>

        <div class="divSection col-lg-12">
          <div>
            <h6 class="section text-white ml-2 mr-2 ml-lg-0 mr-lg-0">Title 3</h6>
            <div>
              <h5>texto 3</h5>
            </div>
          </div>
        </div>

      </div>

    </div>

  </div>
</div>

UPDATE: Removed redundancy

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

Python tutorial: Executing onclick values with a click

I'm currently working on writing some Selenium Python code and I have a question. The website I am testing has multiple time slots available, and I am attempting to simulate a mouse click specifically geared towards the 8:30-11:30 timeslot. Below is ...

In Bootstrap 4, the positioning of :after is different compared to Bootstrap 3

Our bootstrap nav-tabs have a unique default look with an 'indicator' icon below the selected tab. This is achieved by styling the active anchor element as follows: https://i.sstatic.net/UQos5.png However, when migrating to bootstrap 4, we noti ...

How can I generate a checkbox in a database with a field that allows for enabling and disabling?

I am looking to design a table that includes questions, checkboxes, and text boxes. All the questions are stored in a database and called through an array. In addition, I want to create disabled textboxes that become enabled when their corresponding checkb ...

Resizing Your WordPress Header Logo

Hi there! I am struggling to resize the logo in the header of my website www.cookingvinyls.com. Despite my efforts, I can't seem to override the hardcoded version. I attempted to modify the width and height lines in header.php, but unfortunately, it ...

Is there a way to perfectly align a left-aligned drawable with a hint in a TextInputEditText and position them closer to the bottom of the text input field?

Struggling to align the drawableLeft horizontally with the hint and bring them closer to the bottom of the TextInputEditText. I have experimented with various attributes but haven't been successful so far. Wondering if I might be overlooking something ...

Checking with jQuery Validate: displaying an error message if input matches a certain value

I spent 6 hours trying to figure out a solution to my issue. Currently, I am utilizing the jQuery Validation plugin. In my form, there is a password input field. When an AJAX request detects an incorrect password, another input field is set to a value of ...

Encountering a database deletion error with Spring Boot Thymeleaf

I'm currently facing an issue where I am attempting to remove an entry from my database. However, when I try to delete it on my html page, I end up being redirected to an error page instead of the intended destination. The entry I am trying to delete ...

The performance of the image slider is not smooth

After creating a basic javascript/css image slider as a learning exercise, I am now looking to implement it in real-world projects. However, the animation is choppy on my high-spec desktop and even worse on mobile devices. You can view the slider in action ...

Unable to utilize the full column space provided by bootstrap

I need assistance in making three buttons span the entire width of a column. The grid consists of 3 sections for the buttons and 9 sections for other components. Here's a visual reference. Essentially, the buttons should take up the space highlighte ...

Displaying limited items based on conditions in CSS

If there are 10 <p> tags, is it possible to limit them to only 5 by hiding the other 5 using CSS? Do I need to add a class five times with nth-child? Can CSS accommodate conditions for this purpose? Considering that the number of <p> tags is ...

Vuetify: how to disable the color transition for v-icon

My menu includes both icon and text items, with hover color styled using the following CSS: .v-list-item:hover { background: #0091DA; } .v-list-item:hover .v-list-item__title, .v-list-item:hover .v-icon { color: white; } The problem is that the ...

What is the best way to pinpoint particular text within a paragraph that includes numerous line breaks?

So here is the puzzling situation I'm grappling with. Here's a peek at the HTML snippet: <p>This paragraph has <br><br> two unusual line breaks <br><br> and it happens TWICE!</p> The problem arises when tryi ...

Dynamic content in CSS horizontal alignment

In a parent div with fixed width, I have dynamically created divs that I want to distribute horizontally without knowing the exact number of elements. I tried using the "Using inline-block and justified text" technique from a CSS Tricks page but it did not ...

Steps for including a class to a div

I recently implemented code from a tutorial found at in my layout. This tutorial provides instructions on how to incorporate fadeout effects into a bootstrap flash message. <% flash.each do |key, value| %> <div class="alert alert-block alert ...

The display:flex property with justify-content:space-around is malfunctioning in React and causing issues

I've been trying to troubleshoot the issue with my header, but so far I haven't found a solution. Could you please take a look at my code first? // Code simplified for clarity, no need to worry about variables const Header = () => { return ...

What is the best method to align a form in three columns from each side without relying on Bootstrap?

Is there a way to center the form inside a card with 3 columns on each side, so that the form appears in the middle occupying about 6 columns without relying on Bootstrap, Materialize or any similar framework? Thanks! <div class="card"> & ...

What is the method for triggering two actions within a single linked tag?

I have a link tag structured like this: <a href="<?php echo base_url().'dashboard' ?>" class="check_session">Home</a> Upon clicking the "Home" link, it should navigate to the dashboard. At the dashboard page, I want to check i ...

Contrast between using sendFile('/index.html') versus render('index') with Jade

As a newcomer to JS, I recently stumbled upon a similar question but with a different perspective. So my inquiry is: What are the advantages of using a Jade template in Express over simply sending raw HTML as a response? In other words, why would one choos ...

What is the best way to show a dynamic number of data elements for a specific attribute in a Vue js component?

Currently, I am facing an issue with my Vue app where I have a product listing displayed using v-for. Each product has multiple headlines and corresponding top features. The layout for these headline-top feature pairs looks like this in the webpage: PRODU ...

Is there a way to extract all nested URLs on a webpage using rvest and xml2?

I need assistance extracting nested links from the website provided. Despite my efforts, the code I am using is only producing an empty character vector. url1 <- "https://samplewebsite.com/sample-page" url1 <- read_html(url1) url1_body < ...