Show the div in the right position for both desktop and mobile screens, utilize an accordion or consider shifting the div

My webpage is designed using bootstrap 4 and showcases images of our team members along with accordion functionality to display bios upon clicking the image.

On a desktop screen, everything functions smoothly with four images of team members displayed in a row. Clicking on an image reveals the corresponding bio below them.

However, the layout changes on mobile devices, with the images stacked vertically. When clicking on a team member, the bio appears at the bottom after the fourth person instead of directly underneath the clicked person.

My goal is to have the bio display right under the person whose image is clicked.

For instance, refer to the below sample image to get a better understanding:

Here is a section of the code snippet for reference:

<section class="p-5">
<div class="container" id="biolevelone">
<div class="row">
    <div class="col-md-3 col-sm-6">
       <div data-toggle="collapse" href="#bio1"><img src="image1.png"/></div>
    </div>
    <div class="col-md-3 col-sm-6">
       <div data-toggle="collapse" href="#bio2"><img src="image2.png"/></div>
    </div>
    <div class="col-md-3 col-sm-6">
       <div data-toggle="collapse" href="#bio3"><img src="image3.png"/></div>
    </div>
    <div class="col-md-3 col-sm-6">
       <div data-toggle="collapse" href="#bio4"><img src="image4.png"/></div>
    </div>
</div> <!-- row -->

<div class="collapse pt-2" id="bio1" data-parent="#biolevelone">
   <div class="card-body">
     <p>Bio text, a couple of paragraphs</p>
   </div>
</div>
<div class="collapse pt-2" id="bio2" data-parent="#biolevelone">
   <div class="card-body">
     <p>Bio text, a couple of paragraphs</p>
   </div>
</div>
<div class="collapse pt-2" id="bio3" data-parent="#biolevelone">
   <div class="card-body">
     <p>Bio text, a couple of paragraphs</p>
   </div>
</div>
<div class="collapse pt-2" id="bio4" data-parent="#biolevelone">
   <div class="card-body">
     <p>Bio text, a couple of paragraphs</p>
   </div>
</div>

</div><!--biolevelone data parent -->
</section>

I attempted to rearrange the code for the bio text cards, placing it between each profile image div. Unfortunately, this resulted in a different issue where on desktop screens, the profile images disappeared from the row and moved below the bio text upon clicking, although it worked correctly on mobile devices.

Answer №1

Is it possible to add classes to your div? If so, please review what I have implemented.

Here's a brief explanation: simply move your div that wraps the biography below the div that wraps the image. Then, add a class to manipulate the div. Finally, include a media query to display the biographies.

Take a look at the code snippet below:

.bio-container {
  position: relative; 
}
.biography {
    position: absolute;
    top: 200px;
    border: 1px solid;
    width: 100%;
}

