Is it possible to place a DIV between the OL and LI tags when creating a two-column ordered list?

I am utilizing the 960.gs framework to create a two-column ordered list with each list item containing a heading and paragraph. My issue is that I want the numbering to go across, not down (e.g., the top row should contain 1, 2 instead of 1, 3). The only solution I have found is to insert a DIV between the OL and LI elements. However, this method doesn't seem quite right, although I can't pinpoint why. What is the correct approach to achieve this layout? Below is the markup I currently have:

<div class="container_16">
<ol>
    <div class="grid_8">
        <li><h2>Heading</h2>
            <p>Paragraph</p>
        </li>
    </div>
    <div class="grid_8">
        <li><h2>Heading</h2>
            <p>Paragraph</p>
        </li>
    </div>
    <div class="clear"></div>
    <div class="grid_8">
        <li><h2>Heading</h2>
            <p>Paragraph</p>
        </li>    
    </div>
    <div class="grid_8">
        <li><h2>Heading</h2>
            <p>Paragraph</p>
        </li>    
    </div>
    <div class="clear"></div>
</ol>
</div>

Answer №1

In the realm of HTML coding, it is considered incorrect to nest div elements within an ol tag.

The proper structure dictates that only li elements should reside inside an ordered list (refer to W3C documentation on lists for more information).

A typical approach involves utilizing CSS styling like this:

ol{width:200px;}
li{float:left;width:50%;}

You can view a demonstration of this concept at here.


If you are implementing the 960.gs system, adhere to the following format:

<ol class="container_16">
    <li class="grid_8">first</li>
    <li class="grid_8">second</li>
    <li class="grid_8">third</li>
    <li class="grid_8">fourth</li>
    <li class="grid_8">fifth</li>
    <li class="grid_8">sixth</li>
</ol>

Additionally, ensure your CSS contains:

ol.container_16 li.grid_8{
   display:list-item;
}

This will maintain the numbering as expected. View a visual representation at this link.


Update:

Addressing concerns about varying heights within li elements, utilize the following CSS snippet for modern browsers:

.benefits li:nth-child(odd) {
    clear: left;
}

Alternatively, create a separate class and apply it to odd-numbered li elements for consistent spacing.

Answer №2

It's completely understandable to have mixed feelings. Lists are made up solely of list-items with no added elements. To create horizontal numbering, consider floating your LIs for a simple solution.

Answer №3

The source code above contains an error. It is not allowed to insert anything other than

<ol></ol> 

between

 <li></li>

tags. You may need to explore alternative methods for styling your lists.

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

Stacking components when scrolling in CSS to create a scrolling effect

I've been attempting to replicate the scrolling animation seen on this particular website: . The effect involves keeping the previous content in place while new content stacks on top as you scroll. I have experimented with using position:sticky and ad ...

What are some tactics for avoiding movement in the presence of a border setting?

I created a webpage that has the following structure: .topbar-container { width: 100%; position: fixed; top: 0; background-color: #2d3e50; z-index: 999; display: flex; transition: height 500ms; } @media (min-width: 992px) { .topbar-cont ...

Prevent the loading of a <img> element and replace it with a new one using CSS

Is there a way to hide an <img> element without accessing the HTML directly, only by using CSS? The <img> element does not have any specific class. Here is the HTML markup: <img title="Manual" id="imgAjuda" src="images/ico_aj.png" width=" ...

Tips for uploading a file with PHP

Can someone please assist me? I am having trouble getting this to function properly. <form action="accept-file.php" method="post" enctype="multipart/form-data"> Your Photo: <input type="file" name="photo" size="25" /> <input type="s ...

Uploading Blobs using JavaScript and FormData

Currently, I'm encountering an issue with uploading a blob generated in JavaScript to my server. The main concept involves a user uploading an image, which is then center cropped and downsampled using JavaScript before being transmitted. Although the ...

Two Ajax Requests Simultaneously

I am currently faced with the challenge of handling two requests simultaneously. The first request involves executing a lengthy PHP script that takes 10 minutes to complete (I cannot modify it using JavaScript, so that's not an option). The second ...

How to position multiple CSS background images effectively?

Greetings all! I'm seeking advice on how to add a background image to the right of the description and left of the first post column. Any tips on proper placement? Appreciate any help :) ...

Can the top header stay fixed to the top of the screen even when scrolling down?

Code snippet: http://jsfiddle.net/R3G2K/1/ In my project, there are multiple divs with content and each div has a header. My goal is to make the last header that goes out of viewport "sticky" or fixed at the top. I have explored various solutions for thi ...

Issue with PHP Form data not syncing with MySQL Database

I have been attempting to create a form and upload it into my database, but unfortunately, it is not functioning properly. Here is the HTML code I am using: <form name="Form-Request" method="post" action ="icn/form.php"> <div> ...

Toggle the operational status of the bootstrap switch

Does anyone have a solution for customizing the appearance of the Bootstrap switch button when it is disabled? I have successfully styled it for the enabled state, but it defaults to a dark appearance when disabled. I would like the disabled state to have ...

AngularJS directive for dynamically manipulating the DOM

I'm looking to create a directive that updates an image based on the "name" attribute value. Currently, the image displays correctly but does not change when the "name" attribute is updated. Here is the sample HTML code: <img custom-image name="{ ...

Is there a way to incorporate animation into a :hover element?

Currently, I am trying to create a :hover effect that will change the background color of an element between five different colors when it is hovered over. Below is the code I have been working on: <div class="background_changer"> < ...

I tried moving the onchange(this) function from HTML to JavaScript, but I seem to have missed a parameter. The code ends

I'm currently building a website for a fictional ice cream shop to enhance my JavaScript skills. function hideAAndB() { var pickupDiv = document.getElementById("pickupDiv"); var deliveryDiv = document.getElementById("deliveryDiv"); pickupDi ...

Generate a dynamic list item by utilizing two file paths with JQuery

Alright, let me explain this as clearly as possible My goal is to create a jQuery function that will generate a list from images stored in two different folders. The result I am looking for is a list containing up to 30 images. <div id="box"> & ...

Modifying the color of the tooltip arrow in Bootstrap 4: A step-by-step guide

How can I change the arrow color of the tooltip using Bootstrap 4? Here is my current code: HTML: <div class="tooltip-main" data-toggle="tooltip" data-placement="top" data-original-title="Service fee helps Driveoo run the platform and provide dedicate ...

What is causing Firefox to display an additional line in this section?

After much effort, I've been attempting to eliminate the extra spacing on this page in Firefox: Do you see the menu? If you compare it to Chrome, you'll notice that the menu is positioned too low beneath the background, giving the layout a broke ...

The navbar expands in height when resized

I've been working on creating a responsive navbar, but I'm facing an issue where the height of the bar doubles between phone screen size and full window size. Despite trying various Bootstrap classes, I haven't had any success in fixing this ...

Create a duplicate <li> element and animate it using jQuery

Here are the list items: <ul> <li>...</li> <li>...</li> <li>...</li> <li>...</li> <li>...</li> <li>...</li> <li>...</li> <li>...</li> <li>...</l ...

Blog Writer: Picture quality compromised when adjusting size

Issue with blurry images after resizing. The problem is noticeable in the three main images located under the Header section. To preview the blog, click on this link: Click Here Your assistance in solving this issue would be greatly appreciated. Thank yo ...

How to determine button placement based on the content present on the page

I'm struggling to find the right CSS positioning for a button on my page. I want the button to stay fixed in a specific location, but when there's a lot of content on the page, I need it to adjust its position accordingly. Initially, I want the ...