The image is not properly aligned on the desktop screen due to positioning issues in the HTML

Recently, I've been working on optimizing my website for different screen ratios. However, I'm encountering issues with positioning the image on the left side and the text on the right side specifically on desktop screens.

Below is a snippet of my HTML content (text and image):

.wrapper{
    width: 100%;
}

.wrapper img-info{
    width: 100%;
}
...
...

If you would like to see the problem visually, here's a screenshot: incorrect image positioning example For more details or to view the full html/css source code, you can visit my website kevnkkm.de or leave a comment on this question!

Thank you in advance! (And apologies in advance for any facepalms I may have caused šŸ˜…)

Answer ā„–1

Organize your content and visuals within a shared container using Flexbox for optimal display:

  .article-container {
    display: flex;
    flex-direction: row;
  }
  .article-container article {
    flex: 1 0 75%;
    order: 2;
  }
  
  .article-container .startseite-img {
    flex: 1 0 25%;
    order: 1;
  }

With Flexbox, you can easily rearrange elements without changing the HTML structure. This is achieved through order: 1.

The property flex: 1 0 75% serves the following purposes:

  • The first number signifies how an element should expand.
  • The second number denotes how the element should shrink.
  • The third value acts as the base when determining actual expansion and shrinking percentages.

Detailed guide with examples on working with Flexbox available here.

Example in Action:

Expand the code snippet to observe its functionality across the full page layout

.wrapper {
  width: 100%;
}

.wrapper img-info {
  width: 100%;
}

.img-info h2 {
  width: 100%;
  padding: 30px 30px 20px;
  font-size: 50px;
  color: #111;
  line-height: 44px;
}

.img-info p {
  padding: 0px 30px 20px;
  font-size: 16px;
  color: #111;
  line-height: 24px;
}

.startseite-img {
  width: 100%;
}

@media only screen and (min-width:768px) {
  .wrapper {
    width: 600px;
    margin: 0 auto;
  }
  .img-info h2 {
    width: 100%;
    padding: 20px 0px 0px;
  }
  .img-info p {
    padding: 20px 0px 0px;
  }
  .startseite-img {
    padding-top: 30px;
  }
}

@media only screen and (min-width:1000px) {
  .wrapper {
    width: 1000px;
  }
  .article-container {
    display: flex;
    flex-direction: row;
  }
  .article-container article {
    flex: 1 0 75%;
    order: 2;
  }
  
  .article-container .startseite-img {
    flex: 1 0 25%;
    order: 1;
  }
  .wrapper img-info {
    width: 50%;
    float: right;
  }
  .img-info h2 {
    padding: 20px 0px 0px 30px;
  }
  .img-info p {
    padding: 20px 0px 0px 30px;
  }
}
<div class="wrapper">
  <div class="article-container">
    <article class="img-info">
      <h2>Hi!</h2>
      <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
      <p> At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
        et dolore magna aliquyam erat, sed diam voluptua.</p>
    </article>
    <img class="startseite-img" src="16.9%20Placeholder.png">
  </div>
</div>

Answer ā„–2

Your text has been updated. The image tag has been placed after the text, causing the image to appear below the text.

<div class="wrapper">
            <img class="startseite-img" src="16.9%20Placeholder.png">
            <article class="img-info">
                <h2>Hello!</h2>
                <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
                <p> At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
            </article>
            
        </div>

Answer ā„–3

Utilize this code snippet

To display images in a column using flex, place the img tag before the article tag.

.wrapper{
    width: 100%;
    display:flex;
    justify-content:space-around; 
}
.wrapper .startseite-img{
  max-width:100%;
  width:400px;
  height:400px;
  max-height:auto;
  margin-right:1em;
}
.wrapper img-info{
    width: 100%;
}

.img-info h2{
    width: 100%;
    padding: 30px 30px 20px;
    font-size: 50px;
    color: #111;
    line-height: 44px;
}

.img-info p{
    padding: 0px 30px 20px;
    font-size: 16px;
    color: #111;
    line-height: 24px;
}


