When utilizing table-cell, the padding will automatically increase within the <div>

After creating two tables using table,table-cell, I noticed that increasing padding on the first cell also results in an increase in padding on the second cell, and vice versa. How can this issue be resolved?

.desc-one{
  width: 100%;
  margin-bottom: 20px;
  display: table;
}

.desc-one-one{
  width: 350px;
  background-color: #ffffff;
  display: table-cell;
  padding-right: 10px;
  border-radius: 10px;
  vertical-align: top;
  box-shadow: 0px 2px 1px #888888;
}

.quick-heading{
  font-size: 20px;
  font-family: opensans-semibold;
  color: #2199e8;
  padding-left: 10px;
  padding-top: 5px;
}
.row-two-one{
  max-width: 1200px;
  border-radius: 10px;
  background-color: #ffffff;

  box-shadow: 0px 2px 1px #888888;
}
.desc-one-two{
  display: table-cell;
  padding-left: 20px;
}
.recent-heading{
  color: #2199e8;
  font-size: 20px;
  font-family: opensans-semibold;
}
<div class="desc-one">
  <div class="desc-one-one">
    <h1 class="quick-heading">
      Quick links
    </h1>
  </div>
  <div class="desc-one-two">     
    <div class="row-two-one">
      <h1 class="recent-heading open-semibold">
        Low Stock Distributors
      </h1>
    </div>
  </div>
</div>

In my CSS code, when adjusting padding-top or padding-bottom on the first table cell heading, the second cell elements also reflect the same padding as seen in the first cell (and vice versa).

Answer №1

Upon testing your code, I noticed that only the first heading is receiving padding top. It's possible that there is another piece of code elsewhere on your page causing this additional padding.

.desc-one {
  width: 100%;
  margin-bottom: 20px;
  display: table;
}
.desc-one-one {
  width: 350px;
  background-color: #ffffff;
  display: table-cell;
  padding-right: 10px;
  border-radius: 10px;
  vertical-align: top;
  box-shadow: 0px 2px 1px #888888;
}
.quick-heading {
  font-size: 20px;
  font-family: opensans-semibold;
  color: #2199e8;
  padding-left: 10px;
  padding-top: 100px;
}
.row-two-one {
  max-width: 1200px;
  border-radius: 10px;
  background-color: #ffffff;
  box-shadow: 0px 2px 1px #888888;
}
.desc-one-two {
  display: table-cell;
  padding-left: 20px;
}
.recent-heading {
  color: #2199e8;
  font-size: 20px;
  font-family: opensans-semibold;
}
<div class="desc-one">
  <div class="desc-one-one">
    <h1 class="quick-heading">
                    Quick links
                </h1>
  </div>
  <div class="desc-one-two">
    <div class="row-two-one">
      <h1 class="recent-heading open-semibold">
                      Low Stock Distributors
                    </h1>
    </div>
  </div>
</div>

Answer №2

Your code is functioning perfectly, in agreement with the other responses.

However, there's a point of confusion in one of your comments regarding the vertical-align:top property in the style of the first cell.
Why was this property initially included if it needed to be removed for proper functionality? This can be misleading for those looking for solutions.

The reason behind this is that without specifying a vertical-align property, it defaults to 'baseline', causing both cells to align their contents at the bottom of the first line of text within each cell. This behavior is inherent to table cells; they work in conjunction.

To rectify this issue, the solution is to explicitly include vertical-align:top, which ensures that the contents of the cells align at their tops.

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

Start your slideshow automatically (with an option to toggle)

http://jsfiddle.net/r6uf38v4/ After the page loads, my goal is to have the slider begin automatically. However, I also want to provide the option for users to pause it using a checkbox and then resume the slider. $('#checkbox').change(function( ...

Troubleshooting the non-responsive behavior of Bootstrap's hidden-sm-down

Why are the two images within the <div> with hidden-sm-down still visible on my laptop when I resize the page? I need them to be hidden on small devices for a different menu layout. <div class="row"> <div class="col-m ...

New ways to style Links in NextJs 13

