Attempting to align two columns side by side, only to find them overlapping when the viewport is reduced in size

Currently, I am in the process of designing a profile page for a website that is under development. The challenge I'm facing is ensuring that when the page is viewed on a larger screen (anything above a tablet size), two cards are displayed side by side. However, due to the buttons within the cards shifting out of place when the page is resized, I have set a minimum width.

To maintain consistency and fill up space, there are empty columns on either side of the page.

For large desktop screens, everything aligns perfectly with the padding and two adjacent cards. But as the screen size shrinks below 1175px, the cards start overlapping each other. Instead of this behavior, I want the right card to move below the left one, which contains the profile information.

I have already configured it not to display on mobile devices, but I also need it to show with both columns stacked one on top of the other for mobile viewing as well.

Below is the HTML CODE:

<div class="container-fluid pcontainer">
<div class="row">
    <div class="col-2 d-none d-lg-block">
    test
    </div>

    <div class="col-4 d-none d-md-block">
        <div class="card pc mw-100">
          <div class="card-title">
          <img class="pp card-img-top img-fluid rounded-circle" src="img/pp.jpg" alt="Card image cap">
          <h4 class="pt card-title text-left text-justify"> Ryan Edwards </h4>
          <button type="button" class="btn btn-sm btnp btn-outline-info">Add Friend</button>
          <button type="button" class="btn btn-sm btn-outline-success">Message</button>
          </div>
          <div class="card-body">
            <h3> My Biography: </h3>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
          </div>
        </div>
    </div>

    <div class="col-4 d-none d-md-block">
        <div class="card pc mw-100">
          <div class="card-title">
          <img class="pp card-img-top img-fluid rounded-circle" src="img/pp.jpg" alt="Card image cap">
          <h4 class="pt card-title text-left text-justify"> Ryan Edwards </h4>
          <button type="button" class="btn btn-sm btnp btn-outline-info">Add Friend</button>
          <button type="button" class="btn btn-sm btn-outline-success">Message</button>
          </div>
          <div class="card-body">
            <h3> My Biography: </h3>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
          </div>
        </div>
    </div>

    <div class="col-2 d-none d-lg-block">
    test
    </div>
</div>

Here is the corresponding CSS:

.pc {
margin: 0px;
min-width:390px;       
width: auto !important;  
width:390px;            

}

.pp {
max-width: 125px;
width: 125px;
max-height: 125px;
height: 125px;
margin-top: 40px;
margin-right: 40px;
float: right;

}

.pt {
margin-top: 50px;
margin-left: 50px;
}

.btnp {
margin-left: 50px;
}

.btn {
padding-top: 2px;
padding-bottom: 2px;
padding-left: 8px;
padding-right: 8px;
}

Answer №1

Have you considered using a script tag to achieve this? You have the option to specify the distance and even add a new class alongside your current one. It's uncertain whether this will be effective for your situation :)

