What could be causing the issue with the padding-top not being applied to my section?

I'm having trouble getting the desired 150px padding to appear on the top and bottom of a section in my project. Here's an example:

Below is the code for the section:

.wp-block-mkl-section-block .section-bg {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-repeat: no-repeat;
    max-width: none;
    z-index: 0;
}
section.section-hero .wp-block-columns.has-2-columns {
    max-width: 1080px;
    margin: 0 auto;
}
.wp-block-columns {
    flex-wrap: nowrap;
}
.wp-block-columns {
    display: flex;
    flex-wrap: wrap;
}
*, ::before, ::after {
    box-sizing: inherit;
}
.wp-block-column.col-two-third {
    flex-basis: calc(60% - 16px);
}
.wp-block-column {
    margin-bottom: 0 !important;
}
.wp-block-column {
    flex-basis: calc(50% - 16px);
    flex-grow: 0;
}
.wp-block-column {
    flex-grow: 1;
    margin-bottom: 1em;
    flex-basis: 100%;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: break-word;
}
.wp-block-column.col-one-third {
    background: rgb(255,255,255,.9);
    flex-basis: calc(40% - 16px);
    padding: 16px 24px;
}
<section class="wp-block-mkl-section-block section-hero" style="padding-bottom:150px;padding-top:150px">
        <div class="section-bg bg__stretched" style="background: url(http://new.cajunland.com/wp-content/uploads/2019/10/recipe-double-seasoned-cajun-burger.jpg) no-repeat fixed center/100%">
<div class="wp-block-columns has-2-columns">
            <div class="wp-block-column col-two-third">
                <p>&nbsp;</p>
            </div>
            <div class="wp-block-column col-one-third">
                <h1>Double Seasoned Cajun Hamburgers</h1>
                <p style="color:#000;"><strong>Yield:</strong> 4<br><strong>Prep Time:</strong> 15 minutes<br><strong>Cook Time:</strong> 10-15 minutes</p>
            </div>
        </div>
    </div>
</section>

Answer №1

After reviewing the example page's padding-top, it appears that the padding-bottom is functioning correctly as intended. You can see the details below:

However, the issue lies in the fact that the section-bg segment was fixed using position: absolute, resulting in the padding top and bottom not having any effect on the layout. To resolve this, you need to apply the padding to the section-bg class.

.wp-block-mkl-section-block .section-bg {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background-repeat: no-repeat;
  max-width: none;
  z-index: 0;;
  padding-bottom: 150px;
  padding-top: 150px;
}

View codepen for reference

Answer №2

Although there is padding present, the .section-bg container is styled with position: absolute and top: 0.

To address this, consider adjusting the top value and transferring the background property to the section element. Additionally, switching to height: 300px instead of relying on padding may also be beneficial.

Answer №3

Give this a try without the inline styles for padding of 150px from top and bottom.

.wp-block-mkl-section-block .section-bg {
    padding-bottom: 150px!important;    /* Add !important   */
    padding-top: 150px;                 /* Add !important   */
    background-repeat: no-repeat;
    max-width: none;
    z-index: 0;
    margin: 0 auto;
}

Answer №4

Success! After some tinkering, I found that Jaakko's suggestion of changing position:absolute to relative in the .section-bg div was on the right track. Additionally, relocating the background image to the parent section proved to be the key solution. Everything is now working smoothly. Appreciate the help from all involved.

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

Concealing excess background color in HTML/CSS

I'm currently experimenting with adding a background color shape, such as a large rotating div, to the background of my website. However, I've encountered an issue where placing this background in the desired location is causing a large margin to ...

Displaying various values from a cascading dropdown in Django

Currently working with Python 3.8 & Django 3.0, I am in need of passing multiple values (volume & volume size) to a dependent dropdown. While I have managed to fill the dependent dropdown with a single value (volume), I have come across some resour ...

Tips for optimizing iframe loading times using the onload event

I am facing an issue with the timing of iframe loading while using a list of URLs as sources. I have created a child iframe and appended it to the DOM, then run the onload function for further processing. However, the time recorded for each iframe seems in ...

Solving the right-to-left orientation issue in the Bootstrap navbar

I have implemented a navbar using the code below, which aligns well from the right side. However, the menu items are sorted in ltr order and I need them to be in rtl order, so that "Dropdown 1" starts from the right side of the page. Currently, it appears ...

