Adaptive Layout - side menu is shifted to the side by the height of the image

I am currently facing an issue with my code involving a side menu and main content. In Desktop view, the side menu should be on the left and the company content on the right.

However, when I added pictures to the content (which I have commented out for now), the side menu shifted down by the size of the picture. Interestingly, this only happened with the first picture, hence why it is omitted in this example. But ideally, I would like to include images in production.

I attempted to resolve this by placing the picture inside a span, but that did not solve the issue...

Any assistance with this problem would be greatly appreciated.

Here is a snippet of my code:

.side-menu {
    display: inline-grid;
    width: 20%;
    margin-top: 23px;
    margin-left: 27px;
}
.company-content {
    width: 71%;
    display: inline-grid;
    /*margin-left: 75px;*/
}
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e1c11110a0d0a0c1f0e3e4b504e504c">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7c5c8c8d3d4d3d5c6d7e79289978995">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-sm-2 side-menu" style="padding-left: 0px;min-width: 200px;padding-right: 0px;margin-right:50px;padding-left:0px;margin-left:0px;">
      <ul id="menu-map" class="menu" style="padding-left:0px;">
          <li class=""><a href="/Category" aria-current="page">
            <span>Category</span>
          </a></li>        
          <li class=""><a href="/Subcat1" aria-current="page">
            <span><strong>Subcategory 1</strong></span>
          </a></li>
          <li class=""><a href="/Subcat2" aria-current="page">
            <span>Subcategory 2</span>
          </a></li>
          <li class=""><a href="/Subcat3" aria-current="page">
            <span>Subcategory 3</span>
          </a></li>
          <li class=""><a href="/Subcat4" aria-current="page">
            <span>Subcategory 4</span>
          </a></li>
      </ul>
</div>

<div class="company-content">
  <div class="row">
    <div class="col-sm-6">
        <!-- <span><img src="~/graphics/picture.webp" style="max-width: 350px" /></span> -->
      <b>John Doe</b>
      <br />
      <p>
        <span><b>Text</b></span> <br />
        E-Mail: <span id="email1">loading...</span>
      </p>
      <div class="card" data-person="john">
        <span class="dots"></span>
        <span class="more" style="display: none; color: black"
          ><br />This is a test text. Yup, still testing. <br />
          Teeeeeeeeeeeeeeeeeeesttiiiiiiiiiiiinnnnnnggg.</span>
        <button
          type="button"
          onclick="readMore('test')"
          class="Btn btn btn-dark">
          More
        </button>
      </div>
    </div>
    <div class="col-sm-6">
      <span><img src="~/graphics/picture2.webp" style="max-width: 370px" /></span>
      <br />
      <b>Janet Doe</b>
      <br />
      <p>
        <span><b>Text here</b></span
        ><br />
        E-Mail: <span id="test2335">loading...</span>
      </p>
      <div class="card" data-person="janet">
        <span class="dots Btn" onclick="readMore('test2')"></span>
        <span class="more" style="display: none; color: black">
          This is a test text. Yup, still testing.
          <br />
          Teeeeeeeeeeeeeeeeeeesttiiiiiiiiiiiinnnnnnggg...</span
        >
        <button
          type="button"
          onclick="readMore('test2')"
          class="Btn btn btn-dark"
        >
          More
        </button>
      </div>
    </div>
  </div>
</div>

Answer №1

If you include

width: 100%; display: inline-block;
in the span element, the image and text will remain on separate "lines".

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d1f1212090e090f1c0d3d48534d534f">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
    <div class="col-sm-6">
        <span style="width: 100%; display: inline-block;"><img src="https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg" style="max-width: 350px" /></span>
      <b>John Doe</b>
      <br>
      <p>
        <span><b>Text</b></span> <br>
        E-Mail: <span id="email1">loading...</span>
      </p>
      <div class="card" data-person="john">
        <span class="dots"></span>
        <span class="more" style="display: none; color: black"><br>This is a test text. Yup, still testing. <br>
          Teeeeeeeeeeeeeeeeeeesttiiiiiiiiiiiinnnnnnggg.</span>
        <button type="button" onclick="readMore('test')" class="Btn btn btn-dark">
          More
        </button>
      </div>
    </div>
    <div class="col-sm-6">
      <span style="width: 100%; display: inline-block;"><img src="https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg" style="max-width: 370px"></span>
      <br>
      <b>Janet Doe</b>
      <br>
      <p>
        <span><b>Text here</b></span><br>
        E-Mail: <span id="test2335">loading...</span>
      </p>
      <div class="card" data-person="janet">
        <span class="dots Btn" onclick="readMore('test2')"></span>
        <span class="more" style="display: none; color: black">
          This is a test text. Yup, still testing.
          <br>
          Teeeeeeeeeeeeeeeeeeesttiiiiiiiiiiiinnnnnnggg...</span>
        <button type="button" onclick="readMore('test2')" class="Btn btn btn-dark">
          More
        </button>
      </div>
    </div>
  </div>

Using Flexbox would achieve the same effect.

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

What is the reason behind Svelte not scoping the tag under a class, but instead using individual tag.class to style a component?

