The vertical shift in one of the inline table cell DIVs is being caused by two of them

I've been searching for a solution to my issue, but have come up empty-handed. I apologize if this has already been discussed before.

My HTML page contains a section that appears as follows:

<div id=wrap>
    <div id=lb>
         Content
    </div>
    <div id=rb>
        Content
    </div>
</div>

This code divides the body into two sections - a left section (LB) and a right section (RB). Accompanied by some CSS markup:

#bwrap {
 width: 100%;
 height: 400px;
 display:inline-table;
 ...
}
#lb {
 width: 71.5%;
 display: table-cell;
 ...
}
#rb {
  width: 28.5%;
  display: table-cell;
  padding: 30px 6px 7px 6px;
  border-left: 1px #6A6A6A solid;
  border-right: 1px #6A6A6A solid;
 }

Initially, everything looked fine when I added content to #RB from right to left. However, upon inserting content into #LB, I noticed that all the content in #RB shifted downwards to align with the bottom of #LB's content. Despite there being no overlap of content or DIVs. This unexpected shift occurred specifically when I embedded a Google Calendar into #LB. Visually, everything appeared normal except for the downward shift in #RB.

Can anyone provide insight on where I may have made a mistake? I attempted adjusting floats and absolute positioning, but none of these solutions seemed to work - in fact, some worsened the situation.

Answer №1

Implement the following CSS:

vertical-align: top;

See a working demonstration here

Answer №2

The reason for the jumping down is due to the additional padding and border styles applied to rb, which are increasing the overall width of the container beyond 28.5%. To correct this issue, consider using the following CSS:

#lb {
 width: 70%;
 display: table-cell;
 ...
}
#rb {
  width: 20%;
  display: table-cell;
  padding: 30px 6px 7px 6px;
  border-left: 1px #6A6A6A solid;
  border-right: 1px #6A6A6A solid;
  oveflow:hidden;
 }

If the above CSS adjustments do not solve the problem, try adding a float: left property to both ids mentioned.

Answer №3

Remember that when applying paddings to elements with percentage-based widths, the padding is added to the total width. To ensure correct proportions, consider reducing the width slightly.

Answer №4

Avoid the use of display: table-cell as it can lead to inconsistencies across different browsers. Instead, consider utilizing floats and widths for a more consistent layout.

Furthermore, applying padding or margins to an element with a defined width may result in browser compatibility issues. It is recommended to approach this differently to avoid potential challenges.

You might want to try something like the following structure:

<div id="wrap">
   <div id="lb">
      content 
   </div>
   <div id="rb">
      <div id="rp">
         more content
      </div>
   </div>
</div>

Accompanied by the following CSS styles:

#wrap {
  width: 100%;
  height: 400px;
  display: block;
  ...
}
#lb {
  width: 71.5%;
  display: inline; //may not be necessary
  float: left;
  ...
}
#rb {
  width: 28.5%;
  display: inline; //may not be necessary
  float: right;
 }
 #rp {
  border-left: 1px #6A6A6A solid;
  border-right: 1px #6A6A6A solid;
  padding: 30px 6px 7px 6px;
 }

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

Regular Expressions in action - Substituting text within an eZ Publish XML field

Before utilizing the eZ Publish 5 API to create an Xml content, I need to make some modifications. I am currently working on implementing a Regex to edit the content. Below is the Xml code I have (with html entities) : View Xml code here http://img15.ho ...

What is the purpose of using a visually striking and prominent HTML tag?

After 15 years of working in html development and managing multiple websites, I have come to realize that bold and italic tags essentially serve the same purpose. I can apply CSS styles to both to achieve similar effects. I have even experimented with maki ...

Learn the steps to Toggle Javascript on window resize

