The issue I'm encountering is with adjusting the width of the "li" element. I previously faced a similar challenge with the "div" width, but managed to resolve it. My goal is to set the width of the "li" to 50%, but I'm having difficulty achieving

<ul>
  <li>test 1</li>
  <li>test 2</li>
  <li>test 3</li>
  <li>test 4</li>
  <li>test 5</li>
  <li>test 6</li>
</ul>

*{
  margin:0;
  padding:0;
  box-sizing:border-box;

}

ul{
  width:100%;
}

li{
  display:inline-block;
  width:50%;


}

I am looking to achieve a specific behavior for the li elements:

JSbin

Currently, I have set the width of the li elements to be equal at 49%. Is there a workaround or hack to make them truly equal?

In situations where I use nested div elements, setting font-size: 0 works. However, this approach is not feasible with the li elements.

Answer №1

Experiment with the following CSS rule: li{display: inline-block; width: 50%; float: left;}

Answer №2

To address the issue, flex can be utilized. The following CSS code is designed for the same HTML file:


*{
    margin:0;
    padding:0;
    box-sizing:border-box;
}

ul{
    width:100%;
    display: flex;
    flex-wrap: wrap;
}

li{
    display:inline-block;
    width:50%;
}

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

Tips for arranging Angular Material cards in columns instead of rows

I am currently developing a web application using Angular, and I've encountered an issue while trying to display cards in a vertical layout rather than horizontally. My goal is to have the cards fill up the first column (5-6 cards) before moving on to ...

The method models.User.fromURI is unsuccessful

When I try to call models.User.fromURI as shown below: models.User.fromURI("spotify:user:" + user, function (user) { $(div).html("<b ><a style=\"color:#FFFFFF\" href=\"spotify:user:" + user.username + "\">" + us ...

The ideal choice for a default background image in terms of style and dimensions

I'm using this code to set a background image for my website. body{ background: url('path_to_image'); background-size: 100%; } I find that the background-size property works well for handling different screen sizes. I'm creating ...

Python Selenium Timeout Exception Handling

Looking for a solution: def get_info(url): options = webdriver.ChromeOptions() options.headless = True chrome_browser = webdriver.Chrome('./chromedriver', chrome_options=options) chrome_browser.get(url) name = chrome_browser.f ...

Personalizing the Twitter Bootstrap grid layout to fit your needs

I am currently attempting to adjust the number of columns in the standard Bootstrap grid layout from 12 to 8. After reviewing the Bootstrap documentation, I understand that this requires modifying the @gridColumns variable and making adjustments in the res ...

What exactly happened to my buttons when I transition to the mobile display?

Due to time constraints, I decided to save some time by utilizing a CSS template called Horizons created by Templated. This particular CSS template uses Javascript to adjust the layout for mobile devices, causing buttons to switch from inline to block for ...

Steps to vertically shift an image downwards within a navigation bar using HTML and CSS

Currently, there is a fully functional navigation menu that can be toggled within a webpage. An image is also included in the navigation menu and positioned below the text. I would like to move the image to the very bottom of the navigation menu to remove ...

Learn how to synchronize input field with a checkbox using v-model and computed property in Vue.js

Trying to find the best way to mirror two input fields and update them dynamically based on a checkbox value. Currently, I am using computed properties with get and set features. The issue arises when the user enters "ABC" in shipping details, unchecks the ...

Create an animation effect where a div increases in height, causing the divs beneath it to shift downward in a

My aim is to create columns of divs where the user can click on a div to see more content as the height expands. I've managed to set this up, but it seems there's an issue with the document flow. When I click on a div in the first column, the div ...

Avoiding page refresh while submitting a form can be tricky, as both e.preventDefault() and using a hidden iFrame seem

I've been stuck on this issue for a while now, scouring Stack Overflow and Google for solutions, but nothing seems to be working. My main goal is to avoid page reloads after uploading a file because it resets the dynamic HTML I need to display afterwa ...

The versatile nature of the flex-direction CSS property

I am attempting to customize the layout of the code available at https://codepen.io/rperry1886/pen/KKwbQNP in order to showcase the images in a horizontal sequence rather than vertically. Despite referring to resources on Flexbox like https://css-tricks.co ...

Have you ever wondered how the automatic video play on scroll feature works on Tiktok.com and YouTube shorts when using a mobile device?

My goal with React JS is to develop a website similar to Tiktok, where the video below will automatically play with sound as the user scrolls down. I attempted to set this up using window.addEventListener("scroll",...), but after looking into it further, ...

Delete a specific character sequence from a PHP form before storing it in a MySQL database

My Objective: I aim to utilize a straightforward PHP form to transfer data to a MySQL database. However, in cases where the input includes a specific string, I intend to eliminate it before storing it in the MySQL database. For instance: if the input ...

conceal elements created with JQuery within an AJAX function

Is it possible to use jQuery and the $.ajax() method to submit a form, displaying only the result while hiding other elements on the page? I am looking to add a conditional in the Ajax method that will show the result if successful, hiding certain elements ...

How can I receive user input in JavaScript while incorporating three.js?

I am currently exploring the functionalities of this three.js example () and I am interested in enabling users to input specified X, Y, and Z positions for boxes dynamically. Initially, I considered utilizing a JavaScript prompt like below: var boxes = p ...

Confirming information in Bootstrap's pop-up modal dialog

Currently, I'm utilizing Bootstrap 2 in my project. One of the challenges I am facing is that within a form, there is a button triggering a bootstrap modal dialog. Inside this dialog, we have a select2 control that needs validation - specifically, it ...

Place the image in the middle of a div

Struggling to horizontally center an image in a div, but for some reason it's just not working. I've centered images many times before, so why is it different this time? Here's what I've attempted... CSS #cabeca{ position: relative; f ...

Traverse a deeply nested JSON structure

I need assistance with looping through a complex JSON object using only JavaScript. My goal is to log each item along with its properties into the console. const nested_json = { "item1":{ "name": "banana", ...

What is the best way to make a div that fades away after a set period, but remains visible when hovered over?

I am currently working on implementing a notification system that will appear for a few seconds and then vanish. However, I want to give users the option to hover over it with their mouse to prevent it from disappearing. It would also be nice to have the n ...

What is the best way to style a select element to achieve this appearance?

https://i.sstatic.net/4yGqf.png Currently working on converting a .psd file to html/css and encountering difficulty with a unique looking select element. Struggling to find a suitable example online for reference. Wondering if this design element is indee ...