Create responsive div elements within a container

I am working on a layout that consists of an outer div with 5 inner divs nested within it.

------------------------------------
| <div title>                       |   

|             <div value><div unit> |

|                      <div subvalue|

|                         <div date>|

The challenge I am facing is making the outer div responsive while ensuring that the elements inside maintain their position. The title should be on the left, the value in the center along with its unit, and the remaining two elements should stay at the bottom right. However, achieving this has proven to be difficult for me as a developer:

CSS Code:

.container{
    border: 1px solid #57c0e8;
    background-color: white;
    cursor: pointer;
    height: auto;
    width: auto;
    border-radius: 10px;
}

.title {
    color:grey;
    font-size: 0.8em;
    margin-left:2%;
}

.valueAndUnit {
    text-align: center;
    display: block;  
}

.value{
    margin-top: 3%;
    min-height:25px;
    font-size: 2.1em;
    display: inline-block;
}

.unit {
    display: inline-block;
}

.subValue {
    text-align: right;
    min-height:25px;
    font-size:1em;
}   

.date {
    min-height:25px;
    color:lightslategrey;
    text-align: right;
    font-size: 1em;
}

.subValueAndDate {
    margin-right: 6%;
}

@media only screen and (max-width: 770px) {

    .title { 
       font-size: 1.3vw; 
    }
    .value{
        font-size: 3.1vw;
    }

 .unit{
     font-size:2vw;
 }

 .subValue{
     font-size:2.5vw;
 }

 }

This is what the container looks like:

https://i.sstatic.net/PQSZD.png

HTML:

<div className={styles.container}>
            <div className={styles.title}>
            {title}
            </div>
            <div className={styles.valueAndUnit} style={style}>
            <div className={styles.value}>
            {value}
            </div>
            <div className={styles.unit}>
            {unit}
            </div>
            </div>
            <div className={styles.subValueAndDate}>
            <div className={styles.subValue}>
            {subValue}
            </div>
            <div className={styles.date}>
            {date}
            </div>
            </div>
        </div>

Answer №1

If you're using Bootstrap, take advantage of the Grid system it offers and make some adjustments with flexbox classes to customize your layout.

HTML:

<div class="outer-div">
    <div class="row d-flex">
        <div class="col-6 text-left">
            yes
        </div>
    </div>
    <div class="row d-flex">
        <div class="col-12 text-center">
            1111 unit
        </div>
    </div>
    <div class="row d-flex flex-row-reverse">
        <div class="col-6 text-right">
            1234
        </div>
    </div>
    <div class="row d-flex flex-row-reverse">
        <div class="col-10 text-right">
            05/14/3030 4:12
        </div>
    </div>
</div>

CSS:

.outer-div {
    border: solid green 1px;
    border-radius: 5px;
    width: 35%;
    margin-left: 30%;
    padding-left: 1%;
    padding-right: 1%;
    padding-bottom: 1%;
}

Example Snippet:

