Establish divisions within a roster

I'm working on creating a layout with two columns in an unordered list. I've made some progress, but I want the ul and li span elements to take up the full width of their parent container (div) without specifying a specific width. How can I achieve this? Thank you.

CSS

div {
    width:300px;
}
ul {
    width:200px;
}
li span {
    width: 170px;
    display:inline-block;
    padding-left: 10px;
    vertical-align: top;
}

HTML

<div>
    <ul>
        <li>
            <input type="checkbox" value="1" name="someName[]"><span>Some short text</span>
        </li>
        <li>
            <input type="checkbox" value="2" name="someName[]"><span>Some very very very very very very long text</span>
        </li>
        <li>
            <input type="checkbox" value="3" name="someName[]"><span>Some short text</span>
        </li>
    </ul>
</div>

Answer №1

In case you're not concerned about catering to IE7, an alternative method would be utilizing display: table and display: table-cell:

li { display: table; }
li > * { display: table-cell }

http://codepen.io/anon/pen/abc123

Answer №2

Revamp your styling with

div {
    background-color: white;
    border: 1px solid black;
}
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
li span {
    display: inline-block;
    padding-left: 10px;
    vertical-align: top;
}

Answer №3

div {
    width:250px;
}
li input { 
    position: relative; 
}
li span {
    display: block;
    margin-left: 20px;
    vertical-align: top;
}

http://jsfiddle.net/pd2RZ/

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

encountering an issue with the map function being undefined

I am currently working on a todo list and I want to be able to delete data stored in an array using the filter method. However, I am encountering an error with my code. Here is the snippet: const onDelete = (id) => { setaddItem((prevData) => { ...

When utilizing the `express.static(__dirname)` function in Node.js with Express, the visitor may be directed to an incorrect HTML page

My website consists of a login page named login.html and an index page named index.html. I want to implement authentication so that only logged in users can access the index page. I have not set up the post method on the login HTML page. Therefore, I have ...

When a button is clicked, the event is not triggered within a FirefoxOS application

Despite functioning perfectly on Firefox for desktop, my application encounters issues when tested on my ZTE Open C (Firefox OS 1.3). Pressing the button does not trigger any action, while onmouseup and onclick events work flawlessly. Even attempts to bin ...

I am looking to create a div that can consistently refresh on its own without needing to refresh

I have implemented a comment system using ajax that is functioning well. I am looking to incorporate an ajax/js code to automatically refresh my "time ago" div every 5 seconds so that the time updates while users are viewing the same post. Important note: ...

Steps to switch from the "on click" event to on mouse over in the following code

Can someone help me modify this code to load the larger image on mouse hover instead of on click? Additionally, is there an easy way to add "next" and "prev" buttons to navigate through all the images once a larger image is loaded? Thank you! /** * Image ...

Retrieve a React element that incorporates a value from an array based on a separate array of integers

I am working with two arrays that contain integers and strings like the following: let intArr = [4,3,2,1] let player = ['a','b','c','d','e','f','g','h','i','j&ap ...

The select tag in an iOS app is functional, but unfortunately the multiple select feature is not functioning correctly

When developing my ios app, I utilize loadHTMLString to display a view. Within this view, I generate a select tag with multiple selection options using the following HTML code: [HTML appendFormat:@"<select multiple=\"multiple\" onchange=&bsol ...

Importing values dynamically from a file at runtime

I'm seeking assistance on dynamically loading data in a template when a file changes. Below is a snippet of the data and code: Here is a json file: data = '[{"name" : "bob", "value" : "3.1"}, {"name" : "joe", "value" : "5.6"}]'; The value ...

Showing JSON arrays within innerHTML

One of my peers provided me with an array, and my task is to present it in an HTML format. Even after consulting various resources and examples, I am unable to display the required values. This is my first attempt at such a task, so any guidance would be ...

The curly braces in AngularJS are failing to display the values on the HTML page

After trying various articles and solutions to different questions, I am still unable to resolve my issue. I am working on a blank ionic project and it is running smoothly in my browser using ionic serve without any errors. However, instead of displaying ...

Using jQuery to animate the width of a container after it is fixed to the top of the page based on the position of the

Wow, I've been tinkering away for hours and can't seem to crack this code puzzle. Let's dive into some CSS: #wrapper { margin: 0 auto; padding: 0 20px; width: 960px; } #wrapper .block { width: 920px; height: 690px; } ...

Differences in typography across Mozilla Firefox and Internet Explorer

I have come across a question that seems quite common, yet unsolvable. However, I will give it a try anyway. Take a look at this image: To view a larger version of the image, visit the following URL: https://i.stack.imgur.com/dddNm.jpg HTML code: <d ...

Using Javascript to place a form inside a table

When attempting to add a Form inside a Table, only the input tags are being inserted without the form tag itself. $(function () { var table = document.getElementById("transport"); var row = table.insertRow(0); var cell1 = row.insertCell(0); ...

Using JQuery to update text by sliding in the new one and pushing down the old text

I am experimenting with JQuery to create a unique effect where new text pushes the old text down and causes it to vanish. Essentially, it is a stylish text replacement: the new text displaces the old text while making it disappear. Someone has developed s ...

Enhance image with Fancybox on mouse click

I need to display several images in the content area of a page, and when a user clicks on an image, it should enlarge using fancybox. If an image is large, the user should be able to click on it to view an enlarged version in a fancy box. Both the thumbn ...

Looking for a method to emphasize a particular word in a Material-UI Typography component within a Card without causing any alignment changes upon rendering?

Is there a way to bold a single word within a React Material-UI <Typography> element without causing text resizing on load? <Typography><b>First thing:</b> {answers[2]}</Typography> I find myself nesting <Typography> t ...

Is there a method to stop a mobile device from rotating my responsive website on mobile devices?

Currently, I am in the process of developing a mobile responsive website and I'm aiming to prevent any rotation on Safari specifically. Is there a way that I can achieve this without affecting other browsers like Android? ...

Difficulty with float left in HTML/CSS causing divs to appear below each other instead of side by side

I'm currently facing an issue with creating a 2 column layout using the classes "left" and "right". Right now, the .right column is not floating left and is instead appearing below the .left column. Interestingly, when I delete the content inside .le ...

Nightwatch is a tool that allows you to interact with elements on a webpage by clicking on an element within

I have a scenario on my website where I have two separate div elements: <div class="wg-block" data-reactid="10" <div class="wg-header" data-reactid="11"/div> .... <h4 class='condition'> "Text" </h4> <div cl ...

Avoiding ContentPlaceHolder in the creation of ID tags

Recently, I successfully integrated a master page to manage all my sub pages in an older project. In order for the sub pages to render correctly, I had to insert <asp:content id="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> i ...