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: https://i.sstatic.net/KRjA8.jpg

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

Utilize Bootstrap in an Angular template to effortlessly expand one element while collapsing all others

I'm facing an issue with a table in my component. Each row has a button that, when clicked, should expand to show some calculated data specific to that row. However, the problem is that when one button is expanded, it keeps other buttons expanded as w ...

Looking to add elements to a specific div dynamically using jQuery? Let's explore how to insert comments seamlessly

I would like to implement a comment system that adds entered comments to a specific div. Here's the code I have so far: <ul class="comments"> <li> <a class="commenter_name" href="/">Dushyanth Lion</a> ...

Struggling to get the knockout js remove function to function properly within a nested table structure

I've been encountering issues while trying to eliminate the formulation elements with the 'Delete comp' link. I can't seem to figure out why it's not functioning as expected. Moreover, the 'Add another composition' link o ...

I am interested in altering the font color

Hey there, I'm new to HTML and CSS and need some help changing the font color and size of my navbar. I've included my code below: HTML code: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...

Trouble getting custom CSS media queries to function properly alongside Bootstrap 3

I've encountered an issue while using bootstrap 3 with jquery UI to implement search and select fields for the user. The CSS code seems to be working fine on larger screens, but it's completely non-functional on smaller screens. I tried applying ...

Tips for applying styles to elements that are not directly related when the parent element has a specific class using CSS

I have some HTML code structured as shown below. <div class='A'> <div class='B' /> <div class='C' /> </div class='A'> <div class='D' /> My Objective: If A contains C: ...

The scroll() function in jQuery does not bubble up

Recently, I encountered an issue with a Wordpress plugin that displays popups on scroll. The code I currently have is as follows: jQuery(window).scroll(function(){ //display popup }); The problem arises with a particular website that has specific CSS ...

Selecting options from a pop-up menu

I've created a dropdown menu with what seems to be correct code. However, there are no errors showing up, but the selected item from the menu is not alerting as expected. Here is the jsfiddle link $(document).ready(function () { // This function ...

Troubleshooting: jQuery click event not functioning correctly with if-else statement

For some reason, I can't seem to figure out how to toggle the color of all list items with a class of "link" between blue and black. I've searched through numerous posts but still can't find a solution. Working Example: http://jsfiddle.net/ ...

Bootstrap 4 Card Body Spinner Overlay with Flex Alignment

Seeking to center a spinner both vertically and horizontally within a bootstrap 4 card body. Despite trying my-auto, justify-content-center & align-items-center, it seems like I'm missing something. I've double-checked the display types and ...

Rotate images every 5 seconds, pulling them directly from the server

I am looking to update the users every seven seconds on my website. To do this, I need to retrieve all user information from the server using JavaScript. What is the most efficient way to accomplish this task? My initial thought is to send an HTTP request ...

I am experiencing difficulty closing my Bootstrap 5 nav bar once it has been clicked in mobile view

Having an issue with my Bootstrap 5 navbar in mobile view - it can be clicked to open, but won't close when clicked again. Currently using Bootstrap v5.0. If anyone has insight into why this might be happening, please let me know! <link href ...

What is the best way to eliminate the underline text decoration from a link element?

Take a look at this JS Bin. I want to change the link Project name in there. By default, it is underlined when hovered over. How can I remove that effect? I attempted using a class project-name: a:hover, a:focus .project-name { text-decoration: non ...

How can I retrieve XML through a URL using HTML5 and JavaScript?

Currently, I am looking to access an XML file through a URL link. My main goal is to retrieve the file automatically and extract its contents for further processing. However, I am facing difficulties in finding the appropriate method to obtain and read t ...

Strategies for avoiding text selection interference with onMouseMove event

I am in the process of adding a "resize handle" to adjust the width of my left navigation panel. This handle, represented by a div, triggers an onMouseDown() event that calculates the necessary widths and applies them to the relevant elements during subseq ...

floating point for a list item compared to other elements

nav > ul > li { float: left; } #one { float: left; } <nav> <ul> <li> he has a cow </li> <li > he has a dog </li> <li> he has a mouse </li> </ul> & ...

Pressing JavaScript buttons to trigger another button

I am looking to develop a script that generates a button which then creates another button. The subsequent button will be assigned an id attribute by incrementing from 1 to infinity. This feature should apply to all buttons (original button and the newly ...

Is there a way to make the image above change when I hover over the thumbnail?

Seeking assistance with JavaScript to enable changing thumbnails on hover. As a newcomer to JavaScript, I'm struggling to grasp how to achieve this effect. I've already implemented fancybox for gallery functionality. Below is the HTML and CSS f ...

Is there a method to identify if the dark theme is enabled in iBooks while working within an EPUB file?

Is there a specific code or feature that iBooks uses to enable the customization of certain sections within the book, such as changing to lighter colors when night mode is on? ...

Stylesheets may not display correctly in Firefox and IE

Just wanted to say that I recently put together this little website , but I am completely stumped on why the CSS file won't show up in Firefox or IE. I know it's a basic question, but I'm still learning all of this. Thank you so much for a ...