Placing input text alongside the text above by indenting it

Check out the demo here

Here is the HTML code I am working with...

<div>
<input type="radio" value="some value">some text goes here<br />
<input type="radio" value="some value">some text goes here and it's quite long<br />
</div>

The div element has a width of 110 pixels. When the text becomes too long and wraps, I want it to stay on the same line like this.

o some text
o some text
  and long

Answer №1

To achieve this effect, simply apply some CSS to your existing code.

HTML:

<div>
    <input type="radio" value="some value" />
    <label>insert text here</label>
    <br />
    <input type="radio" value="some value" />
    <label>insert long text here</label>
    <br />
</div>

CSS:

div {
    width: 110px;
}
input[type="radio"] {
    float: left;
}
label {
    float: left;
    width: 80%;
}

For a live example, view this JSFiddle

Answer №2

Here's a suggestion for displaying it on tables:

<div style="width: 110px;">
    <table>
        <tr>
            <td><input type="radio" value="some value"></td>
            <td>insert text here</td>
        </tr>
        <tr>
            <td><input type="radio" value="some value"></td>
            <td>add text here as well as this being lengthy</td>
        </tr>
    </table>
</div>

Answer №3

This solution appears to be the most viable for me.

See the demonstration here

div{
    width: 110px;
    position:relative;
    margin-left: 15px;
}
input[type="radio"]{
    position:absolute;
    left: -20px;
}

Alternatively,

Check out the demo

div{
    width: 110px;
    position:relative;
    padding-left: 20px;
}
input[type="radio"]{
    position:absolute;
    left: 0;
}

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

Changing direction of arrow upon dropdown menu opening with JavaScript

I have developed a piece of code that enables users to click on a div in order to reveal a dropdown menu containing radio buttons. My goal is to make the arrows rotate 180 degrees when the dropdown menus are opened, and then return to their original positi ...

Using HTML or JavaScript to generate a multitude of identical HTML elements on a webpage

I am currently designing a page that requires the presence of numerous tree illustrations with leaves, spanning across the width at the bottom of the page. I have considered two methods to achieve this. One option is to create a single set of trees and lea ...

Ways to conceal HTML tags within a text box

Currently, I am utilizing PHP to extract content from a text file and display it in a textbox. However, I am interested in finding a way to conceal the HTML tags within the textbox (as shown in the image) without deleting them, making them invisible to use ...

Using the ID selector to create a media query

My website is live, and I'm working on making it mobile-friendly. Most of the site works well on mobile, but I'm having trouble centering a jquery lightbox function using media queries. I'm not sure if my syntax is wrong or if there's a ...

Implementing a Radial Cursor with a Custom Background Image in JavaScript

I am attempting to implement a radial cursor on a website that features a background image. Currently, I am facing two main issues: The radial cursor works in Chrome but not in Firefox. When using Firefox, I encounter a parsing error related to the "bac ...

Determine whether an element has the capability to hold text content

Is there a surefire and reliable method to determine if an HTML element is capable of holding text, using only pure JavaScript or jQuery? For example, <br>, <hr>, or <tr> cannot contain text nodes, whereas <div>, <td>, or < ...

Placing two tables in an HTML document

I am working on integrating two tables into my web application and I would like them to be positioned on the same row horizontally. <span><table><tr><td>A</td><td>B</td></tr></table></span> <s ...

`To position an element within a div without affecting its layout, use absolute positioning``

Is it possible to add an element to a div that is aligned to the right but still sits on top of the other element within the div? Here are some images to illustrate the issue: https://i.sstatic.net/dW7ev.png The problem arises when you try to center the ...

Tips for creating sliding header content alongside the header

Is it possible for the content in the header to scroll up, displaying only the navigation list and hiding the logo when a user scrolls on the website? Currently, while the header background slides up, the content within the header remains in place. I feel ...

Eliminate the need for background video buffering

I have a piece of code that I'm using to remove all the created players for my video elements. The code works fine, but I'm facing an issue where the video keeps buffering in the background after it's changed via an ajax call success. Can yo ...

Struggling to incorporate z-index for a tooltip component that overlaps in a project utilizing React, Tailwind, and DaisyUI

Hello everyone, I trust you are all doing great. I have a query regarding a Fireship IO tutorial on incorporating TailwindCSS and DaisyUI into React. I've managed to create a side navbar similar to Discord, complete with tooltips that display as span ...

The inability of Chrome and Firefox browsers to open Windows folders directly from a hyperlink is a common

My link is directing to a Windows folder using its directory path. Surprisingly, it works perfectly fine in Internet Explorer but fails to work in Chrome and Firefox. How can I resolve this issue? The structure of my link looks like this: <a href="&bs ...

Retrieve the initial link value in jQuery and make changes to it

Is there a way in jQuery to append to the current value of an attribute without storing it in a variable first? For example: $(document).ready(function() { $("#btn").click(function() { // get the link currently var linkCurrent = $("#link").att ...

Utilizing Web API for efficient polymer data binding

Is there a way to bind data to a variable upon command, triggered by a button press, from a server? A server-side function returns a JSON object, which is validated by directly accessing the API link. However, the variable remains undefined regardless of m ...

Adding a combination of HTML and Javascript to an element can result in unexpected behavior

http://jsfiddle.net/PeKdr/ Encountering an issue when having a JavaScript variable that contains both HTML and JavaScript, resulting in unexpected behavior in the output window. Neither of the buttons - one triggering the function appendTheString() or the ...

Display a pair of distinct items side by side on a webpage

When needing to display information in the format below: Reason : reason number 1 reason number 2 reason number 3 Code : code number Remarks : remark In this scenario, Reason, Code, and Remarks serve as headings enclosed in <s ...

Tips on choosing a text option from a selection menu

When I try to retrieve the text displayed in my select menu upon selection, I encounter a challenge. While this.value allows me to fetch the value, both this.label and this.text return as undefined. Is there a method to extract the visible text from the d ...

scrolling modal in bootstrap does not function properly if a navigation tab is included within it

I am encountering an issue with a scrolling Bootstrap modal. When I include a nav-tabs within the modal, the scroll function stops working. However, if I remove the nav-tabs, the functionality returns. Do you have any insights on how to solve this problem? ...

DIV with Scrollbar

Is there a method to ensure that both scrollbars are displayed, regardless of whether vertical or horizontal scrolling is required? Currently, I am only seeing one scrollbar when needed. I want to achieve this without restricting the use of the Height or ...

Using cell in a React table

I am in the process of developing a basic table in React with three columns labeled WO, PID, VS. For each cell within these columns, I will need to input data accordingly. The code snippet below showcases my initial implementation along with the desired ou ...