I am relatively new to Next.js and I am attempting to create a menu with a hover effect using the following code: import Link from 'next/link'; const MenuItem = ({ href, label }) => ( <Link href={href} className="menu-item"> ...

Inject $scope into ng-click to access its properties and methods efficiently

While I know this question has been asked before, my situation is a bit unique. <div ng-repeat="hello in hello track by $index"> <div ng-click="data($index)"> {{data}} </div> </div> $scope.data = function($index) { $scope.sweet ...

Unpredictable hues in a headline

Can the text in an H1 tag have each word appear in a different random color, and then refresh to show new random colors? I have 5 specific colors in mind that I'd like to use. How would I go about coding this? ...

An abundant array of options spread across numerous dropdown menus

I have been tasked by a client to do something new that I haven't done before, so I am seeking the best approach. The project involves creating a form with three dropdown menus where users can select from thousands of options. For instance: Users mu ...

Minimize the screen dimensions and adjust the margins accordingly

Having a problem with responsive margins? Take a look at this site as an example: When I shrink the screen size, the margins decrease and smoothly transition from 4 to 2 columns. In my case, it does something similar but the issue is that the margin does ...

SVG files do not fetch external CSS stylesheets when embedded in the DOM

Take a look at this example on jsFiddle. When using IE, the external CSS is loaded and the rectangle is red, but in Chrome and FF the rectangle stays black. What causes this difference? <!-- Used for referencing the external css --> <?xml-styl ...

Gleaming personalized select input/selectize input

I am striving to customize my Shiny select input in the following ways: Eliminate the label Set a unique background color: #2f2d57 Include a placeholder Enable users to both type-in and select Despite my efforts, I have not been successful in alignin ...

Having trouble submitting a date input form generated with vuejs on Safari browser

I am a huge fan of Vuejs and it's my go-to at work. The other day, I came across a rather perplexing scenario. If you have any insights into this, please do share. Here is the code in question: <script setup lang="ts"> import { ref ...

Tips for adjusting row height in a fluid table design using div elements

I'm having trouble making a responsive table (a keyboard) where only the cells are resizing instead of the whole keyboard fitting on the screen without any scrolling required. Here is the code I have so far: https://jsfiddle.net/723ar2f5/2/embedded/r ...

Next JS and the power of media queries

I've been searching for a while now, but I just can't seem to find a solution to my problem. I'm attempting to utilize different files for my media query breakpoints in Next JS, but they don't appear to be working. I created the files ...

Unable to generate webpage source code

Having some trouble with my Next.js project as I'm using getStaticProps and getStaticPath to build a page, but unfortunately, the HTML is not being generated in the page source. This issue is causing problems with SEO, and I haven't implemented r ...

Preventing a particular CSS file from being applied to my Angular component

Currently, my modal component is built using bootstrap, but we encountered an issue with our project's CSS file which also utilizes the same classes as bootstrap (.Modal, .Modal-header). This conflicting styling was causing problems for the design of ...

Retrieve the labels associated with highlighted text in a JTextPane

Hey everyone! I'm currently working with a JTextPane that has content type 'text/html'. I have loaded the Bible into this JTextPane where verses are separated by tags. What I want to achieve is determining the selected verse when a user clic ...

What is the best way to select just the innermost row of a nested table for emphasis?

I am working on a project with multiple nested tables and I am looking for a way to highlight the innermost row below the mouse pointer. How can I achieve this? Just to provide some context, I am using nested tables to present recursive tabular data, with ...

Having trouble choosing elements with angular.element within ng-repeat loop

In my HTML code, I am using an ngRepeat element: <ol id="animationFrame"> <li ng-repeat="animationImage in animationImages" ng-repeat-listener> <img ng-src="{{animationImage.src}}" id="{{animationImage.id}}"> </li> </ol& ...

Exploring Selenium WebDriver: Manipulating Table Elements and Iterating Through Rows

Is there a more efficient way to iterate through tables row by row without using Absolute Xpath? In my test case, I need to search for specific data in each row. This was the previous logic of my code: private static int iRow; WebElement sWorkUnitRows = ...

Having trouble with your CSS dropdown menu?

I've been struggling to implement a dropdown menu on my website following an online tutorial. Despite following the steps, I can't seem to get it working. It's frustrating because I want to move on to backend development. Hoping someone can ...

Sending JavaScript functions to PHP files via Ajax

My Current Project: I am currently developing a script that provides users with choices and generates new options based on their selections. To achieve this, I have created two scripts - one for the HTML structure of my page and another for fetching serve ...