Ways to utilize media queries for repositioning one div on top of another div

Utilizing Bootstrap 5 for website development, my aim is to enhance the responsiveness of the site across various devices.

For mobile users, I envision the image-containing div to appear above the div containing the header and paragraph content, but I'm uncertain on how to achieve this.

Here is the current mobile view:

https://i.sstatic.net/QMHlt.jpg

This is the code snippet:

h3:after {
  background: none repeat scroll 0 0 hsl(210, 55%, 41%);
  bottom: -10px;
  content: "";
  display: block;
  height: 2px;
  position: relative;
  width: 100px;
}

@media (min-width: 300px) {

}
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>About | </title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet">

Similar Challenge

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CCTV Services |</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="./css/all-services.css" />

Answer №1

Give This a Shot:

Please be advised that I have substituted your image with a placeholder image for the code snippet to function properly.

h3:after {
     background: none repeat scroll 0 0 hsl(210, 55%, 41%);
     bottom: -10px;
     content: "";
     display: block;
     height: 2px;
     position: relative;
     width: 100px;
}
 @media (min-width: 300px) {
}
<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>About | </title>
      <!-- <meta name="description" content="Write an awesome description for your new site here. It will appear in your document head meta (for Google search results) and in your feed.xml site description." /> -->
      <link href="https://cdn.jsdelivr.net/npm/font-awesome@6.4.0/css/all.min.css" rel="stylesheet">
      <link rel="stylesheet" 
         href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
      <!-- <link rel="stylesheet" href="/css/index.css" /> -->
      <link rel="stylesheet" href="./css/about.css" />
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0/dist/js/bootstrap.bundle.min.js"></script>
      <!-- <script src="/_bridgetown/static/js/main.96ffffaea92690057bfb.js" defer></script> -->
   </head>
   <body>
      <!-- ABOUT US SECTION  START -->
      <section>
         <div class="container text-start mt-3">
            <div class="row">
               <div class="col-md col-12 order-1 order-md-0">
                  <h3 class="display-3 text-start" id="about" pt-5>About Us</h3>
                  <br>
                  <p class="text-start">
                     We are dedicated IT professionals who excel in resolving a variety of IT-related challenges for our clients.
                     Utilizing cutting-edge technology, we offer hands-on assistance that empowers businesses to efficiently manage and sustain critical systems.
                  </p>
                  <br>
                  <p class="text-start">
                     At <Organization Name>, our focus is on harnessing technology to support our clients in reaching their business goals, whether they're launching a new project or executing an existing plan. Regardless of the scenario, we ensure seamless completion of projects, committing to delivering outstanding results that drive growth and success for our clients.
                  </p>
                  <br />
                  <div class="d-grid  col-6 mx-auto mb-4 text-start">
                     <button class="btn btn-primary" type="button" id="button">Submit a Ticket</button>
                  </div>
               </div>
               <div class="col-md col-12 order-0 order-md-1">
                  <img src="https://picsum.photos/200" class="img-fluid rounded float-start mb-3" alt="IT technicians working">
               </div>
            </div>
         </div>
      </section>
      <!-- ABOUT US SECTION  CLOSE -->

Clarification:

I adjusted col to col-md for both text and image to enable dynamic column widths beyond a certain screen size.

I included col-12 for the image and text to occupy full width and collapse on smaller screens.

Utilized order-md-x and order-x to alter the item order at different screen sizes.

Answer №2

If you want to achieve a responsive design using Bootstrap 5, you can take advantage of its grid system and ordering classes. Here's a breakdown of how you can structure your HTML and apply the necessary classes:

/* Styling for image container */
.col-md-6.order-md-2 img {
    max-width: 100%;
    display: block;
    margin: 0 auto;
    margin-bottom: 20px;
}

/* Styling for header and text container */
.col-md-6.order-md-1 {
    padding: 20px;
    background-color: #f7f7f7;
    border: 1px solid #ddd;
}

/* Media Query for screens with max-width of 767px (small screens) */
@media (max-width: 767px) {
    .col-md-6.order-md-2 img,
    .col-md-6.order-md-1 {
        width: 100%; /* Stack columns on top of each other */
        padding: 10px; /* Adjust padding */
        border: none; /* Remove border */
    }

    .col-md-6.order-md-1 {
        margin-bottom: 10px; /* Reduce spacing between containers */
    }
}
<div class="container">
    <div class="row">
        <div class="col-md-6 order-md-2">
            <!-- Image container -->
            <img src="your-image-source" alt="Image">
        </div>
        <div class="col-md-6 order-md-1">
            <!-- Header and text container -->
            <h2>Your Header</h2>
            <p>Your paragraph text here.</p>
        </div>
    </div>
</div>

Here's an explanation of the code:

The container class creates a fixed-width container that responds to different screen sizes.

The row class creates a row to hold your columns horizontally.

The col-md-6 class makes each column occupy half of the available width on medium screens and larger.

The order-md-2 class changes the order of columns on medium screens and larger, making the image container appear second.

The order-md-1 class changes the order of columns on medium screens and larger, making the header and text container appear first.

This setup ensures a responsive layout where the image container appears above the header and paragraph text container on smaller screens.

Remember to replace "your-image-source", "Your Header", and "Your paragraph text here." with your actual content and image source.

Bootstrap's grid system and utility classes like order-md-* simplify creating responsive layouts across different screen sizes without the need for extensive custom CSS for every breakpoint.

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

