Combining several position-aligned classes into a single div instead of each having their own individual div

http://jsfiddle.net/58arV/

Trying to create a question component where users can choose the correct answer out of 4 options.

I planned to use 4 input styles with a checkmark "radio" DIV on the right. When a user clicks on an option, it should display a checkmark while others show a red "x".

<div class="answer">
<input type="text" autocomplete="off" name="answer" id="answer-1" placeholder="Answer 1" class="form-control input" value="" />
<button type="radio" class="btn btn-success answer-type" style="" value="1">
<i class="glyphicon glyphicon-ok"></i>
<div class="left-check"></div>
</button>
</div>

Facing an issue where all boxes are positioned at the top-right corner of the first input field.

Any suggestions or solutions would be greatly appreciated. Thank you!

Answer №1

Simply add the following CSS code to your existing stylesheet:

.answer { position:relative; }

Check out the updated example here: http://jsfiddle.net/58arV/1/

Remember, according to CSS specifications, an absolutely positioned element is placed relative to its nearest parent that is either relative or absolute.

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

Intersecting Hyperlink Elements Creating a Hover Effect

I've encountered a perplexing CSS display issue and I'm at a loss for alternative solutions besides simply widening the width of the parent div. Allow me to explain the layout: <div> <ul> <li> <a href="javascrip ...

The div remains unchanged when the button is clicked

My webpage is filled with several large div elements. There's a button on the page that, when clicked, should switch to the next div. Despite my efforts, the code I've written doesn't seem to be working as expected. :( This is the HTML st ...

SWI-Prolog and the Selection drop-down element in HTML

Is there a way to convert this code into SWI-Prolog? I couldn't find any information online on how to write the select statement in Prolog. Can you also provide guidance on making the PHP code function properly within the context of SWI-Prolog? <s ...

Inserting JQuery Selector from a .js file into a .php file at the beginning

Incorporated in my project is a jquery plugin for a slider, which includes the code snippet below for handling 'next and prev' buttons. $(selector).prepend('\ <ul class="mk-nav-controls">\ <li>& ...

Issue with scrollTop functionality on Android smartphones

Currently working on implementing chat functionality for an Android mobile app using jQuery and jQuery mobile theme for the frontend. The issue I am encountering is related to the scrollTop() function not functioning as expected in Android browsers. Does ...

JavaScript can be used to create dynamic frames within a

Can anyone help identify the issue in my code? frame 1 <script type="text/javascript"> var Clicks = 0 ; function AddClick(){ Clicks = Clicks + 1; document.getElementById('CountedClicks').innerHTML = Clicks ; } localStorage.setItem(' ...

Various conditional statements based on the dropdown menu choice

I currently have a basic dropdown menu on my webpage that enables users to switch between viewing Actual or Planned dates/times in a table (I am utilizing the controller as syntax): <select ng-model="trip.viewType"> <option value="actual"> ...

Can you explain the meaning of this AJAX code snippet?

I've been researching online for information, but I'm struggling to find any details about the AJAX code snippet that I'm using: function getEmployeeFilterOptions(){ var opts = []; $checkboxes.each(function(){ if(this.checke ...

Modify the text tone within a specific cell

Welcome to my unique webpage where I have implemented a special feature. The text highlighted in red represents the unique identifier for each individual cell. Interestingly, below there is an input field containing the code "0099CC", which corresponds to ...

Using jQuery to Drag: Creating a draggable effect on a div element

I recently posted a question, but I feel like I need to rephrase it to make it more general. Basically, I have an element that can be moved around and resized using jQuery. I used CSS to attach another div to the right of this element. Initially, when you ...

Creating a sliding bottom border effect with CSS when clicked

Is there a way to animate the sliding of the bottom border of a menu item when clicked on? Check out the code below: HTML - <div class="menu"> <div class="menu-item active">menu 1</div> <div class="menu-item">menu 2</ ...

Creating unique CSS div designs based on the nth-child selector

I have created a website layout. https://i.stack.imgur.com/6FSEb.png I have included the file showing the design. The data in the boxes will come from a MySQL database. My query is, can it be done with just one query? Currently, I am running separate q ...

Using Cascading Style Sheets (CSS) to make posts appear above an image in a scrolling format

Can anyone guide me on how to show the text above an image contained within a scroll bar, similar to the picture below? Despite trying position property and searching online, I haven't found a solution yet. Your help would be greatly appreciated. ...

How can we transfer a jQuery value from an input field without using a single

This task may seem challenging. How can single quotes be eliminated from a variable when passed directly to another variable? I am using jQuery variable $("#test").val() to extract the value from an input below <input type="text" ...

"Employing AJAX along with jQuery in .NET often leads to the error message stating, 'The requested resource was not

Could use some guidance on setting up a simple Ajax call in .NET Any suggestions? [WebMethod] public string Greetings() { return "Hello World"; } When I try to access the webmethod through my browser using this URL: I encounter the error: "The r ...

Issue with Bootbox alert causing focus to not return to the input box

For my latest project, I decided to upgrade from standard alert and confirm boxes to the more stylish bootbox. However, I encountered a problem where the focus does not return to my input field after closing or dismissing the bootbox. bootbox.alert("P ...

How can I code a div to automatically scroll to the top of the page?

I'm attempting to implement something similar in WordPress - I want a div containing an advertisement to initially start 300px down the page, then scroll up with the page until it reaches the top, and finally stay there if the user continues to scroll ...

Stopping all animations with JQuery animate()

I have a question about stopping multiple animations. Here's some pseudocode to illustrate my situation: CSS #div1 { position: absolute; background-image: url("gfx/cat.jpg"); width: 60px; height: 70px; background-size: 50%; b ...

What is the best way to instruct jQuery to disregard an empty server response?

After examining this piece of code: $.ajax({ type: "POST", url: theRightUrl, data: whatToPost, logFunction: whatever, suppressSuccessLogging: !0, dataType: "html" }); I encountered an issue where Firefox displays a "no element ...

Acquiring a hyperlink using a regular expression from the <a href> tag

Currently utilizing JMeter and in need of extracting a link from the <a href> tag below: <a href="/i/info/14259.html" class="ogrLink">Department page</a> The desired regular expression for obtaining this link is: /i/info/14259.html An ...