@media only screen and (min-width:768px){
    
    .wrapper{
        margin: 0 auto;
    }
    
    .img-info h2{
        width: 100%;
        padding: 20px 0px 0px;
    }
    
    .img-info p{
        padding: 20px 0px 0px;
    }
    .wrapper .startseite-img{
        margin-right:1em;
        margin-top:1em;
  }

}

@media only screen and (min-width:1000px){
    
    .wrapper{
        width: 1000px;
    }
    
    .wrapper img-info{
        width: 50%;
        float: right;
    }
    
    .img-info h2{
        padding: 20px 0px 0px 30px;
    }
    
    .img-info p{
        padding: 20px 0px 0px 30px;
    }
    .wrapper .startseite-img{
        margin-right:1em;
        margin-top:1em;
     }
    
 }
<!DOCTYPE html>
<html lang="en">
<head>
  <title>image-on-left</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="wrapper">
            <img class="startseite-img" src="https://www.motocms.com/blog/wp-content/uploads/2018/07/css-main-image.jpg">
            <article class="img-info">
                <h2>Hi!</h2>
                <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
                <p> At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
            </article>
        </div>
</body>
</html>

Answer ā„–4

.container{
    width: 100%;
}

.container .image-info{
    width: 100%;
}

.image-info h2{
    width: 100%;
    padding: 30px 30px 20px;
    font-size: 50px;
    color: #111;
    line-height: 44px;
}

.image-info p{
    padding: 0px 30px 20px;
    font-size: 16px;
    color: #111;
    line-height: 24px;
}

.main-image {
    width: 100%;
}

@media only screen and (min-width:768px){
    
    .container{
        width: 600px;
        margin: 0 auto;
    }
    
    .image-info h2{
        width: 100%;
        padding: 20px 0px 0px;
    }
    
    .image-info p{
        padding: 20px 0px 0px;
    }
    
    .main-image{
        padding-top: 30px;
    }
}

@media only screen and (min-width:1000px){
    
    .container{
        width: 1000px;
    }
    
    .container .image-info{
        width: 50%;
        float: right;
    }
    
    .image-info h2{
        padding: 20px 0px 0px 30px;
    }
    
    .image-info p{
        padding: 20px 0px 0px 30px;
    }
    
     .main-image{
        padding-top: 0px;
        width: 50%;
        float: left;
    }
}
<div class="container">
  <article class="img-info">
    <h2>Hello!</h2>
    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
    <p> At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
      dolore magna aliquyam erat, sed diam voluptua.</p>
  </article>
  <img class="main-image" src="https://via.placeholder.com/150">
</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

Leverage the power of jQuery to merge the values from two input fields into a third input

Currently exploring jQuery and attempting to combine the contents of box one and box two to display them in another input field separated by ||. For instance, if "hello" is entered in the first text box and "you" in the second box, I want to show hello||y ...

Using an aria-label attribute on an <option> tag within a dropdown menu may result in a DAP violation

Currently, I am conducting accessibility testing for an Angular project at my workplace. Our team relies on the JAWS screen reader and a helpful plugin that detects UI issues and highlights them as violations. Unfortunately, I've come across an issue ...

Is it possible to create a responsive Material UI tab design?

How can I make the Material UI tab react component responsive? Check out the documentation for MATERIAL UI TAB here If I have multiple tab items with a search bar like shown below, how can I ensure that the input component stretches the whole width of th ...

Issue with PHP redirection not functioning as expected upon submission

Thank you for taking the time to offer assistance. I am encountering an issue with a basic HTML contact form that utilizes a PHP file for processing. The form's method is set to post and it directs its action to a PHP file. Upon completion of the PHP ...

Using Bootstrap DatePicker with Angular on Safari

I am experiencing some difficulties with the safari browser. I have an angular app that includes a function to automatically select the current week in a datepicker during ngOnInit. Interestingly, this feature works perfectly on browsers like Firefox, Bra ...

