The positioning of inline block elements is not aligned correctly

Can anyone shed light on why my text is causing the block element to move downward? Removing the text aligns the block elements perfectly.

<div class="item-0" align="center">
    <div class="row">
        <div class="col-lg-12">

            <div class="body-0">
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
                tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
                quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
                consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
                cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
                proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
            </div><!-- body-0 -->

            <div class="image-0">
                <img src="images/ios_android_devices2.png" class="img-responsive" alt="ios_android" id="ios_android">
            </div><!-- image-0 -->

        </div><!-- col12 -->
    </div><!-- row -->
</div><!-- item-0 -->

This is the CSS code:

.item-0 {
background-color: green;

}

.body-0{
display: inline-block;
background-color: red;
max-width: 100;
width: 400px;
height: 250px;

}

.image-0 {
display: inline-block;
height: 250px;
max-width: 100;
width: 300px;
background-color: #ccc;

}

Answer №1

Implement vertical-align:top;:

   .image-0 {
      display: inline-block;
      height: 250px;
      max-width: 100;
      width: 300px;
      background-color: #ccc;
      vertical-align:top;
    }
    .body-0{
      display: inline-block;
      background-color: red;
      max-width: 100;
      width: 400px;
      height: 250px;
      vertical-align:top;
    }

View Codepen Example

Answer №2

To ensure the inline blocks align properly, utilize vertical-align:top (remember to view the effect using the "Full page" option in the demo):

.item-0 {
background-color: green;
}

.body-0{
display: inline-block;
  vertical-align:top;
background-color: red;
max-width: 100;
width: 400px;
height: 250px;
}

.image-0 {
display: inline-block;
  vertical-align:top;
height: 250px;
max-width: 100;
width: 300px;
background-color: #ccc;
}
<div class="item-0" align="center">
    <div class="row">
        <div class="col-lg-12">

            <div class="body-0">
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
                tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
                quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
                consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
                cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
                proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
            </div><!-- body-0 -->

            <div class="image-0">
                <img src="images/ios_android_devices2.png" class="img-responsive" alt="ios_android" id="ios_android">
            </div><!-- image-0 -->

        </div><!-- col12 -->
    </div><!-- row -->
</div><!-- item-0 -->

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

Automatically populating and submitting a form after receiving search results via ajax

I have been struggling with this issue for a few days now and could really use some help from the experts here. I am new to sql, javascript, jquery, ajax, css, and php. Although I studied Computer Science in college 15 years ago, I seem to be missing some ...

Using Python's Beautiful Soup library to retrieve text from h1 and id tags

I've been attempting to retrieve the text from an HTML id called "itemSummaryPrice," but I'm having trouble figuring it out. html = "" <div id="itemSummaryContainer" class="content"> <div id=&quo ...

DIV that can be removed and dragged around, as well as replaced

I plan on creating a few <div> elements and I am looking to have the ability to move and replace these Divs. After doing some research, I believe that jQuery could help me achieve this. I came across the following code snippet: <script> ...

ASP.NET Dynamic Slideshow with Horizontal Reel Scrolling for Stunning

I'm curious if there is anyone who can guide me on creating a fascinating horizontal reel scroll slideshow using asp.net, similar to the one showcased in this mesmerizing link! Check out this Live Demo for a captivating horizontal slide show designed ...

What is the best way to conceal a div when there are no visible children using AngularJS?

I need help with hiding a parent div only if all the child items are invisible. I have successfully hidden the parent when there are no children, but I am struggling to figure out how to hide it based on visibility. <div ng-repeat="group in section.gro ...

Place background image in the center with a background color overlay

After browsing through this post on Stack Overflow, I managed to stretch my background image using CSS with the background-size: cover; property. However, I realized that this solution doesn't completely meet my needs. I'm dealing with an image ...

Issue with CSS for Pagination and Content Display

When I print an HTML page, I want to include custom text in the header of all printed pages. @page { margin-top:5mm; margin-bottom: 25mm; margin-left: 30mm; margin-right: 30mm; @top-right{ content: "Page title"; /* Page title ...

Exploring innovative CSS/Javascript techniques for creating intricate drawings

When using browsers other than Internet Explorer, the <canvas> element allows for advanced drawing. However, in IE, drawing with <div> elements can be slow for anything more than basic tasks. Is there a way to do basic drawing in IE 5+ using o ...

Is it possible to merge two HTML selectors using jQuery?

In my HTML, I have two button elements defined as follows: <input type="button" class="button-a" value="Button a"/> <input type="button" class="button-b" value="Button b"/> When either of these buttons is clicked, I want to trigger the same ...

What is the best way to implement CSS rules for a hidden submenu?

Can anyone help me figure out how to apply CSS rules for a hidden submenu? I've attempted to use some JavaScript, but it's not working as expected. Below is a sample of the code I'm working with. The idea is that when you click on the anchor ...

Utilize DELETE and POST functionalities within a single form

Is it possible to include both a POST and DELETE request within the same form tags? I have a table and I want to be able to delete a row when it is selected. I have tried to make it work for both but I can only get one to function. My backend is built on ...

What methods can I use to locate and delete body selectors within CSS styling?

Currently, I am in the process of enhancing my PHP skills by identifying and removing body selectors within style tags. The objective is to eliminate any occurrences of body selectors that could potentially alter the body section of my HTML, especially pro ...

How can we apply styling to all selected elements except for the first one?

When customizing elements, I typically use the following approach: app-csv-header-selection { margin-left: 2rem; } This method has been effective so far. However, I am now looking to exclude the styling from the first element selected. Is there a way ...

The sole functioning menu at the moment is the final one

The values of u and v are being retrieved correctly as 1 and 0, but there seems to be an issue using them in the statement "t[i].children[v].onclick=function(){}". The code works fine when I manually input 1 for u and 0 for v. Here is the snippet: < ...

Show the content within the carousel indicators div

I'm working with a bootstrap carousel that has 3 tabs and I want to name them Step 1, Step 2, and Step 3. Even though I've placed these names in the carousel-indicator divs, they are not showing up. Any assistance on this issue would be greatly ...

Converting a lengthy HTML document into numerous JPEGs (or any preferred image format)

I am working on a lengthy webpage that can be viewed as having 40 individual pages. Each "page" is separated by a horizontal rule () and has a fixed height of 860px. My goal is to convert each of these "pages" into JPG images automatically. Can anyone pr ...

Creating a versatile table design using flexbox

Looking to create a gallery for images and videos using flexbox properties to create a dynamic table of divs to hold media. The challenge is generating the table automatically without specifying the number of rows and columns needed. For example, if I ha ...

The ripples can be found at the bottom of the map, not at the front

Having an issue when working with Globe where Ripple rings are always appearing on the backside of the map, rather than in front of it Referencing the source code from https://github.com/vasturiano/globe.gl/blob/master/example/random-rings/index.html and ...

Employing the HTML post method in conjunction with checkboxes

I am facing an issue while trying to use the HTML post function with PHP to insert a value of 1 or 0 into a database based on whether a user has checked a checkbox or not. Every time I submit the form, I encounter index errors regardless of the checkboxe ...

Creating functional links with card-img-overlay in Bootstrap v4

Encountering an issue where Bootstrap v4 cards utilizing card-img-overlay to overlay text on an image are causing links below the image to become unresponsive. The following links are functional: <div class="card" style="border-color: #333;"> & ...