Place the custom form error in various responsive layouts

I have set up a bootstrap navigation bar along with a form to the right. An additional custom error box is designed to be displayed at the bottom of the form in the browser.

https://i.sstatic.net/6c6Zz.png However, when viewed in responsive mode, the layout changes as shown in this image: https://i.sstatic.net/9g5xE.png The issue arises due to the error box being positioned absolutely. I am looking for ways to improve its display on mobile and tablet devices.

The objective is to have the error box appear similar to the first image but showcased before the search (which should instead be changed to login) button on mobile/tablet screens.

It's important to note that jqueryvalidation is not being used. These errors will originate from .NET Core, and currently, positioning them correctly has been quite challenging for me.

.navbar {
  min-height: 70px;
  background-color: #fff;
  border-bottom: 1px solid #eee;
}

.navbar-brand {
  height: 70px;
  line-height: 55px;
}

.navbar-toggler {
  border: 0 !important;
  border-radius: 0 !important;
}

.navbar-toggler:active,
.navbar-toggler:focus {
  outline: 0;
}

.dropdown-menu {
  border-color: #eee;
  border-radius: 0;
}

.error {
  background-color: red;
  color: #fff;
  padding: 5px;
  border-radius: 5px;
  position: absolute;
  top: 65px;
  right: 240px;
}