Is there a way to toggle Javascript on and off when the window is resized? Currently, resizing the window causes the navigation bar to stick and remain visible above the content. <script> if ( $(window).width() <= 1200 ) { }else{ $('nav& ...

Reset the dropdown list back to its initial state

I am facing an issue with two dropdown lists in my view. When I change the value on the first one, it should update the second one accordingly. Initially, this functionality works fine with the script provided below. However, if I change the first dropdown ...

Can we ensure there is consistently an even number of columns when using auto-fill?

Hello, I am just starting to explore CSS grid. Take a look at the example below: .platform { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); grid-gap: 20px; } .item { width:100%; background-color:#aaa; padding:10 ...

Showing the number of times a button has been pressed

I have written some HTML code to create a button and now I am looking for guidance on how I can use Vue.js to track how many times the button has been clicked. Here is what I have so far: <div class="123"> <button id = "Abutton&q ...

Showing ASP code within a DIV element (inline)

Working on setting up a 'shopping cart' feature on our website, but running into some issues with the ASP code. Does anyone have any advice to offer? In the image below, you can see that when items are added to the cart, the 'total' is ...

Exploring smooth scrolling functionality using AngularJS and integrating it with IFrames

After implementing an angular controller, I included the following code: angular.element(document).ready(function () { ... } Within this setup, I added a function to enable smooth scrolling to the hash of window.location.hash using .animate({scrollTop... ...

What is the proper usage of main.js and main.css within the skeleton portlet project that is created by the Liferay 6.0.6 plugin SDK?

Is it a good practice to include portlet-specific JS or CSS in them only if <portlet:namespace /> works within them? Should I rely on unique function/variable names or class names instead? ...

Is there a way to overlap shapes (transform) using ::before and ::after in CSS? I'm facing an issue where Edge is not showing the shape on top

I designed two diagonal shapes to overlay a container with a background image using the pseudo elements ::before and ::after. While this setup functions correctly in Firefox and Chrome, it is not working as expected in Edge. What could be causing this di ...

The switch statement is not functioning properly when the button is pressed

I am trying to trigger an alert inside a switch statement when I click a button, but for some reason, it is not working. Even if I simply have an alert in the previous function, there is no output on my website. What could be causing this issue? Here is ...

What is the best way to create grid designs using less in bootstrap?

When using Bootstrap without a preprocessor, we include classes directly into our opening tags like this: <div id="El" class="col-md-1"></div> Personally, I usually work with Bourbon Neat and Sass. With Sass, I can import mixins in the rules ...

Transferring the AJAX response into a JavaScript variable

New to AJAX and JS here. I am implementing an AJAX code that fetches data from a php service. I am trying to figure out how to store the returned data in a JavaScript variable, which I can then display on the UI. Below is my AJAX code snippet: <script ...

Fan Animation in CSS

I have three unique images that I would like to animate in a fan-like manner consecutively. I prefer not to merge the images in Photoshop, as I want them to be displayed one after the other. Here is the code snippet (dummy images are used): .bannerimg ...

What are some ways to achieve a smoother hover effect?

.proposal p{ font-size: 14px; color: #494949; margin-bottom: 15px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; line-height: 20px; max-height: 100px; -webkit-line-clamp: 3; -webkit-box-orient: vertical; } .proposal: ...

Generate selection choices by looping through a JSON document

I am attempting to develop a search box that will provide autocomplete suggestions based on user input from a key-value pair in a json file. I initially thought using datalist would be the most suitable approach for this task, however, upon running the cod ...

Using HTML to get the minimum date specified by a different date

Can someone assist me? I am trying to retrieve the minimum parameter for the second date field based on the value entered in the first date field: Check-In: <input type="date" name="checkin" min="<?php echo date('Y-m-d');?>" required& ...

Splitting areas within a liquid vessel using bootstrap 5

My container is structured like this with divisions: <div class="container-fluid"> <div class="row"> <div class="col-3"> sidebar </div> <div class="col-7"> top slider </div> <di ...

Ensure that the dropdown <select> remains open even while filtering through options

I am currently working on implementing a mobile-friendly "filtered dropdown" design: Usually, a <select> control remains closed until the user clicks to open it. Is there a straightforward way to keep it always open? I understand that this would ma ...

The div is not completely encased by the fieldset

I have utilized fieldset to generate a titled border around a div. Here is the code snippet: <div class="form-group col-xs-12"> <fieldset class="field_set col-xs-12"> <legend style="font-weight:bold;font-size:20px"> ...