Place the block at the bottom without using absolute positioning

In the design, there is a block that should be positioned absolutely on desktop screens. However, for mobile screens, it needs to adapt so that elements do not overlap.

.wrapper {
    position: relative;
    border: 2px solid black;
    border-radius: 10px;
    padding: 20px 0 0 20px;
    height: 250px;
}

.text {
    max-width: 300px;
    margin-bottom: 20px;
}

.button {
    width: 50px;
    border: 1px solid black;
    border-radius: 10px;
    cursor: pointer;
    padding: 10px 15px;
    margin-bottom: 15px;
}

.block {
    position: absolute;
    width: 200px;
    background: purple;
    bottom: 0;
    right: 0;
    z-index: 2;
    padding: 10px 15px;
 }
 
 @media only screen and (max-width: 767px) {
  .block-wrapper {
       display: flex;
       justify-content: flex-end;
  }
  
  .block {
      position: relative;
  }
 }
<div class="wrapper">
  <div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
  <div class="button">Button</div>
  <div class="block-wrapper">
    <div class="block">
      <div class="block-name">Hector</div>
      <div class="block-position">Developer</div>
    </div>
  </div>
</div>

If the block must always have an absolute position, then with long text and a small screen size, it may overlap with the button.

Therefore, for smaller screens, I need to adjust the layout so that the elements stack vertically.

I've used flex display to push this block to the right, but how can I ensure it remains at the end of the entire wrapper?

Answer №1

Insert the following code snippet within your media query:

@media only screen and (max-width: 767px)
.

.container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

Can you show me a way to use jQuery to delete several href links using their IDs at once?

Currently facing a challenge with removing multiple href links that share the same ID. Here is a snippet of my code: $('.delblk').click(function(e) { e.preventDefault(); var id = $(this).attr('id').substr(7); ...

Is there a way to adjust the positioning of an image within a <div> element?

I'm attempting to vertically align an image within a horizontal menu bar. My goal is to adjust the padding/margin of the image using inline CSS. However, I've noticed that when I add margin-top or padding-top, it affects the positioning of all m ...

Having trouble inserting a hyperlink using the <a> element into a list item (<li>) tag

I have developed a partial view that displays a menu using an unordered list. I am trying to add links to each list item but regardless of whether I use relative paths or absolute paths, the linked pages are not opening and I keep seeing a 404 error in my ...

Triggering div visibility based on jQuery select change event

I am currently working on a form feature that involves showing a div when a specific option in a select element is chosen, and hiding the div when the option is not selected. Here is the current structure of my markup: Here is the current HTML markup I ha ...

Submitting a HTML form with a select element that will pass comma-separated values in the URL query

My HTML form includes a dropdown menu. <form method="get"> <select name="category[]" multiple class="form-control"> <option value="1">First Value</option> <option value= ...

The Material UI month picker interface is not displaying correctly

When trying to implement the code snippet below, <MonthPicker/> I am encountering issues with the UI of the month picker both on the website and at times. https://i.stack.imgur.com/EKsYA.png It seems like the month picker is being utilized in a di ...

Challenges regarding the CSS styling of the ui bootstrap modal and its compatibility with

Currently, I am in the process of developing a webpage utilizing angularjs and ui bootstrap to generate modals. However, as I attempt to print just the modal using javascript, I have encountered an issue with my CSS. It seems that due to potential formatti ...

Retrieving HTML tag content using Javascript

I'm searching for a JavaScript code that can scan all the HTML files in my main directory and subfolders to extract content located within a specific tag, like this: <div id="content"> !!this content!! </div> Additionally, it should only ...

execute numerous Jssor Caption instances simultaneously

I have a Jssor slider and I want to create an animation for the first slide. My goal is to make two images come from the sides and merge in the center. I tried using a div for each image with a caption, and it works well. However, the second image starts ...

Adding a sibling inline can be accomplished by simply using the "+"

$("#sibling").prepend("#sibling2") <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="sibling">First sibling</div> <div>Another component</div> <div id="sibling2">Seco ...

Enhance the appearance of a button in Rails by incorporating custom styles or images

I am currently working with Rails and I am curious if there are any simple ways to enhance the appearance of the button_to control. Is it possible to style the <%= submit_tag 'Log in' %> or <%= button_to "Show Me", {:controller => ...

Building a website using Bootstrap: A step-by-step guide

Wondering how I can incorporate all the cool Bootstrap components into a webpage. Is there a tool that offers live preview? Back in the day (web 1.0), Dreamweaver was my go-to for creating HTML and basic CSS, but what are some current tools where I can si ...

Scroll up and down to witness the enchanting interplay of fading in and out

Looking to expand upon the solution given in this response. The existing code effectively fades in an element while scrolling down and fades out an image when scrolling up; however, it lacks the functionality to fade out when scrolling down. I am aiming ...

Concluding remarks can be found at the end of the article

Is there a way to keep text aligned next to an image without it dropping down and disrupting the layout of the article? * { margin: 0; box-sizing: border-box; } * a:link { text-decoration: none; ...

Utilizing a CSS/HTML div grid to mirror a 2D array in JavaScript

Currently, I am working on a personal project that involves creating a grid of divs in HTML corresponding to a 2D array in JavaScript. However, I am uncertain about the most effective way to accomplish this task. Specifically, what I aim to achieve is tha ...

Stop flash notifications from sliding below the container

Creating a web application using Bootstrap 4, I implemented user notifications with alerts according to the documentation found here. However, I encountered an issue where the content below the alert shifts when the alert is displayed and then shifts back ...

The issue of Markdown not being recognized inside nested divs

As I develop a Bootstrap-themed website with Jekyll, I've encountered an issue when formatting content in markdown. My goal is to organize my posts using Bootstrap grids like this: <div class="row"> <div class="col col-md-6" markdown="1"&g ...

How can you apply margin to an element within a column in Bootstrap 4?

Within a column, I have several span elements: <div class="container-fluid"> <div class="row"> <div class="col"> <span class="myClass">some text</span> <span class="myClass">some text</span> ...

Changing the color of the font in your Bootstrap Navbar 3.4.1

Hello, I'm looking to customize the font color of the links in my Bootstrap navbar. I've attempted to apply specific classes to the navbar as suggested in related posts, but so far I've only been successful in changing the font of the navbar ...

Looking to access files from the Android asset folder within an HTML document?

I'm currently developing an HTML-based app for Android. I've successfully displayed the HTML file using this code: "file:///android_asset/index.html" Now, my goal is to load local image files or fonts within that HTML file from the assets folder ...