.arr {
  width: 0;
  height: 0;
  position: absolute;
  top: -7px;
  margin-left: 80px;
  text-indent: -9999px;
  border-right: 8px solid transparent;
  border-bottom: 8px solid blue;
  border-left: 8px solid transparent;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<nav class="navbar navbar-expand-lg navbar-light py-0">
  <div class="container-fluid px-0">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">

      <form class="form-inline my-2 my-lg-0 ml-auto">
        <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
        <input class="form-control mr-sm-2" type="password" placeholder="password" aria-label="password">
        <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
        <div class="error">
          <div class="arr"></div>
          <p>Error box with validation</p>
        </div>
      </form>
    </div>
  </div>
</nav>

Answer №1

Take a look at this one

.navbar {
  min-height: 70px;
  background-color: #fff;
  border-bottom: 1px solid #eee;
}

.navbar-brand {
  height: 70px;
  line-height: 55px;
}

.navbar-toggler {
  border: 0 !important;
  border-radius: 0 !important;
}
.navbar-collapse{
position:relative
}

.navbar-toggler:active,
.navbar-toggler:focus {
  outline: 0;
}

.dropdown-menu {
  border-color: #eee;
  border-radius: 0;
}

.error {
  background-color: red;
  color: #fff;
  padding: 5px;
  border-radius: 5px;
  position: absolute;
  top: 65px;
  right: 240px;
}

.arr {
  width: 0;
  height: 0;
  position: absolute;
  top: -7px;
  margin-left: 80px;
  text-indent: -9999px;
  border-right: 8px solid transparent;
  border-bottom: 8px solid blue;
  border-left: 8px solid transparent;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<nav class="navbar navbar-expand-lg navbar-light py-0">
  <div class="container-fluid px-0">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">

      <form class="form-inline my-2 my-lg-0 ml-auto">
        <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
        <input class="form-control mr-sm-2" type="password" placeholder="password" aria-label="password">
        <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
        <div class="error">
          <div class="arr"></div>
          <p>error box with validation</p>
        </div>
      </form>
    </div>
  </div>
</nav>

Answer №2

This is just a minor adjustment...now the error box is positioned at the bottom without any shifting..but it still does not point to the correct form element...

.navbar {
  min-height: 70px;
  background-color: #fff;
  border-bottom: 1px solid #eee;
}

.navbar-brand {
  height: 70px;
  line-height: 55px;
}

.navbar-toggler {
  border: 0 !important;
  border-radius: 0 !important;
}

.navbar-toggler:active,
.navbar-toggler:focus {
  outline: 0;
}

.dropdown-menu {
  border-color: #eee;
  border-radius: 0;
}

.error {
  background-color: red;
  color: #fff;
  padding: 5px;
  border-radius: 5px;
  position: absolute;
  bottom: -55px;
  right: 240px;
}
form {
  position:relative;
  }

.arr {
  width: 0;
  height: 0;
  position: absolute;
  top: -7px;
  margin-left: 80px;
  text-indent: -9999px;
  border-right: 8px solid transparent;
  border-bottom: 8px solid blue;
  border-left: 8px solid transparent;
}

@media (max-width:574px) {
   .error {
  background-color: red;
  color: #fff;
  padding: 5px;
  border-radius: 5px;
  position: absolute;
  bottom: -35px;
  right: 240px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<nav class="navbar navbar-expand-lg navbar-light py-0">
  <div class="container-fluid px-0">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">

      <form class="form-inline my-2 my-lg-0 ml-auto">
        <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
        <input class="form-control mr-sm-2" type="password" placeholder="password" aria-label="password">
        <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
        <div class="error">
          <div class="arr"></div>
          <p>error box with validation</p>
        </div>
      </form>
    </div>
  </div>
</nav>

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

Create a layout using CSS that features two columns. The left column should be fluid, expanding to fill all remaining space, while the right column should be fixed

I need to ensure that the Online Users div always remains at a fixed size of 200px, while allowing the chat window next to it to resize dynamically based on available space. Essentially, I want the chat window to adjust its width as the window is resized, ...

Preventing the stacking of numerous animations triggered by jquery events

Hey there! I'm currently working on a webpage and utilizing the Transit library for 3D rotations and other CSS transformations. On this page, I have three links that are set to scale up by 1.2 times when hovered over. Everything seems to be working we ...

Error: The JavaScript SRC cheat is malfunctioning

Having an issue with the code below. The 'dummy1' and 'dummy2' variables are not loading their content as expected on the page. Any suggestions? <html> <head> <title>JavaScript On-line Test</title> <script LA ...

Retrieving Multiple Arrays of Variables in PHP Output

I am struggling to retrieve the GET Variables from the URL of this particular page. Here is the URL: http://thisthat.com/category/?field_issue_month_value%5Bvalue%5D%5Byear%5D=2013&field_issue_month_value%5Bvalue%5D%5Bmonth%5D=10 I am attempting to ...

Excessive content within the div element causing overflow

In my Laravel project, I am facing an issue with the patient history form. The content overflows under a div as shown in the image below. View first image To address this problem, I tried using overflow:hidden in the CSS section. However, this caused my ...

Tips for dealing with a div that needs to be contained within another element with scrollbars?

I am facing an issue with a div that has specific dimensions (height:x; width:y; overflow:auto;) and displays the content of an article. The problem arises when the content exceeds the div's limits, causing a scrollbar to appear for navigation. Withi ...

Creating Horizontal Repeating Cards in Three Columns with Bootstrap 4: Cards

I want to create a layout like the one shown below: card1 card2 card3 card4 card5 card6 card7 card8 card9 card10 card11 card12 card13 card14 card15 etc....(using asp.net repeater control) INSTRUCTION: I need the cards to be displayed horizontally in thre ...

Creating Stylish Buttons with Icons in Bootstrap 4

Currently, my goal is to design buttons similar to the ones displayed below using Bootstrap 4: https://i.sstatic.net/fqkeU.png The font awesome icon should be perfectly centered with the text and aligned at the same y position on the screen. Furthermore, ...

Is it permissible to utilize multiple ":root" selectors in a CSS file?

One of the features in TWBS 4 is the presence of color variables within the :root selector in bootstrap.css. Is it possible for my child stylesheet to also include a :root selector, allowing me to define my own variables? I assume that :root {} can be ov ...

Navigating into the forbidden territory of the if block that holds secrets untold

Encountering an issue with the angularjs $location feature. I have set up an auth interpreter that redirects to the login page if a 401 error (unauthorised) is returned by the server. In my app.js file, both the auth interpreter and the account data loadin ...

Struggling to follow the placement of elements within the treeview component

I have successfully implemented a method to track the positions of Div elements on my webpage. However, I am facing an issue with keeping track of the position of a div within a modal popup extender that contains a TreeView. The position is always reset to ...

Internet Explorer 8 is throwing an error with code SCRIPT438, indicating that the object does not have the capability to support the property or method known

Encountering an error in IE8 when loading the jspdf.debug.js file: SCRIPT438: Object doesn't support property or method 'getContext' and SCRIPT257: Could not complete the operation due to error 80020101. After researching with Google, un ...

When reducing the page size, the Bootstrap columns are colliding with

While resizing the screen, I noticed that these images are overlapping each other. I haven't made any changes to the css for container-fluid or row. <div class="container-fluid bg-grey"> <div class="row center"> <div class= ...

Is it possible to make a model draggable but disable it specifically on input fields?

I'm exploring the implementation of a draggable feature by using both a JavaScript directive and the simple draggable="true" attribute. (Testing each method separately). Here's my basic code structure: <div draggable="true& ...

Unable to establish connection with server through Ajax request on HTML page

I set up a NodeJs server using the Express module. However, I am facing issues with implementing an AJAX request from an HTML page using $.ajax when clicking a button. I want to retrieve data from the server in either JSON or text format but for some reaso ...

The challenge of overlapping elements in jQuery UI resizable

Encountering an issue with the resizable class in jQuery UI (http://jqueryui.com/resizable/). When resizing begins, all divs below move to overlap with the resizing div. Upon inspecting the js console in chrome, it appears that resizable applies inline sty ...

Animation of shaking CSS circles

I have been working on creating a circle using CSS, but I've run into some issues that I can't seem to fix. There are two main problems I'm facing: When viewed in Chrome: The circles shake while rotating. When viewed in Firefox: A tail ...

The hover feature in the plugin is stuck in an infinite loop

I'm currently working on a plugin that will change the background color of an image to semi-transparent black when it's hovered over. To achieve this effect, I've added a overlay class tag above the image. Since each image may have different ...

How can I receive user input in JavaScript while incorporating three.js?

I am currently exploring the functionalities of this three.js example () and I am interested in enabling users to input specified X, Y, and Z positions for boxes dynamically. Initially, I considered utilizing a JavaScript prompt like below: var boxes = p ...

Enhance your form input-group in Bootstrap-4 by adding a stylish border and background-color through validation

I'm working on a form using Bootstrap 4 and I need to display validation errors. Specifically, I want the text field with an input-group for the password to have the same styling as the Username field when there is an error (i.e., red border and backg ...