It is common practice to scope CSS styles for components like this: .my-component-01 h1 { ... } .my-component-01 h2 { ... } However, Svelte takes a different approach by applying the styles directly to the tags: h1.svelte-hlsza1{color:orange} h2.svelte- ...

Ways to ensure that a div, header, container, and other elements completely cover the viewport

Currently, I am attempting to create a header that spans the entire viewport regardless of screen size. This header will be split horizontally into 3 equal sections, each occupying one third of the header space. I experimented with setting the header hei ...

Adjust the height of the container div for the carousel according to the length of the text displayed

My image carousel features description content positioned on the right for wide-screen windows. However, I want the description to shift below the images when the browser window reaches a certain breakpoint. The challenge I am facing is that the height of ...

Exploring the process of web scraping from dynamic websites using C#

I am attempting to extract data from using HtmlAgilityPack. The website is dynamic in nature, displaying content after the page has fully loaded. Currently, my code retrieves the HTML of the loading bar using this method, but encounters a TargetInvocation ...

Enhancing Image Upload with Ajax/JavaScript: Generating Multiple Previews

I've been experimenting with an Ajax image uploader that I found on this website. Currently, I have managed to create duplicate preview images: one displayed under the input field and the other elsewhere on the page labeled as "this what you chose". H ...

Struggling with inputting text in an AngularJS application

I am facing an issue with populating a text input with the output of a function in my HTML code. Despite trying different approaches, I am unable to figure out why it is not working correctly. Below is the snippet of my HTML code: <input type="text ...

As you scroll, the opacity gradually increases, creating a dynamic visual

Struggling to replicate a feature on a website where images gain opacity as you scroll down? Check out this site for reference: . While my current code somewhat achieves this effect, I'm having trouble figuring out how to apply a darker opacity gradua ...

The alignment of the footer navigation is off-center

I can't seem to get my footer navigation centered properly. I've tried adjusting the CSS but it's still not working as expected. .main-footer li { float: left; font-size: 0.85em; padding: 0 0.5em; margin-bottom: 0.5em; } .main-fo ...

Is the MDL drawer not reaching the full height of the page?

I am currently utilizing Material Design Lite to incorporate a fixed header and drawer into my Ruby on Rails application. In the following video, you can observe that when I switch to another page, the drawer menu on the left side of the page fails to fill ...

Modify background image upon hovering using AngularJS

I cannot seem to make the background images of my divs change. Despite trying various options, none of them have been successful. Here's an example of my code: <div ng-controller="mainController" class="main"> <div ng-repeat="land in lan ...

Exploring a one-dimensional nested array in order to make updates to the higher level nodes

I have a 1D nested array: nestedArr: [ { id: 1, parentId: null, taskCode: '12', taskName: 'Parent', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []}, { id: 2, parentId: 1, taskCo ...

The navbar seamlessly adapts to the screen size, maintaining its responsiveness even when utilizing the .container class within Asp.Net MVC

I'm relatively new to ASP.NET MVC. Currently, I'm facing an issue with the navbar in my partial view for the shared layout. Despite adding the .container class from Bootstrap, the navbar doesn't conform to the screen size as expected. My a ...

The conditional rendering logic in the ng-if directive does not seem to be synchronizing

Currently, I am delving into AngularJS and working on a basic application to gain familiarity with it. Within my app, there are four tabs: List, Create, Update, and Delete. However, my goal is to only display the Update and Delete tabs when I press the b ...

Center the text vertically within a card using Vuetify styling

I am seeking a way to vertically align text within a card using Vuetify or traditional CSS in a Vue project. Here is my code: <template> <div> <v-container class="my-5"> <v-row justify="space-between"> <v- ...

Tips for creating a responsive Youtube embedded video

Check out this website for a good example: If you take a look, you'll notice that the header youtube video is responsive - it automatically resizes when the window size changes. Here are the <iframe> codes: <iframe id="bluetube-player-1" fr ...

Error in Flask app: Stripe Elements - "400 bad request: CSRF token not found or invalid"

Currently, I am in the process of following the Stripe Quickstart guide for integrating stripe Elements with Flask. While working through the tutorial available at https://stripe.com/docs/stripe-js/elements/quickstart, I encountered an issue - the token ap ...

What is causing the error that app.js file cannot be located?

Here is the layout of my directory: ReactCourse // Main folder public // Subfolder within ReactCourse index.html // HTML file with linked js file app.js // JavaScript file This is the content of index.html: <!DOCTYPE ...

Obtaining the Div ID After Clicking on a Link

I'm attempting to fade out a box once the X in that box is clicked. I haven't been able to make it work even after searching on Google. I managed to get it working when clicking the div itself using $(this), but my goal is for it to work when the ...

Enhance the appearance of a custom checkbox component in Angular

I developed a customized toggle switch for my application and integrated it into various sections. Recently, I decided to rework it as a component. However, I am encountering an issue where the toggle switch button does not update in the view (it remains t ...

Multiple web pages utilizing Angular app/widget

I have successfully built a chat application similar to Google Hangouts. However, I am facing a challenge with the angular app/widget running on other pages when URL's are changed, causing the app to either remain fixed or restart on the new web page. ...