In mobile view, the grid text should be positioned on top of the input field

Created a basic grid layout with input fields. Everything looks fine on the PC, but on mobile devices, long text causes the input field to be positioned below the text. However, when the text is short like Lor, it appears next to the input field... I want the text to go over the input and maintain the same structure.

    body {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
      font-family: sans-serif;
    }
    .container {
      display: grid;
      grid-template-columns: 1fr 1fr;
      
      width: 1100px;
      max-width: 100%;
      height: 200px;
      margin: 0 auto;
    }

  input {
    border: none;
    border-bottom: 1px solid #000;
    width: 250px;
  }
  p{
    font-weight: bold;
    text-align: right;
  }
  h4{
    background-color: #ecf0f1;
    padding: .5rem;
  }
  @media (max-width: 500px) {
    .container{
      display: grid;
      grid-template-columns: 1fr;
      
    } 
    p{
      text-align: center;
    }
    input {
      padding-left: 2rem;
      
      
    }
<div class="container">
        <div class="one">
          <h4>Heading</h4>
         <p>Lorem ipsum lorem ipsum<input type="text" value="[[Lorem]]"></p>
         <p>Lorem ipsum lorem ipsum<input type="text" value="[[Lorem]]"></p>
         <p>Lor<input type="text" value="[[Lorem]]"></p>

        </div>
        <div class="two"></div>
        <div class="one">
          <h4>Heading</h4>
         <p>Lorem ipsum lorem ipsum<input type="text" value="[[Lorem]]"></p>
         <p>Lorem ipsum lorem ipsum<input type="text" value="[[Lorem]]"></p>
         <p>Lor<input type="text" value="[[Lorem]]"></p>

        </div>
        <div class="two"></div>
        </div>
      </div>

Answer №1

Consider using the white-space CSS property as outlined below:

    body {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
      font-family: sans-serif;
    }
    .container {
      display: grid;
      grid-template-columns: 1fr 1fr;
      
      width: 1100px;
      max-width: 100%;
      height: 200px;
      margin: 0 auto;
    }

  input {
    border: none;
    border-bottom: 1px solid #000;
    width: 250px;
  }
  p{
    font-weight: bold;
    text-align: right;
    white-space: pre-line;
  }
  h4{
    background-color: #ecf0f1;
    padding: .5rem;
  }
  @media (max-width: 500px) {
    .container{
      display: grid;
      grid-template-columns: 1fr;
      
    } 
    p{
      text-align: center;
    white-space: pre-line;
    }
    input {
      padding-left: 2rem;
      
      
    }
<div class="container">
        <div class="one">
          <h4>Heading</h4>
         <p>Lorem ipsum lorem ipsum
         <input type="text" value="[[Lorem]]"></p>
         <p>Lorem ipsum lorem ipsum
         <input type="text" value="[[Lorem]]"></p>
         <p>Lor
         <input type="text" value="[[Lorem]]"></p>

        </div>
        <div class="two"></div>
        <div class="one">
          <h4>Heading</h4>
         <p>Lorem ipsum lorem ipsum
         <input type="text" value="[[Lorem]]"></p>
         <p>Lorem ipsum lorem ipsum
         <input type="text" value="[[Lorem]]"></p>
         <p>Lor
         <input type="text" value="[[Lorem]]"></p>

        </div>
        <div class="two"></div>
        </div>
      </div>

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

Simple: What is causing the error message "TypeError: 'int' object is not callable" to appear? (refer to line 24 in the code)

I'm struggling with a coding issue and can't seem to find a solution. Would appreciate it if someone could provide some guidance on what's going wrong. Essentially, this script is designed to fetch the HTML content of a URL, extract specific ...

Colorbox scalePhotos function malfunctioning

The scalePhotos option in Colorbox does not seem to be working correctly for me. I have tried various methods to set it, including initializing Colorbox using the following code snippet right before the closing </body> tag in my HTML: jQuery('a ...

a graphical representation of data organized in tabular form using

I am trying to develop a game where I need to generate a map using PHP. The goal is to create 100 table boxes in a specific pattern, but so far my attempts have not been successful... $field = 100; echo "<table border='3px' dir='ltr&apos ...

Is there a way to eliminate the .html extension from the end of URLs for web pages?

Can someone provide guidance on how to eliminate the .html extensions from file names? Specifically, I noticed this feature on the site tekmillion.com. Your assistance is greatly appreciated. Thank you! ...

Implementing a password toggle feature on a form that extends Django's default Authentication Form

Incorporating a password toggle feature has become quite the challenge as I extend Django's AuthenticationForm to create my UserLoginForm. Attempting to implement this feature has proven difficult, especially since I have been unable to make use of th ...

The Issue of Horizontal Scrolling - None of the elements are out of

I am facing an issue with an unwanted horizontal scroll on my website and I can't seem to identify the cause. The header of my site is quite simple, utilizing display: flex, justify-content: center, marin-top: 5vh, along with some padding on the logo ...

Vertical centering menu adjustment

Can anyone help me with centering an image on my website? I've tried the following code: top: 50%; -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%); You can see what's happening on my site here: ...

An uncomplicated vessel design

Having experience in mobile programming, I am accustomed to creating a parent hidden view and positioning subviews inside it. Now, I am trying to replicate the same functionality using HTML/CSS/Bootstrap. Let's say I have already laid out a cover bac ...

Changing the content of a DOM element containing nested elements using JavaScript/jQuery

Need some help with a DOM element that looks like this: <span>text</span> <b>some more text</b> even more text here <div>maybe some text here</div> How can I replace text with candy to achieve this result: <span> ...

Having trouble with enter key input not triggering?

I have scoured various resources for answers to my query, including Stackoverflow. Unfortunately, none of the posts I came across have helped me resolve my issue with getting the enter key to work in my project for FreeCodeCamp on Codepen. When I press the ...

Conceal the slider image without removing it

Is there a way to hide the slider background image on mobile screens? @media screen and (max-width: 800px){ .home #mainSliderWrapper { background-image: none; } .stlye { background-image: none; } .img--holder { background-image:none; } } I tr ...

Retrieving Table Cell Values Using Jquery: A Step-by-Step Guide

<table class="table" align="center" id="tblMain"> <tr> <td>Status</td> <td><b><span name="current" value="Dispatch">Dispatch</span></b></td> </tr> </table> JS $(&apos ...

Find your way to a unique div created through a while loop

Describing my issue clearly, I am using PHP to retrieve data from MySQL. The table contains multiple records. To display table records, I have implemented a while loop with mysqli_fetch_array() as the condition. These records need to be echoed out (in HT ...

How can jQuery be used to target a specific class based on its inner value?

For instance, within a div of the same class, there are 6 "p" tags - some containing 'member' text and others not. I aim to use jQuery to select all "p" tags with 'member' as their inner text and apply an additional class to them. Here ...

The customized cursor image fails to load after switching the application URL from http to https

After implementing a redirect from http to https in my application, I encountered an issue with custom cursor images not displaying as intended. Prior to the redirect, the custom cursor images worked fine and were visible on the page. The URL for these cur ...

Is there a way to utilize PHP/HTML to exhibit a diverse array of random images as dynamic background visuals?

I'm currently learning the process of constructing a website. I've successfully constructed the index page, and below you will find the PHP and HTML code: <?php session_start(); $pngFiles = array('image1.png', 'image2.jpeg' ...

Compact NiceScroll Scroller within a narrower div compared to the width of the scrolled div

I am currently working on a table layout where I have fixed two columns on the left, similar to what is shown in this example. To enhance the scrolling experience, I am using the nicescroll plugin. However, I have encountered an issue where the plugin be ...

Guide to counting the number of image tags within a parent div and selectively removing them starting from a specific position

My dynamic image tag <img> is generated inside a div from the database using fetching. Here is how my HTML looks: <div class='forimgbox'> <p class='palheading'>Pals</p> <img src='userpic/2232323.p ...

Can curly braces be utilized in the style section of Vue.js?

Can I utilize curly braces in the style section of vue.js to set a value? For instance .container { background: url({{ image-url }}; color: {{ color-1 }} } ...

Unable to save the ID of an element into a jQuery variable

I am currently working on a project that involves an unordered list with anchor tags within it. I am trying to access the id of the li element that is being hovered over, but for some reason, the alert is returning undefined or nothing at all. Here is the ...