Python script utilizing Selenium is returning an empty string when trying to extract data from

When I try to retrieve the value from a dynamically loading table by clicking on the TD element, it works fine. However, when I attempt to fetch the text from the same TD element, it returns an empty string despite trying XPATH and CSS Selector methods. H ...

The PHP random number generator appears to be malfunctioning when being compared to the $_POST[] variable

In this section, random numbers are generated and converted to strings. These string values are then used in the HTML. $num1 = mt_rand(1, 9); $num2 = mt_rand(1, 9); $sum = $num1 + $num2; $str1 = (string) $num1; $str2 = (string) $num2; The following code ...

Ways to Randomly Flip Divs

I have developed an application where all divs flip vertically on hover. I am looking for a way to make the flipping random without requiring a hover. Any ideas on how to achieve this? .vertical.flip-container { position: relative; float: left; ma ...

Center and justify image inside flexbox using MUI

Can someone explain why my image appears centered but not justified? I'm feeling confused about this. <Box sx={{ display: 'flex', minHeight: '100vh', alignItems: 'center', flexGrow ...

Forced Landscape Viewing on Mobile Site with No Auto-Rotation

My website is equipped with a mobile stylesheet: <link rel="stylesheet" href="css/mobile.css" media="handheld"> In addition to that, I am utilizing jQuery to customize functionality for mobile devices. I am wondering if there is a method to enforc ...

jquery hover effect not functioning properly

I have a question regarding my jquery mobile application. I am trying to implement a hover effect on items with the class grid-item, where the width and height change simultaneously in an animation. Here is the code snippet I am using: $('.grid-i ...

Modify the appearance of HTML dialog box using CSS styling

Currently, I am working on a Java Spring project that includes a single CSS file consisting of around 1500 rows. Recently, I was tasked with adding a dialog box to one of the screens in the project. The issue I encountered is that the style of the dialog b ...

Display a jQuery loading window

Need help with displaying a loading div when making an ajax post request. I've tried the following code but it's not working. Can someone please assist in resolving this issue? $(document).ready(function() { $('a.pagerlink').click( ...

What could be causing my sticky positioning to not function properly when I scroll outside of the designated

My website is organized into sections, with each section corresponding to a hyperlink in the navigation menu. I've applied the CSS property position: sticky to my navbar, which works as expected within the section bounds. However, I want my red navbar ...

Steps for pulling information from the database and presenting it in a text box for users to edit

I'm struggling with a webpage that should allow users to update data from the database, but for some reason, the data is not displaying in the textbox. How can I make it show up correctly? Currently, on my webpage, users have to manually input all th ...

Java servlet is unable to interpret the name of an html select tag

Currently, I am implementing a feature where table rows with select boxes are added dynamically and the values of these select boxes are retrieved in a servlet. The process of adding the select boxes is functioning properly; however, when attempting to ret ...

Toggle visibility of multiple DIVs with identical classes using radio buttons

I'm looking to streamline my use of radio buttons in HTML. How can I implement a single set of radio buttons at the top that will toggle the visibility of all DIVs with the same class on my webpage? <form> <input type="radio" name="csr_sel ...

There is a lack of definition for an HTML form element in JavaScript

Encountering an issue with a HTML form that has 4 text inputs, where submitting it to a Javascript function results in the first 3 inputs working correctly, but the fourth being undefined. Highlighted code snippet: The HTML section: <form action="inse ...

What is the best way to execute two JavaScript functions within an inline onclick event?

I am currently working on the following code snippet: <script> function delay (URL) { setTimeout( function() { window.location = URL }, 2000); }</script> And then I have the following within the <body> element: <img src="small_rabbi ...

Retrieving a value from an array at random to assign to a different variable

I have different options for a specific variable depending on the scenario --> var lowSpeed = Math.random() * (45 - 30) + 30; var mediumSpeed = Math.random() * (60 - 45) + 45; var highSpeed = Math.random() * (80 - 60) + 45; var highwaySpeed = Math.rando ...

What steps can I take to guarantee that both images and text adapt well to different screen sizes?

Is there a way I can organize my website to display 3 movies per row with the text centered relative to the image? Here is how it currently looks (the red box is just for reference, please ignore): https://i.stack.imgur.com/w2pgN.jpg Also, when I resize m ...