Adjusting the margin on an element within a div with display: table-cell can cause the content in another cell

Here is a simple layout that I have: http://jsfiddle.net/656ckfyq/


  <div class="container">
        <div>
           Some jumping content here
        </div>
        <div>
            <a href="#" class="more">More</a>
        </div>          
   </div>

And these are the styles for it:


    .container {
        display: table;
        border: 1px silver solid;
     }

     .container div {
         display: table-cell;
         padding: 10px;
     }

    .more {
        display: block;
        border: 2px red solid;
        margin-top: 20px;
     }

The issue arises when trying to move only the link in the second cell down by 20px. Somehow, this also affects the content in the first cell.

What could be causing this behavior and how can it be fixed?

Answer №1

To ensure proper alignment, apply the vertical-align: top property to the table-cells:

.container {
  display: table;
  border: 1px silver solid;
}
.container div {
  display: table-cell;
  padding: 10px;
  vertical-align: top;
}
.more {
  display: block;
  border: 2px red solid;
  margin-top: 20px;
}
<div class="container">
  <div>
    Some content with consistent alignment
  </div>
  <div>
    <a href="#" class="more">More</a>
  </div>
</div>

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

Implement CSS to stack images upon zooming

On my menu page, I have two images that I want to display side by side in the web browser and stacked on top of each other in a column when viewed on mobile. Currently, with framework7's row and column classes, the images are positioned next to each o ...

How can I access the DOM element within my render function in React on the same component?

I'm curious about the best approach for accessing DOM elements within my render function from the same component. It's important to keep in mind that this component will be rendered multiple times on a single page. For example: var ToDoItem = R ...

Stop the bootstrap navbar from resizing

I implemented a bootstrap navbar that looks like this... <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="#">WebSiteName</a> </div& ...

Increase the spacing between elements in a row using Bootstrap's margin utility

I am working with Bootstrap and have a row class containing three different elements. I want to create a margin of 20px between each element in the row container while keeping them all on the same line. Currently, when I add a margin class with a parameter ...

What is causing this Container Div to disrupt my design?

I have a situation where I am attempting to place two elements, a "read more" button and another floating button, inside a container. However, I want both of these elements to align to the left within the container. Strangely, when I run the code, the elem ...

Static vs Relative Positioning: Understanding the Contrast

Can you explain the distinction between static (default) positioning and relative positioning in CSS? ...

The window.addEventListener function is failing to work properly on mobile devices

Hey there! I am facing an issue in my JS code. I wrote this code because I want the menu to close when a visitor clicks on another div (not the menu) if it is open. The code seems to be working fine in developer tools on Chrome or Firefox, but it's no ...

The Bootstrap Row emerges from the shadow of the margin

Recently, I started diving into the world of Bootstrap. While playing around with some code to create rows resembling a table, I noticed an issue. When I loaded the code in my browser, the margins of the rows appeared off-screen. Take a look at this simple ...

Adding a gradient to enhance an SVG chart

Hey there! I'm currently experimenting with Plotly to create some awesome charts, and I've been trying to figure out how to give my area-charts a gradient instead of the usual fill with opacity. This is how I typically build my graph: Plotly.ne ...

What is the best way to implement jQuery on my website?

Instead of copying all the example code here, you can check out the jQuery demo page: Demo Page I would like to integrate the Latest News example with scrolling text in red from the demo page into my website. The demo page also provides links to the sour ...

What causes the lower gap to be smaller than expected when using "top: 50%; translateY(-50%);" on specific elements within the parent container?

My top-bar layout needs to have all elements vertically centered, but I'm experiencing issues with the top-bar_right-part not behaving as expected when using the core_vertical-align class. The left menu works fine, however. To illustrate the problem, ...

Animating the height of a container with unspecified initial and final heights using CSS transformations

I am faced with a challenge in styling a container that dynamically changes its height based on the content it holds. The issue arises when I want to add a transition effect to this dynamic height change. Since the height is determined by the changing text ...

Issue with importing CSS file in Vaadin Java

Currently, I am tackling the eighth part of the Vaadin Tutorial series. Watch the video here: https://www.youtube.com/watch?v=ttuBu8dYNn0 For the text version, visit: I am currently facing a challenge with the final step of importing the provided CSS fi ...

The navigation bar buttons are aligned to the left and are configured to stack on smaller screen

My Navbar is giving me some trouble. It collapses on screens less than 768 pixels wide, but from 768 pixels onwards it acts strangely until it can fill the page properly: https://i.sstatic.net/jOVYX.png I attempted to use nav-justified in the HTML, but it ...

Troubleshooting problem with responsive image display and blurred effects

Initial problem I have a photo gallery on my website. When you click on a photo, you can view a larger preview. To cater to mobile users, I set the following CSS: .overview img { height: auto; width: 90%; } However, I am facing an issue where the hei ...

Is it possible to conceal the controls on the slick carousel?

Is there a way to prevent slick from automatically adding next and previous buttons? I've tried using CSS to hide them but it doesn't seem to work. <button type="button" data-role="none" class="slick-prev" aria-label="previous" style="displ ...

Having trouble loading CSS and JavaScript files in CodeIgniter?

In my project, I am utilizing Bootstrap as a template. However, when attempting to access Bootstrap in Codeigniter, the page fails to load the CSS and JavaScript files. I have included the URL in autoload.php $autoload['helper'] = array('url ...

PHP Random Background Image Selector

I have a PHP code that is currently displaying a random header image every time the page is refreshed. While this works fine, I now need to add specific background-position css properties to some of the images. For instance, I would like 'headerimage ...

Stop images from flipping while CSS animation is in progress

I've been developing a rock paper scissors game where two images shake to mimic the hand motions of the game when a button is clicked. However, I'm facing an issue where one of the images flips horizontally during the animation and then flips bac ...

JavaScript - The left dropdown menu stubbornly remains visible when clicked in white space, unlike the right dropdown which disappears as expected. Puzzled by this inconsistency

Whenever I click on the selection criteria box, a dropdown menu appears. Clicking on the white space or the data table button makes the drop-down menu disappear, which is good. However, when I perform the same action for 'choose data table,' the ...