Adjust the div container to wrap underneath the image if the webpage width decreases

Hello there, I am currently in the process of creating my own portfolio. I have a brief introduction that I would like to display next to an image of myself, with the image positioned on the right side.

I have a div called "container" which contains another div where the image and introduction are placed like this:

    <body>
  <div class="content">
    <img src="images/sjforwebsite.png" alt="Luigi and his dog" width="600" height="auto"> 
    <div class="introduction">
      <h2>
        Hello, hello! <br>
        My name is Steven Johnston
      </h2>
      <p>
        Thank you for visiting. <br>
        You can refer to me as "Steve" if you'd like! <br>
        I'm 28 years old and currently looking for a web developer position.
      </p>
      <p> 
        I have a passion for web development. <br>
         Especially designing visually appealing, robust, user-friendly websites. </p>
      <p> 
        Apart from web development, <br>
        I enjoy playing video games, watching horror movies, and going for walks. </p>
      <p>
        I am proficient in Python, Java, Kotlin, HTML, CSS, and JavaScript. <br>
        Additionally, I work with Adobe XD and Ableton for music production.
      </p>
      <p> 
        Creating meaningful projects is what drives me, and I thrive in collaborative environments. 
      <br>
        I believe I could be a valuable asset to your team! Feel free to reach out anytime.
      </p>
   </div>
  </div>
</body>

Here are the CSS styles used:

.root {
  background-color: aliceblue;
  font-size: 62.5%;
}

.content {
  max-width:70%;
  margin: auto;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: 80rem;
}

.introduction {
  border-radius: 5px;
  margin-top: 10rem;
  font-family: 'Source Sans Pro', sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  flex-direction: column;
  padding: 0.5rem;
}

I'm facing challenges in making the introduction div wrap below the image properly.

As shown in the images provided, when the webpage width decreases, I want the div to move under the image on the right. Any advice on achieving this layout adjustment would be much appreciated. Thank you.

https://i.stack.imgur.com/ke1nq.png https://i.stack.imgur.com/Ye9aY.png

Answer №1

If you're utilizing the power of flexbox, why not make use of the flex-wrap property within your .content class? This way, your content will wrap appropriately when the screen size decreases:

.content {
  max-width:70%;
  margin: auto;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-wrap: wrap; /* --> Inserted here <-- */
  justify-content: center;
  align-items: center;
  max-width: 80rem;
}

Answer №2

In this scenario, my recommendation would be to skip using flex entirely and instead opt for making the image a floated element (as demonstrated in the example below). This approach will allow the text to wrap around the image as intended.

(please note: I included width, height, and background color attributes to the image solely to ensure it takes up space in this code snippet, since the actual image is not available here)

.root {
  background-color: aliceblue;
  font-size: 62.5%;
}

.content {
  width: 100vw;
  height: 100vh;
  max-width: 80rem;
}

.content img {
  width: 300px;
  height: 400px;
  float: left;
  background: #ddd;
  margin: 0 10px 10px 0;
}

.introduction {
  border-radius: 5px;
  font-family: 'Source Sans Pro', sans-serif;
  padding: 0.5rem;
}
<div class="content">
  <img src="images/sjforwebsite.png" alt="Luigi and his dog" width="600" height="auto">
  <div class="introduction">
    <h2>
      Hello, hello! <br> My name is Steven Johnston
    </h2>
    <p>
      Thank you for coming over. <br> You can call me "Steve" if you want! <br> I'm 28 years old, and I am seeking a web developer position.
    </p>
    <p>
      I love web development. <br> just love designing websites that are visually stunning, robust, and satisfactory to the user. </p>
    <p>
      Other than web development, <br> I love playing video games, watching scary movies, and going on walks. </p>
    <p>
      I have experience with Python, Java, Kotlin, HTML, CSS, and Javascript. <br> Other technologies include Adobe XD, and Ableton for music production.
    </p>
    <p>
      I am passionate for creating meaningful work, and I love working with others.
      <br> I think I can be a great addition to your team! Feel free to contact me any time.
    </p>
  </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

Ensuring User Input Integrity with JavaScript Prompt Validation

I need help with validating input from a Javascript prompt() in an external js file using HTML code. I know how to call the Javascript function and write the validation logic, but I'm unsure how to handle the prompt and user input in HTML. Do I need ...

Issue: Map container not located when implementing a leaflet map with Angular