@media only screen and (max-width: 812px) {
    .biography {
        position: static;
    }
    .collapse {
        display: block !important;
    }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<section class="p-5">
<div class="container" id="biolevelone">
<div class="row bio-container">
    <div class="col-md-3 col-sm-6">
       <div data-toggle="collapse" href="#bio1"><img src="https://dummyimage.com/100x100/000000/ffffff"/></div>
    </div>
    <div class="collapse pt-2 biography" id="bio1" data-parent="#biolevelone">
       <div class="card-body">
         <p>Bio text, a couple of paragraphs 1</p>
       </div>
    </div>
    <div class="col-md-3 col-sm-6">
       <div data-toggle="collapse" href="#bio2"><img src="https://dummyimage.com/100x100/000000/ffffff"/></div>
    </div>
    <div class="collapse pt-2 biography" id="bio2" data-parent="#biolevelone">
       <div class="card-body">
         <p>Bio text, a couple of paragraphs 2</p>
       </div>
    </div>
    <div class="col-md-3 col-sm-6">
       <div data-toggle="collapse" href="#bio3"><img src="https://dummyimage.com/100x100/000000/ffffff"/></div>
    </div>
    <div class="collapse pt-2 biography" id="bio3" data-parent="#biolevelone">
       <div class="card-body">
         <p>Bio text, a couple of paragraphs 3</p>
       </div>
    </div>
    <div class="col-md-3 col-sm-6">
       <div data-toggle="collapse" href="#bio4"><img src="https://dummyimage.com/100x100/000000/ffffff"/></div>
    </div>
    <div class="collapse pt-2 biography" id="bio4" data-parent="#biolevelone">
       <div class="card-body">
         <p>Bio text, a couple of paragraphs 4</p>
       </div>
    </div>
</div> <!-- row -->
</div><!--biolevelone data parent -->
</section>

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

AngularJS - Show Banner after two rows, then show two more rows

I'm attempting to showcase a Banner <div> after 2 rows of 4 x "col-md-3", succeeded by another 2 Rows - thus, resulting in the following markup: <div class="col-md-3">1</div> <div class="col-md-3">2</div> <div clas ...

What is the reason for the Pointer Lock API entry displaying a significant number when the window is compressed?

Take a look at these two screenshots that illustrate the issue: The first screenshot demonstrates the correct behavior - the fullscreen mode works perfectly. However, in the second screenshot, a problem arises. Depending on the size of the browser window, ...

Displaying a dynamic splash screen during the resource-loading process on an Android application

I would like to implement an animated image (currently using a set of PNGs) as a splash screen while my resources are loading. I have successfully displayed the splash screen using this method. However, the issue I am facing is that the splash screen appe ...

What is the best way to align a jQuery Cycle 2 Slider in the middle of the

Having some trouble centering a jQuery Cycle 2 Slider on my page. You can see the slider here. I've attempted multiple methods to center it, but none have been successful. Check out the HTML code: <div class="slider"> <div id=outside> ...

The drop-down menu is misaligned from its designated position underneath the title

Trying to incorporate a dropdown menu into my website, I am structuring the HTML as follows: <ul class="topnav"> <li> SECTION TITLE <ul class="subnav"> <li>One</li> <li>Two</li> ...

problem specifically occurring on tablets with fixed positioning

Have you checked out the site I'm referring to here? An unusual issue seems to be occurring specifically on tablets. We implemented the scroll to fixed jQuery plugin to fix the position of the sidebar after scrolling, which works perfectly on all de ...

When utilizing ng-content alongside *ngtemplateOutlet, the content does not appear visible within the DOM

I'm working with three Angular components - a base component and two child components (child1 and child2). The structures are as follows: child1.component.html <ng-template #child1Template> <div> <h1>CHILD 1</h1> ...

Exploring the use of React material-ui Drawer list to render various components onClick in your application

Working on designing a Dashboard with the React material-ui package involves implementing an App bar and a Drawer containing a List of various items. The objective is to render the corresponding component inside the "main" tag of the Drawer upon clicking a ...

Is there a way to include an optional backslash in URLs using the .htaccess file without leading browsers to believe I am navigating to a subfolder?

As I update my php pages with the .htaccess file, I am facing an issue where the pages do not load properly when an optional backslash ("/") is included in the URLs. One possible solution is to use absolute URLs instead of relative ones so that CSS and J ...

How to use jQuery to extract a particular text from an anchor tag

If I want to choose a specific anchor text and make changes to it, I can do so by targeting anchors with a certain href attribute. For example, on a page with multiple unordered lists, each containing different links: <ul> <li><a href="v ...

What is preventing me from clicking on the left side of the link on this CSS flip card while using Chrome browser?

When attempting to click the left side of the link on the back of this flip card in Chrome, it does not respond. However, hovering over the right side allows interaction with the link: /* Vendor prefixed by https://autoprefixer.github.io */ .card { ...

Traversing through Object consisting of dual arrays within VueJS

Currently, I am working on a chat application built in VueJS and encountering an issue when attempting to display messages along with their respective timestamps. The challenge arises from the need to iterate through an object that contains two arrays: one ...

Incorporating groovy script into HTML: Is it possible, akin to embedding JavaScript

Can groovy script be embedded in HTML similar to JavaScript? I am interested in creating an onclick button event that utilizes groovy script instead of JavaScript. Thank you. ...

Is it possible to divide a column in an HTML table into two separate

I am currently working with an array of elements that I need to iterate over. For each element, I create a <td></td> tag. When dealing with 10 elements, it results in a table with one column and 10 rows. Is there a method, using either HTML o ...

What is the reason behind using <script> tag for scripts, instead of using <style> tag for external CSS files?

A family member who is new to Web Development posed an interesting question to me. Why do we use <script src="min.js"></script> and <link rel="stylesheet" href="min.css">? Why not simply use <style href="min.css"></style>? Wh ...

What is the best way to display a header element in front of an article element?

I'm struggling with making my header element sticky and appear in front of my article. Modifying the z-index hasn't given me the desired result so far. Is the z-index ineffective when dealing with floating elements? Or is there a workaround to m ...

Creating visually appealing layouts with CSS floats and divs while ensuring responsiveness

As I work on bringing my vision to life, I'm experimenting with a mix of floats and divs, along with using a responsive image for the background and text. There's quite a bit involved in this process. 1. To start off, check out this example with ...

Tips for designing an intricate Bootstrap 4 layout

I'm having trouble positioning box 7 below box 6, can someone help me with this? Here is the code for reference. To test it on your machine, make sure to include Bootstrap 4 from a CDN: https://www.w3schools.com/bootstrap4/bootstrap_get_started.asp ...

Exploring hash retrieval in Perl templates

What is the method for accessing variables in a hash when using Perl's HTML::Template module? As I construct the following hash in my Perl code: # Implementing success/error flash messages if ($query->param("submit")) { $template->param( ...

Challenge with adjusting opacity of background when hovering over a box

I've encountered an issue with the background transparency in the following demo. For some reason, it's not working properly. .figure .caption-mask:hover { background: rgba(0, 0, 0, 0.0); } I'm attempting to remove the opacity f ...