Tips for determining the full width of a webpage, not solely the width of the window

While we can easily determine the width of the window using $(window).width(); This only gives us the width of the window itself, not accounting for any overflowing content. When I refer to overflowing, I mean elements that extend beyond the visible view ...

Guide on aligning text to the center in the navigation bar

I am currently experimenting with a dropdown navigation bar using pure CSS. However, I am facing issues with text alignment as it only aligns the dropdown text. Setting left: 50% and right: 50% does center the text, but it doesn't cover the width of m ...

Is there a way to streamline the process of uploading an image and storing its details in a single HTML form with just one submit button?

Here is the code snippet I have: <form id="registration_form" action="AddProductServlet" method="post"> <div> <label> <input placeholder="Product ID" name="pid" type="text"> ...

Safari-exclusive: Google Maps API dynamically altering page aesthetics post-loading

Recently, I encountered a peculiar problem. Upon loading a page, the text displayed with full opacity. However, upon the Google Maps API loading after 2 seconds, the entire page's styling suddenly changed. It was as if the text on the page became less ...

Encountering an error of "undefined is not iterable, cannot read property Symbol(Symbol.iterator)"

While learning React through coding, I encountered an error (Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)). I am unsure where the problem lies. Any suggestions? When utilizing useEffect to activate setFiltere ...

Transitioning from LESS to SASS involves adapting responsive breakpoints

Adapting from Less to Sass has been my current focus. I have defined responsive breakpoints in Less variables: /* Breakpoints */ @break1:~"(max-width: 570px)"; @break2:~"(min-width: 571px) and (max-width: 1002px)"; @break3:~"(min-width: 1003px)"; These ...

What is the best way to narrow down the content cards displayed on the page?

I have recently developed a blog post featuring three distinct categories: digital marketing, tips and advice, and cryptocurrency. My goal is to implement a filtering system for these categories. For instance, I would like users to be able to click on a b ...

What is preventing hover from working correctly?

I'm having trouble getting images to display when hovering over text. Can anyone offer suggestions on what might be causing this issue? The images are being downloaded when clicked, so I know they're in the correct path. I've checked for com ...

Seeking a precise placement, must find a CSS-only answer

After spending two days experimenting with different CSS styles like absolute positioning, inline/inline-block display, and flex display, I have yet to find a solution for styling a timestamp's label position using pure CSS. https://i.stack.imgur.com ...

Issues have arisen in IE8 with the background gradient on hover elements in the menu, while it functions properly in all other web browsers

Welcome to the website: I've recently taken on a project involving the gradiated menu on this site. The menu works flawlessly in Firefox, Chrome, and Safari - the hover effect changes the background color to a light gradiated green. However, when it ...

Transforming data from an HTML table into a MySQL database

Is there a way to transfer data from an HTML table created with JavaScript to a SQL database? I have been experimenting with the addRow(tableID) function but it doesn't seem to work. Any suggestions on how to solve this issue? Below is the code snipp ...

Checkbox customization that shifts position when clicked

I seem to be missing something as I can't seem to find a solution for this particular issue. I have implemented custom checkboxes on a list of sentences. Initially, they appear fine, but once you check the first checkbox, it shifts its position. I am ...

Using a Jinja 'for' loop to create nested 'If' statements

I'm attempting to include an if statement within a loop for a jinja template: </table> <class="container"> <table border ="1"> <caption> BBOXX <caption> <thead class="thead-inverse"> <tr> <th& ...

Using column-count within a media query is not supported

I am encountering an issue with my CSS code that includes the column-count property within a media query, and for some unknown reason, it doesn't seem to be working! .masonry { -webkit-column-count: 3; -moz-column-count: 3; column-count: ...

Align the items in the center of a Bootstrap navigation bar

I am looking to center the navigation menu items on my navbar. Currently, my navbar layout appears like this: https://i.sstatic.net/BqRwW.png Specifically, I want "Users", "Admin", and "Records" to be centered within the navbar. Additionally, I would lik ...

What causes the device pixel ratio to vary across different web pages on the same device and operating system?

I am curious about why device pixel ratio varies between different websites and operating systems. For instance, when using the same device, this site displays a different pixel ratio on Windows compared to Ubuntu. On Windows, the pixel ratio is 1.34 whi ...

Styling with CSS to ensure divs are displayed in two rows

Check out this example I found: https://jsfiddle.net/n3qs0wke/ .wrapper { max-width: 600px; border: 1px solid #333; } .big-div { min-width: 212px; min-height: 212px; max-width: 212px; max-height: 212px; display: inline-flex; ...

Creating image filters using an object in jQuery

I am faced with a challenge where I have multiple image tags nested within a div that has the class google-image-layout. Each image is equipped with various data attributes, including: data-anger="0" data-disgust="0" data-facedetected="0" data-fear="0" da ...

Achieving Vertical Centering of Text in Bootstrap 5 Buttons with Flex Box to Prevent Overlapping Icons

How can I prevent the text on a Bootstrap 5 button with horizontally and vertically centered text, along with a right aligned icon, from overlapping when it wraps? Additionally, how do I ensure that the icon stays vertically centered when the button text w ...

Calculate the total width of LI elements and apply it to the parent UL or DIV

Is there a way to calculate the Total LI width and then set the width for the parent div? Here is an example of my code: <ul> <li>dsfdsfdsfds</li> <li>dsfdsfdsfds</li> <li>dsfdsfdsfds</li> <li>dsfdsfdsfds&l ...