Struggling to format the input inside a span tag to appear as a single entity

In my Rails 3 application, I have created a form with placeholders using span tags inside input fields within divs. The structure for most of the form fields is as follows:

<div class="holds">
  <span class="holder">Placeholder</span>
  <input>Input</input
</div>

However, there is one field where I would like the actual input to be surrounded by text so that it resembles a fill-in-the-blank. The rendered HTML for this specific field should look something like this:

<div><span>It is supposed to <input id="foo" placeholder="ex: rain"> today</span></div>

My challenge lies in styling this particular div to maintain uniformity. Specifically, I want the div to:

  • Have a consistent border around both the span and input, but no borders inside the span on the left and right of the input.
  • Allow the entire div to be focused when the input is focused.
  • If possible, position the cursor inside the input field when the span is clicked (though this is not a top priority).

You can view my current progress on this issue in the following jsFiddle. Any assistance or guidance would be greatly appreciated.

Answer №1

Check out this demonstration that achieves your desired outcome: http://jsfiddle.net/jalbertbowdenii/akCsP/2/

In the example, I replaced the div with a label. Utilizing elements correctly has its advantages, such as the default user agent behavior where focusing on a label will automatically focus on its associated form control - in this case, the input.

As for styling the div when focused, since it was not specified how you wanted it, I chose to use the input's focus styles instead.

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 setting up a Subnav within a Subnav Code. In this article,

Looking to enhance the bootstrap 4 navbar with multiple subnavs? Check out this code example from W3Schools <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> .... ...

Retrieving a targeted data point from a JSON object

I am working with a json data that contains various properties, but I am only interested in extracting the uniqueIDs. Is there a way to retrieve ONLY the uniqueID values and have them returned to me as a comma separated list, for example: 11111, 22222? (I ...

It's proving difficult for me to align my header and navbar on the same line

Recently, I've delved into the world of HTML/CSS and encountered a challenge. My goal is to align my header (containing an h1 tag) and navbar on the same line. Ideally, the header should float left with the navbar positioned closely to its left. Howev ...

How to flexibly show one item on the top line and two items on the bottom line using CSS

I've been trying to solve a simple problem with my flex container layout. I want to display 3 items in 2 rows - one item in the first row and the other 2 in the second row. However, no matter what I try, the items all end up on a single line due to th ...

The @html.TextBoxFor model value does not appear pre-filled or set for the date type

I am using the @html.TextBoxFor method with a specified type of date. However, when rendering the view, the model value (retrieved from the database) is not being set. Here is an example of my code: <tr> <td>@Html.Label("ReferenceId")< ...

PHP: Trying to access an index that was not defined while retrieving data from $_

I've encountered a problem with a seemingly simple code while trying to make an ajax submit work. The ajax functionality is working correctly up until this point, but for some reason I am unable to print out the $_POST data. After checking the consol ...

The PHP script is exhausting memory resources and triggering a fatal error

I encountered the following error message: Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 528384 bytes) in /home/u234536193/domains/monetizingonline.com/public_html/wp-includes/wp-db.php on line 2024 The problematic cod ...

What is the best way to retrieve data from PHP and format it into JSON for use in my jQuery script?

I need help formatting the data returned to jQuery from a query. The specific format I want is: var externalDataRetrievedFromServer = [ { name: 'Bartek', age: 34 }, { name: 'John', age: 27 }, { name: 'Elizabeth', ...

Tips on adding space between a material icon and its corresponding description

I have a design that needs some adjustments. The material icon is too close to the description, and I attempted to create padding by adding the following CSS: .location-secondary-info span:first-child { padding-right: 5px; } However, this change did no ...

How can I make a clickable button or link within an anchor tag that is still able to be right-clicked?

Hey there, I'm currently working on a notification dropdown menu where each <li> contains a link or an <a> tag. I'm aiming to create something similar to Facebook's notification system. However, the challenge lies in trying to ...

How can we allocate array elements dynamically within div elements to ensure that each row contains no more than N items using only HTML and JavaScript?

For instance, if N is 3 in each row, as more elements are added to the array, the number of rows will increase but each row will still have a maximum of 3 elements. I am currently using map to generate corresponding divs for every element in the arr ...

Steps to ensure checkboxes are enabled for selection only when another box has been checked

Consider having 3 checkboxes: 1 'parent' checkbox and 2 'child' checkboxes. If the parent checkbox is selected, you should be able to select either or both of the child checkboxes. If the parent checkbox is deselected, neither of the ...

Using jQuery and Laravel framework to handle a POST request

Could someone assist me with troubleshooting a jQuery post request issue? I suspect there may be an error with the routes or controller. Here is my JavaScript code for the post request: $.post('http://localhost:8000/ajax', { ...

Incorporating local JSON data into HTML: A Step-by-Step

I'm completely new to javascript and the utilization of json. What I want to accomplish is quite straightforward, although I am encountering difficulties. My objective is to create a website consisting of two pages: one that showcases artists and ano ...

Using Selenium to scroll down to an element until its 'style' changes

I'm in the process of scraping a review page similar to this one. While this specific page has only a few reviews, there are others with a larger volume that require extensive scrolling. Upon observation, I noticed that when the page is not complete ...

Unable to access the jcrop object in order to release it using ajax with jQuery

Hello everybody, I've been struggling with this issue for the past 3 hours and I can't seem to find a solution XD. I have an ajax upload that successfully opens a Twitter Bootstrap modal window upon completion, loads the image, initializes the j ...

What is the best way to center this image horizontally within its variable-sized parent container?

I am currently working on a webpage that has a responsive design. The page features a list of products, with the product listing adjusting in size as the page width changes. My goal is to center the product image within its container, ensuring that the i ...

Storing JSON string data in a MySQL database using PHP can be achieved by first

How can I store a JSON string in my database successfully? This is the issue I am facing: // $data contains a JSON string // info column is of type TEXT in MySQL $q = "UPDATE user SET info = $data WHERE userid = $id"; $sql= $this->db->query($q); ...

Experiment with a variety of designs using HTML and CSS

Struggling with HTML and CSS, I need help achieving the layout shown in the image. How can I use different layouts in a div or organize the controls like in the picture? I'm more familiar with Android layouts, so this is a bit confusing for me. Any as ...

Are there occasional issues with the proper functionality of Bootstrap modals?

I have encountered an issue with a modal I created for my website using Bootstrap v3.3.2. Occasionally, when triggered, the modal appears but the contents within it do not display properly. It seems to be empty, showing only the background of the modal. ...