management in the same row or in the following row fashion

Looking to achieve a specific behavior for a label and control:

  • If the screen width is less than X, the label and control should be on different rows with the control expanding to full width.
  • If the width is equal to or greater than X, the label and control should be in the same row with the control aligned right. Additionally, text and control should be vertically centered:

Code snippet (test the jsFiddle):

HTML:

<div class="container">
    <div class="dispInlineLabel" >
        <label for="rb_geschlecht-2a">Gender</label>
    </div>
    <div class="dispInline">
        <fieldset  data-role="controlgroup" data-type="horizontal">                     
            <input type="radio" name="rb_gender" id="rb_gender-2a" value="0">
            <label for="rb_gender-2a">female</label>
            <input type="radio" name="rb_gender" id="rb_gender-2b" value="1">
            <label for="rb_gender-2b">male</label>
        </fieldset>
    </div>
    <div class="clearFloats"></div>

    <div class="dispInlineLabel" >
        <label for="ti_dob">Date of Birth</label>
    </div>
    <div class="dispInline">       
        <input name="ti_dob" id="ti_dob" style="text-align: right" type="date"  data-theme="d">
    </div>
    <div class="clearFloats"></div>                                     
</div>  

CSS:

.dispInline, .dispInlineLabel{
    display: inline-block;
    border-bottom-width:0;
}
.dispInlineLabel{
    min-width: 120px;
}
.dispInline{
    float:right;
}
.clearFloats{
    clear:both;
}

While the layout appears as desired, facing issues:

  • In the case where control is on a separate row, it does not expand fully.
  • Alignment of text and control is not centered when on the same row.

Could someone provide guidance on resolving these issues?

Answer №1

Implementing media queries in your CSS:

@media all and (max-width: 500px){
  .dispInline{
      width:100%;
    }
}

View example on jsFiddle

More information

Update:

To vertically align elements, ensure rows have the same height and set line height accordingly:

CSS Code:

.dispInlineLabel{
    min-width: 120px;
    height:55px;
}
.dispInlineLabel label{
    line-height:55px;
}
.dispInline{
    float:right;
    height:55px;
}

Updated version on jsFiddle

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

Steps for launching an application through a hyperlink to appear on the foreground rather than the background

For my project, I am utilizing "a href" to open a windows application. <a href={`enter app here`}> //Similar concept as mailto The issue I am facing is that it opens the application in the background rather than bringing it to the foreground. Esse ...

Restrictions on the utilization of Google Maps Geocoding API

Currently utilizing Google's Maps Geocoding API, with a daily limit of 2500 requests as stated in the documentation. Is there a service available to track the number of requests made or remaining? While I understand this information can be found in G ...

The div element is supposed to only be visible when the user scrolls down and then back up, rather than when the

Looking for some help with a Javascript issue on my website (http://www.pjsmusic.com). I need a div of 200px to appear when the user scrolls down 40px. I have tried using the following Javascript code: $(document).scroll(function() { $('#jerkBox& ...

What is the best way to incorporate data from my Input field into my Vue.JS application's existing data structure

Struggling with integrating new users into my personal project, particularly in passing input values (userName and userAge) to the parent element for addition to playersData. Here is a sample code snippet from the child component: `<template> <d ...

Interactive Click Actions on Rotated Divs

Does anyone know why, when clicking on the back side of a div that has been rotated with rotateY, the clicks pass through to the next div inside the body tag instead of registering on the intended div? And is there a way to fix this issue? You can view th ...

Is it possible to customize the name of the app separately from the activity label using the intent-filter?

I recently developed an app that consists of four different activities. One of these activities has an intent-filter set on it so that it is the first one displayed to the user upon opening the app. This activity is labeled "Add expense". However, I notic ...

Using Flexbox for dynamic-height items with column wrapping

Struggling to create a dynamic layout that adapts differently for mobile and desktop devices? The goal is to have items sorted based on screen size, with the layout changing accordingly. Check out the main objective below, with a mobile layout on the left ...

Tips for triggering the .click() function upon returning to index.html after visiting a different page

I'm in the process of creating a portfolio website where the index.html page features a sliding navigation bar that displays a collection of projects. Each project is linked to a separate work.html page. I would like the sliding nav to automatically o ...

Step-by-step guide to implementing a floating action button on the bottom-right corner of a screen using Material-UI in a React application

I have been attempting to place the FloatingActionButton on the bottom right corner of the screen. To achieve this, I am utilizing the following library: http://www.material-ui.com/#/components/floating-action-button import React, { Component } from "reac ...

Tips for clearing input fields in React.js without using an empty string

Is there a way to reset the input field in this specific scenario? const [username, setUsername] = useState({ username: "", usernameError: "" }); const handleUsername = (inputUsername) => { if (inputUsername.length > ...

tips on launching a pre-existing react native project

Trying to run a project downloaded from someone else can be quite challenging. I encountered some issues where the project just wouldn't start, and now I'm completely stuck. Can anyone help me out? https://github.com/sunlight3d/react_native_v0.4 ...

Is there a way to efficiently create an ng-repeat for multiple divs?

I am looking to iterate through a collection of divs, as mentioned below. Each object in the list will have content-data and a link to an image. The code provided shows individual entries for each list item, but I would like to retrieve it from the angular ...

CSS grid tracks remain fixed in size while other tracks expand

Why won't the grid track cells dynamically shrink when other cells are enlarged in the following code? In this snippet, hovering over any track section causes that cell to grow to 75% of the viewpoint. However, instead of the other sections shrinking ...

Guide on generating a video thumbnail using JavaScript Application

Searching for a way to easily create a thumbnail from a video for uploading alongside the video itself to a server? I've been looking for JavaScript libraries to simplify the process without much luck. The scenario involves the user selecting a video ...

What is the best way to bring the global stylesheet into a Vue component?

Embarking on my first VueJS project, I decided to create a global stylesheet to maintain consistent styles across different components. After installing the SCSS loader and setting up my stylesheets, I encountered an issue. $mainFont: 'PoppinsRegular, ...

React-Native: Image picker faces challenges due to updated Google MEDIA policy restrictions

Currently, I am utilizing the react-native-image-picker library for managing media in my react-native project. However, due to Google's new policy, this library is no longer compliant. According to Google: "For a more privacy-preserving experience f ...

How come padding-bottom isn't effective in increasing the position of an element?

My goal is to adjust the position of the orange plus sign (located in the lower right corner of the screen) so that it aligns better with the other icons, directly below them. I've tried using padding-bottom, but it doesn't seem to work, while pa ...

Bespoke animated angular material tabs

Having an issue with Angular Material tabs. I have managed to remove the "slide" effect, but I can't figure out how to modify or remove the black effect behind my tab. Can anyone offer some assistance? black effect 1 black effect 2 Here is a snippe ...

There is zero gutter in Bootstrap

Is it possible to use the bootstrap grid system without any gutters? I want to have 3 columns in one row like this: http://prntscr.com/6gpmhm. I have shared the markup for the CSS I am using, which is the default CSS of the framework. <section class ...

Trouble with margins on tr elements and borders in CSS and HTML

Here are my current findings: http://jsfiddle.net/62hKs/2/ What I desire to achieve: 1) Create a 15px margin between the two red boxes displayed 2) Modify the appearance of the 4 boxes so they resemble only 2, by eliminating the middle red line caused ...