$(document).ready(() => {
        $(document).scroll(() => {
            if ($('.yourclass').offset().top - $(window).scrollTop() <= 25) {

                if ($(window).scrollTop() < 400) {
                    $('.yourclass').removeClass('currentyclass');
                } else {
                    $('.yourclass').addClass('newestclass');

                }
            }


        })

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

How can I line up the bootstrap datepicker with a bootstrap column?

I currently have Bootstrap 3.3.7 and a bootstrap datepicker version 1.6.4 integrated into my project. However, I am facing an issue where the datepicker does not fill up the designated column within a div with the class col-md-6. Here is the HTML code sni ...

flask - Transfer data from Python to HTML using a database

I have written code to fetch data from a database and now I want to display it in an HTML format. Below is the code snippet from app.py @app.route('/news') def news(): import pymysql import re host='localhost' user = ...

Arranging divs using the float property

I am currently working on a Django project where I have a large list of dictionaries in the view: 'description': [ { 'name': 'Parts', 'good': ['Engine', 'Transmission&a ...

Easily accessible button and span located on the right side

One issue I'm facing is that the button and span are not aligned on the same line. Is there a way to resolve this? <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/c ...

Trouble with canvas setLineDash and lineDashOffset persisting in iOS/Safari?

Check out the fiddle linked here: http://jsfiddle.net/mYdm9/4/ When I execute the following code on my PC: ctx.lineWidth=20; ctx.setLineDash([20,30]); ctx.lineDashOffset=10; ctx.beginPath(); ctx.moveTo(150,150); ctx.lineTo(240,240); ctx.lineTo(180,40); ...

Is it better to use on click instead of href for this task?

I have a limited number of items in my navigation bar, both vertically and horizontally. Each item corresponds to a different page. I've come across several articles discussing href attributes and the various opinions on their usage, particularly in H ...

Using javascript to overlay and position many images over another image

I've searched extensively but haven't been able to find any relevant answers here. Currently, I am developing a hockey scoring chance tracker. My goal is to display an image of the hockey ice where users can click to mark their input. Each click ...

Utilize JavaScript and jQuery to extract the selected text's context from a webpage

I'm looking to extract the contextual information surrounding a selected text on a web page, specifically the 25 words before and after it. I've tried using JavaScript and jQuery with the following code snippet but unfortunately, it doesn't ...

Tips for stopping a click from going through a fixed element to the one in the background

My website features a fixed positioned header with a search box, overlaying content below it (thanks to the higher z-index). When I click on the search box, an event handler is triggered. However, the click response also passes through the header to the ...

Bars of varying heights (Google Chart)

I have incorporated a Google chart within a mat-grid-tile. In this setup, one column displays a value of 50, while the other showcases a value of 30. These particular values are sourced from myService and are accurate. Although when I hover over the bars i ...

Tips for addressing the issue of line height causing padding at the bottom of divs

I am facing an issue on my website where I need to create <div> elements that expand to display images and a title. My current approach involves a structure like this: <div class="thumb"> <img src="image_url"/> <div id="title" ...

Issues with functionality of Tumblr share button

I've been attempting to integrate a Tumblr share button on my online store, but I'm having trouble getting the Tumblr Share Button (see here) to function properly. My goal is to allow users to share a customized picture of a product and include ...

Guide on adding a circle shape in the intersection table

Is it possible to add a circular shape in the intersection table, or should an image (table) be utilized from the layout? ...

Ways to generate a fixed-length string without relying on the rand() function

Is it possible to create a fixed length string without relying on the rand() function? I currently have a method for generating random strings, but I would prefer not to use the rand() function function generateRandomString($length =6) { $characters ...

What is the process for integrating a personalized font into the <head> section of the ConvertTo-HTML?

I created a script to generate an HTML file containing information about the services on a computer, along with some additional styling. $a = "<style>" $a = $a + "BODY{background-color:peachpuff;}" $a = $a + "TABLE{border-width: 1px;border-style: so ...

What is causing the content to overflow outside of the navbar on smaller screens or mobile devices?

/* *{ font-family: sans-serif; box-sizing: border-box; margin: 0; padding: 0; overflow-x: hidden; } */ .main { min-height: calc(100vh - 10rem); display: grid; place-items: center; } p { font-size: 4rem; line-height: 1.6; } nav ...

The resizable function in jQuery is not functioning as expected

Within my project, the initial page includes the following code snippet: html <div id="box"> <div id="header"> <span id="title"></span> <span id="button">X</span> </div> <div id="text"> </div> ...

There seems to be an issue with the functionality of Bootstrap 4

I'm having trouble incorporating bootstrap4 into my website because the navbar feature is not functioning properly. It seems like all the attributes are being crossed out in the CSS file. Can someone assist me with this? Here is the result: https://i ...

What is the best way to utilize ajax for submitting and fetching content?

It's pretty obvious that I'm a complete novice when it comes to JavaScript and jQuery, but I have a query regarding ajax requests. Here's what I'm trying to achieve but struggling with: I've defined a content.append('<di ...

Is it possible for an object hidden in the DOM using jQuery to magically reappear when you click the back button or use the bfc

Is there a way to prevent a box from reappearing when using the back button on a webpage? On my website, there is a box that shows up on the first visit. However, when navigating using the back buttons on the site or the browser back button, the box appea ...