.outer-div {
border: solid green 1px;
border-radius: 5px;
width: 35%;
margin-left: 30%;
padding-left: 1%;
padding-right: 1%;
padding-bottom: 1%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="outer-div">
<div class="row d-flex">
<div class="col-6 text-left">
yes
</div>
</div>
<div class="row d-flex">
<div class="col-12 text-center">
1111 unit
</div>
</div>
<div class="row d-flex flex-row-reverse">
<div class="col-6 text-right">
1234
</div>
</div>
<div class="row d-flex flex-row-reverse">
<div class="col-10 text-right">
05/14/3030 4:12
</div>
</div>
</div>

Check out a Codepen example here.

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

Is it possible that using vim omni-complete will remove the word that I had previously selected

When writing HTML with gvim, I find it frustrating that the omni-complete feature always deletes my previous word and even my previously selected ones. For example, let's say I'm in the middle of writing the following code**('_' indica ...

Prevent the text within the textarea from wrapping onto the next line

My challenge involves a textarea where text overflows onto the next line when it exceeds the maximum characters. However, I want the text to continue on the same line with a scroll bar for better visibility. Here's an illustration: text here flows on ...

Guide to Generating a Dynamic HTML Menu

Is "dynamically" the correct term for what I'm trying to achieve? * I am looking to have a basic one-level menu appear on every one of the 80 pages on my website. The menu items will be updated regularly - some added, some removed, and so on. What is ...

Unable to select selectbox in the bottom section of Safari browser

There seems to be an issue with the selectbox being unselectable at the lower part in Safari. It's difficult to pinpoint the exact problem in the code. You can see the issue on the country selectbox by visiting this website: <span> <sp ...

Guide on extracting data from a JavaScript table using Python

Looking to extract information from a table on this page: . There are a total of 18 pages, but the url remains constant for each page. My usual method involves using BeautifulSoup to scrape data from HTML pages. However, in this case, the required data is ...

Tips for deactivating dropdown values based on the selection of another dropdown

There are two dropdown menus known as minimum and maximum, each containing numbers from 1 to 25. If a value is selected from the minimum dropdown (e.g. 4), the maximum dropdown should only allow values that are equal to or greater than the selected value ...

What is the best way to align the 5th and 6th list items to the left using CSS?

I am experimenting with Bootstrap to create a customized navbar. I am encountering difficulties in aligning the login and logout buttons to the right. Is there a way to achieve this? I have included my HTML and CSS code below: HTML code: <body> &l ...

Tips for creating a hovering bar underneath your links

I'm currently working on designing a stylish navigation bar using CSS, and I have a specific feature in mind. When a user hovers over a link in the navigation bar, I want a colored bar to appear under a different link. Essentially, I need the backgrou ...

The term "Highcharts does not exist"

I'm encountering an issue with my code: <html> <head> <title><%=sAtaskaitaTitle%></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name=vs_targetSchem ...

Placing two images next to each other with accompanying captions

Currently working on developing a webpage, I am aiming to have two images in each row with captions positioned beneath them. The images are already configured as follows, I just require the captions: <div class = "container"> <img class = "pi ...

Accessing variables within a frame using JavaScript.Is there a way to access variables within

I am having trouble accessing a Frame that is included within a frameset. The structure looks like this: IFRAME \ FRAMESET \FRAMESET \ FRAME I have been struggling to find a solution, I can only access the iframe ...

Interactive elements embedded within an image - digital board game

I'm currently working on integrating a board game into React, and I am facing some difficulties in figuring out how to translate the board squares shown in the image into data. Is there a method through which I can assign unique IDs to each square di ...

Tips on moving information from one form to another after referencing the original page using Javascript and HTML

Imagine this scenario: A page with three text fields, each with default values. There is also a hyperlink that performs a database lookup and returns parameters to the same page where the hyperlink was clicked. The goal is for the text boxes to be automa ...

Struggling to extract information from the front-end by utilizing Node.js/Express with body-parser and encountering difficulties

Attempting to transfer data from the frontend to a node server utilizing body-parser Shown below is the frontend code: <body> <h1>Donate!</h1> <h2>Select A tier</h2> <label for="donate-tier-select">Suggested Sp ...

Optical imaging-guided Page Division

Looking for guidance on implementing a program that can perform "Vision-based Page Segmentation" with practical information rather than just theoretical knowledge. I prefer using JS (jQuery) and PHP for this project. After reading the article on VIPS: a ...

In the game of rock paper scissors, the icons become unclickable once you achieve a score of 5

I have created a Rock Paper Scissors game where the score resets if either the user or computer reaches 5 points, but I want to prevent any further play after hitting 5. Currently, the game displays a message and reloads after 5 seconds, during which tim ...

Ways to showcase INPUT TYPE when making a Selection?

I've been struggling with a simple issue and despite trying multiple solutions, I can't seem to get it right. I have a form where I'm using the <select> tag with two options: coo and uh. What I want is for an additional input type fiel ...

Prevent users from saving changes made to dropdown menu values (as well as other user-inputted content) using Inspect Element on the website before it

Recently, I started testing my website for bugs and stumbled upon a major issue that caught me by surprise. I never realized that changes made with Firebug or similar plugins on websites could actually be saved and implemented. Despite my efforts to preve ...

The <div> tag fails to comply with the Display: inline CSS property

I need help with a web development issue as I am new to this field. My problem is that I am trying to display three divs next to each other, but despite applying display:inline-block to them, they still appear stacked on top of each other instead of side b ...

What is the best way to ensure that the input search bar, microphone icon, and two small boxes adapt to different screen

Upon submitting my exercise for The Odin Project, I was under the impression that everything looked perfectly aligned and centered on my MacBook Pro 15-inch screen. However, when I viewed the completed webpage on a larger computer screen at work, I noticed ...