Placing an alert box within a text input field

After experimenting with the code, I managed to place an alert box within a textarea using the following CSS styling:

CSS :

#alertBox {
    width: 30%;
    height: 12%;
    margin: auto;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    padding: 40px;
    background-color: #0075bf;
    color: white;
    text-align: center;
    font-size: 20px;
}
#template {
    font-family: Lato Regular;
    width: 70%;
    margin: auto;
    margin-top: 10%;
}

@media (max-width: 992px) {
    #alertBox {
        width: 100%;
        margin-left: 3%;
        margin-right: 10%;
    }

    #template {
        width: 100%;
        margin-top: 5%;
    }
}

HTML :

   <div class="container">
   <article id="template">
    <form role="form">
        <fieldset class="form-group">
            <h5 for="myOffer">Mon offre</h5>
            <div id="alertBox" class="alert alert-info">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a> Merci de compléter votre offre avant de cliquer sur envoyer
            </div>
            <textarea class="form-control" rows= "13 " id="myOffer "></textarea>
        </fieldset>
    </form>  
    </article>
    </div> 

However, during resizing of the form, the positioning of the alert box inside the textarea is not perfect.

Check out the desired outcome here:

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

If you have any recommendations on how to improve this, please share them. Thank you!

Answer №1

To correctly achieve this, you need to specify the width and position of the fieldset element as shown, and set the width of the textarea to 100%:

fieldset {
    position:relative;
    width: 600px; //adjust as needed
}
textarea {
    width:100%;
}

By doing so, your alert box will be positioned absolutely relative to the <fieldset> element. As you resize the window, the fieldset will adjust accordingly, ensuring that your alert box remains centered within it.

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

"Pressing the 'back' button on your browser takes

Is there a way to navigate back to the main page by clicking on an image? After selecting First, Picture1 will be shown. How can I go back to the selection page for further choices? <a href="picture1.jpg"> <h3>First</h3></a> <a ...

Mobile Menu in wordpress stays visible after being clicked

I recently created a one-page layout that includes some links. However, when I view the site on my smartphone and open the main menu using the button to click on a link (which scrolls within the same page), I noticed that the mobile menu remains visible a ...

Looking to automatically adjust the browser viewport when the iOS keyboard pops up?

Is there a way to keep the conversation area completely in view when the keyboard displays on iOS web browsers like Safari and Chrome? I am trying to create an app-like chatting experience, but the viewport keeps getting partially pushed out of view when t ...

How can I allow scrolling within a specific div element?

Here is the structure of my layout: <html> <head> stuff goes here </head> <body> <div id="master"> <div id="toolbar"> <input type="text" id="foo"> </div> <div id="c ...

Preventing Div items from rearranging during size transitions using toggleClass

When I click on an element with the ID "id", I use toggleClass to resize a div from 10px to 500px in width. This is done partly to show/hide content. However, the issue arises when the transition occurs and the contents of the div start rearranging, overfl ...

Exploring the font variables in the asset pipeline of Rails 7

Creating a habit of defining a set of root variables is crucial for maintaining consistency throughout an application. :root { --main-font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif; --kbd-font-family: Consolas, "Libe ...

Arranging the form in an organized and visually pleasing manner

Does anyone have any ideas on how to design this form in a clean and organized way? I've experimented with lists, tables, and divs but can't determine which works best. Contact Information: <div class="formsubmit"><label>Name:& ...

Is your floating action button malfunctioning?

Having an issue where clicking on a button should bring it to the top and float. The button is coming to the top but not floating. Any suggestions on how to solve this problem? Here is the code: <div class="create-course-info" id="scroll"> <a hr ...

What is the complete list of features that ColorTranslator.FromHtml() supports and what are the reasons behind its departure from traditional CSS color interpretation guidelines

I'm looking to enhance an API by providing users with the ability to specify the color of something. I want it to accept various representations of colors, such as hex codes and CSS colors. Initially, I thought that ColorTranslator.FromHtml() would fu ...

CSS exclusive - achieving a horizontal scrolling list with all list items in a single row

I am working with a div that has a fixed width. Inside this div, there is an unordered list (ul) containing a random number of list items (li) with varying widths. My project utilizes the Bootstrap framework. Below is an example of the code structure: & ...

As the height is expanded, the background color gradually infiltrates the body of the page

I am currently working on an angular application that utilizes angular-pdf. The controller and view function perfectly, and the PDF is displayed correctly, except for one issue. The height of the PDF exceeds the min-height of the module, causing it to expa ...

Unable to apply border radius to the div containing the video

Currently, I am attempting to create a video with rounded corners by wrapping the <video> tag in a div element with rounded corners. This method works perfectly in Chrome and Firefox, but unfortunately does not work in Safari. It seems like this ma ...

Exploring the world of mathematics using JavaScript, adjusting the range input, and applying CSS transform with scale()

In my project, I have a container div set to a width of 794px and a range input with a maximum value of 250 and a minimum of 0. I am using CSS transform property like this: scale(1), where the scale is equivalent to 794px. The challenge arises when the br ...

What could be causing the menu to not align in the center?

Take a look at the HTML code below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="v ...

Change the maximum width of the parent element when it is positioned relatively

In my web design project, I have a full-container with a maximum width of 1080px and positioned relatively to hold all content. Within this container, there is another div element (.portfolio) that I want to extend to the full width of the page (max-width: ...

css problem with stacking order of child elements

Trying to arrange 3 HTML elements on the z-plane: .bank { width: 200px; height: 200px; background-color: grey; position: absolute; z-index: 100; transform: translateY(10%); } .card { width: 100px; height: 100px; background-color ...

position the table next to the graph

I'm having trouble moving/placing items in HTML. Can we experiment with rearranging the tables as demonstrated at the bottom (expected output)? Is it feasible to achieve a layout like the one below? Shifting the bottom section up next to the plots. ...

Creating a dynamic button with Angular that appears when focused

I want to have a button appear when the user focuses on an input with the ng-model=query. I know there is an ng-focus directive, but how can I implement it? <input type="search" ng-model="query"> <!--this is the button I need to show once th ...

Expanding Div Heights that Adjust to the Browser's Width

Looking to set up a responsive height for a div, almost there but facing some distortion when resizing the browser. Here is the fiddle file for reference: https://jsfiddle.net/td5n8ky9/10/ The issue lies in the bottom 2 divs - aiming for a grey bar the wi ...

The Bootstrap Grid system quickly transitions between multiple columns simultaneously

My bootstrap responsive row initially resizes correctly as the window width decreases, but then it suddenly jumps to a layout where each item is on its own line. I would prefer a more graceful transition where items are added one at a time when they no lon ...