Encountering unexpected problems when generating large image files using BufferedImage, the results may vary based on the compilation process

I'm currently working on a project in Java where I need to create a huge image using the following code: BufferedImage bi = new BufferedImage(58240, 1664, BufferedImage.TYPE_INT_RGB); The size of the image is quite large. However, I am facing a st ...

Struggling to get the nth-child selector to function properly in IE8

Looking for a solution to alternate colors in a table? Here's what I tried: #grid tr:nth-child(odd) { background-color:#eee; } #grid tr:nth-child(even) { background-color:#fff; } Unfortunately, this works in Firefox but not in IE8. After some i ...

Display temporary image until real image loads within ng-repeat angularjs

I am looking to display a placeholder image while the actual image is being loaded. I have tried using the ng-image-appear plugin. The issue I'm facing is that the placeholder image does not appear for img elements inside ng-repeat, although it works ...

col-md is taking precedence over col-sm at lower screen resolutions

Col-md takes precedence over col-sm in Bootstrap 4 https://i.sstatic.net/ydL5O.png ...

Creating a list of items using HTML tags should be coded in a way that fits neatly within the main container element

UPDATE: I've come across this code that seems to be functioning somewhat as desired. You can view it live at UPDATE - It's still not aligning properly within the #main div! I've experimented with both 100% and 990px for width in #menu span, ...

"Modify the MySQL database each time a user changes the value in a

As a student, I am looking to update value(s) whenever a student changes the value(s) in the correction or update form. So far, I have been able to retrieve and display values in text boxes based on the name selected from a dropdown list from the database ...

Position a box to the right of a Bootstrap 3 fluid container

I've been grappling with Bootstrap and just launched a web app using Bootstrap 3. I'm trying to position a box on the right side of the screen, but despite several hours of researching and testing, I can't seem to find the solution... This i ...

Optical imaging-guided Page Division

Looking for guidance on implementing a program that can perform "Vision-based Page Segmentation" with practical information rather than just theoretical knowledge. I prefer using JS (jQuery) and PHP for this project. After reading the article on VIPS: a ...

Inconsistent behavior with CSS Grid column widths in Firefox versus Chrome

As a beginner in CSS Grid, I recently encountered an issue where the layout differed between Firefox and Chrome. It seems like Firefox is adhering strictly to the grid width specifications set with "grid-template-columns", whereas Chrome is adjusting based ...

How can I make the Search String stand out in the mysql result?

Here's the code I've written up to now <form method="post" name="search"> <input type="search" name="k" placeholder="Enter Keywords"> <input type="submit" value="Search"> </form> <? $skw = $_POS ...

Fastest method for inserting CSS rules using pure JavaScript

I've been developing a library with a strict size limit of 1KB, and I'm almost hitting that threshold. My challenge now is to implement a CSS rule for controlling the show/hide behavior. [hidden]{ display:none !important } The HTML page does no ...

Is it possible to switch the value of a css property using jQuery without toggling

Can you provide an efficient way to toggle a CSS property value back and forth? Iā€™m currently trying to address the CSS transition 0/auto issue. Here is my code snippet in JavaScript: jQuery(document).ready(function($) { var height = $('#men ...

jQuery load script triggers multiple executions

There is a method that loads content and replaces it into a div element: $("a[data-ajax='true']").on('click', function (event) { event.preventDefault(); var goToLink = this.href; animateLink(this); $(&ap ...

Ways to turn off hover highlighting

Is there a way to disable the highlighting effect of the <select> element in HTML? When you hover over items in the dropdown list, a blue color strip moves with your mouse. I need to find a way to get rid of this effect. Here is an example of the c ...

Exploring methods to validate a Reactive Form in Angular 10+ by incorporating two groups within the formBuilder.group

I am looking to implement form validation with two separate groups within the main formBuilder.group. I am unsure of how to access the 'errors' value in my HTML [ngClass]. component.ts: createForm(): void { this.myForm = this.formBuilder ...