Here is the complete error message: core.js:6479 ERROR Error: Map container not found. at NewClass._initContainer (leaflet-src.js:4066) at NewClass.initialize (leaflet-src.js:3099) at new NewClass (leaflet-src.js:296) at Object.createMap [a ...

Assistance with Javascript Objects Using JSON and AJAX

Currently, I am utilizing Ajax to retrieve data from my Json file. A problem I am facing is that in one particular div of my html, I need to include both a heading and a paragraph. I attempted to create a property like so: "headingpara": "<h1> blah ...

Introducing HTML elements into pre-existing web pages

My interest lies in the idea of injecting HTML into existing web pages for enhanced functionality. Specifically, I am exploring the concept of creating a more efficient bookmarking system. As someone new to web development, I am unsure of how to achieve th ...

Avoid form submission when the 'enter' key is pressed in Edge, but not in Chrome or Firefox

I'm dealing with an issue in HTML where a 'details' tag is set to open and close when the user presses enter. However, on Edge browser, pressing enter on the 'details' tag actually submits the form. I've been tasked with preve ...

What is the best way to assign specific codes to separate pages using a single JS file?

I am currently working on a project that involves an authentication JavaScript which is responsible for managing user sign-ins and registrations. However, there are certain lines of code within this script that impact different pages in various ways. I n ...

Reorganizing content under an image as the browser is resized by implementing a media query

In the footer section of my document, I have text positioned next to an image (floated to the right). However, when I resize my browser to a minimum width of 768px, both the text and image lose alignment. My goal is to centralize both elements with the ima ...

The transparent overlay div does not activate when clicking on a button in Internet Explorer 10

While tidying up my CSS and JavaScript, I may have gone a bit overboard. The code seems to work fine on Chrome, Safari, and Firefox, but it's causing chaos in IE10. Check out the code here <div id="bgmbutton1"> <img id="button1" src ...

"The issue of a malfunctioning selected option in a select dropdown within an AngularJS application

I've been experiencing some odd behavior with my Dropdown control in an AngularJS application. The selected="selected" attribute doesn't seem to be working, resulting in blank default selected values. Additionally, I'm having trouble with t ...

Tips for including a close button in a slidedown panel

Having this as a functional slidedown effect: ::-webkit-scrollbar { width: 0px; /* remove scrollbar space */ background: transparent; } /* optional: show position indicator in red */ ::-webkit-scrollbar ...

Python is experiencing difficulties with copying xpath elements

I attempted to utilize some Python code to access Twitter and retrieve the "Happening now" text. Unfortunately, it was unsuccessful. import webbrowser print("Visiting Twitter.com...") webbrowser.get('C:/Program Files (x86)/Google/Chrome/Application/c ...

Guide on making an SVG tooltip using the Menucool JS extension

I am trying to add a simple tooltip to an SVG "map" when the mouse hovers over a rectangle. To create the tooltip, I would like to utilize this specific plugin. Here is how I have connected the SVG to HTML: <object data="map.svg" type="image/svg+xml" ...

CSS Problem: Background Color Not Showing Up in Table Rows

Check out my fiddle below: https://jsfiddle.net/teo7auv3/ I'm facing a challenge where I want to change the background color of the entire table row (TR) to red when there are validation errors. The problem seems to be related to this code snippet: ...

generate a flexible div that adjusts its height based on the size of the browser window

Is it possible to create a div layout structured like this: <div_wrapper> <div_header> </div_header> <div_content> </div_content> </div_wrapper> Upon page load, the div_header o ...

What could the possible reason behind the malfunctioning of my prepared statements for the insert operation?

I recently discovered that using prepared statements is a more effective method than using deprecated ones. Despite my best efforts and online tutorials, I haven't had any luck getting this to work or finding the problem. That's why I'm her ...

Methods for dynamically populating dropdown lists with JavaScript and Bootstrap

I have collected all 387 regions for the current date and now I want to dynamically populate a bootstrap dropdown with these regions using JavaScript. Below is the basic HTML code for a bootstrap dropdown: <div class="dropdown"> <button class ...

What is the most effective method to arrange absolute divs generated randomly in a grid-like formation?

Hey there! I'm facing an intriguing challenge with my app. It's designed to generate a variable number of divs which are always in absolute positioning. Unfortunately, making them relative is not an option due to some other factors within the app ...

Ways to modify CSS using JavaScript

Can anyone assist me with a custom CSS code that I found? It looks like this: header.type-2:not(.fixed-header) nav>ul>li>a{ color:#000; } I've been trying to change the color to #fff using JavaScript, but haven't had any success yet. ...

Text is overflowing from the table cell due to its length

UPDATE: I have included a screenshot for reference. My goal is to ensure that the text within the grid container does not scroll horizontally and instead fits within the available space. https://i.stack.imgur.com/CfFuy.png In my React Material-UI table, ...

The outcomes of using Wget versus Python requests may vary

I have been attempting to extract transaction records from the following website: . While researching on stack overflow, I came across a possible solution that involves using urllib.request and selenium.webdriver to retrieve and render a webpage. Here&ap ...