Arranging several lists in columns with a customized header title

I am looking to have 7 lists displayed side by side, each with a unique styled header title. I want the lists to be neatly organized under their respective titles, including the bullets. I attempted to use text-indent for this purpose, but it seems that it's not compatible with IE8. Below is the code I came up with as a beginner web developer, however, I'm encountering validation errors. Even though I know having styled headers directly under the UL tag is not standard practice, it's the only way I could achieve the desired clean layout. Can someone help me identify what mistake I am making?


<ul style="width:14%; float:left;">
    <span style="font-size: 13px;"><p class="notice">Title 1</p></span>
    <li><a class="underline2" href="etc etc"><span style="font-size: 10pt; line-height: 14px; color: #616161;">aaaaa</span></a></li>
    <li><a class="underline2" href="etc etc"><span style="font-size: 10pt; line-height: 14px; color: #616161;">bbbbb</span></a></li>
    <li><a class="underline2" href="etc etc"><span style="font-size: 10pt; line-height: 14px; color: #616161;">ddddd</span></a></li>
</ul>

<ul style="width:14%; float:left;">
    <span style="font-size: 13px;"><p class="notice">Title 2</p></span>
    <li><a class="underline2" href="etc etc"><span style="font-size: 10pt; line-height: 14px; color: #616161;">eeeeee</span></a></li>
    <li><a class="underline2" href="etc etc"><span style="font-size: 10pt; line-height: 14px; color: #616161;">ffffff</span></a></li>
    <li><a class="underline2" href="etc etc"><span style="font-size: 10pt; line-height: 14px; color: #616161;">hhhhhhh</span></a></li>
</ul>

<ul style="width:14%; float:left;">
    <span style="font-size: 13px;"><p class="notice">Title 3</p></span>
    <li><a class="underline2" href="etc etc"><span style="font-size: 10pt; line-height: 14px; color: #616161;">iiiiii</span></a></li>
    <li><a class="underline2" href="etc etc"><span style="font-size: 10pt; line-height: 14px; color: #616161;">kkkkkk</span></a></li>
    <li><a class="underline2" href="etc etc"><span style="font-size: 10pt; line-height: 14px; color: #616161;">llllllll</span></a></li>
</ul>

Answer №1

Your HTML code is not valid, and you are using inline styles unnecessarily.

To improve the structure, I have added a wrapping div around the lists and headers with a specific class name.

For a working demonstration, see this link:

http://jsfiddle.net/Pf8eR/

Below is the corrected HTML markup:

<div class="column">
    <h2>First Column</h2>
    <ul>
        <li>First item</li>
        <li>Second item</li>
        <li>Third item</li>
    </ul>
</div>

<div class="column">
    <h2>Second Column</h2>
    <ul>
        <li>First item</li>
        <li>Second item</li>
        <li>Third item</li>
    </ul>
</div>

<div class="column">
    <h2>Third Column</h2>
    <ul>
        <li>First item</li>
        <li>Second item</li>
        <li>Third item</li>
    </ul>
</div>

And here is the corresponding CSS:

ul, li{
margin:0;
padding:0 0 0 15px;    
}

.column{
    float: left;
    margin: 0 20px 0 0;
}

Answer №2

The issue with the validator error messages stems from the fact that a ul element can only have li elements as children, and a span element should not contain a p element. (This is typically covered in most HTML tutorials.)

However, your list titles are more appropriately considered headings rather than paragraphs. Depending on the context, if this construct appears at the top level of hierarchy, using h2 would be suitable. This code snippet demonstrates the structure:

<div class=list>
<h2>Title 1</h2>
<ul>
<li>Item one
<li>Item two
<li>Item three
</ul>
</div>

Introducing an additional div element allows you to style the list and its heading as a cohesive unit. To achieve a desired result, you may consider implementing a stylesheet like the example provided below:

.list { width: 14%; float: left; }
.list h2 { font-size: 13px; font-weight: normal }
.list li { font-size: 10pt; line-height: 14px }
.list ul, .list ul li { margin: 0; padding: 0; }
.list ul, .list h2 { margin-left: 1.3em; }

It is advisable to place these styles in an external stylesheet or a style element to enhance readability and ease of maintenance. The specified font sizes in the example correspond to your current settings. Ideally, refrain from setting font sizes for list items and instead consider adjusting the font size of headings to a larger value relative to regular text, such as font-size: 115%.

Answer №3

Consider adding the following CSS code to your ul element.

ul{
display:inline-block;
vertical-align:top;
}

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

Issue with backdrop-filter blur effect not functioning correctly

I'm currently utilizing SCSS and within my _header.scss file, I am importing it into my main.scss like so: @use "header"; Here is the snippet of code from my header file (I've removed some less important details such as borders, margin ...

Enable the use of custom tags containing hyphens in the kses filter for WordPress

I developed a specialized Wordpress plugin that enables users to incorporate custom HTML element tags (such as <my-element>) into the content of a Post. This allows users without the unfiltered_html capability to utilize predefined custom tags. The ...

Code snippet that will emphasize the active page if there are multiple pages, such as highlighting page 2

My current project involves implementing a script to highlight the current page on a Tumblr blog. I found the script I am using here: $(function(){ $('a').each(function() { if ($(this).prop('href') == window.location.href) { ...

Issue with the flexbox div not fully occupying the vertical space

I can't seem to get flexbox to fill the spaces as I want it to. I've been trying to figure out what I'm missing, but I just can't wrap my head around it. Here's a recreation of the issue with a link to a codepen. I want the div in ...

Can you conceal the label while also displaying the placeholder?

Within my form, I am using the following code: <div id="zipcode-label" class="f-label"><label for="zipcode" class="required">Zip code</label></div> <div id="first-element" class="f-element"><input type="tel" class='ro ...

Replace the typical bootstrap text class with stylish and modern google material icons

As a newcomer to the world of javascript, I acknowledge that my approach may not be ideal... I'm attempting to modify the color of a material icon upon clicking it. Essentially, I want to toggle it on and off. The challenge lies in the code's in ...

Exploring the possibilities of applying CSS to customize the color of various elements

Is there a way to set the color of elements in CSS so that it applies to everything such as fonts, borders, and horizontal rules when applied to the body? How can I accomplish this effectively? ...

Toggle the visibility of a div depending on the user's selection

My HTML select element has a few options to choose from: <select class="form-control" data-val="true" data-val-number="The field CodeSetup must be a number." id="CodeSetup" name="CodeSetup"> <option selected="selected" value="0">AllCodes< ...

Change the width of specific <li> elements to create variation

My goal is to configure a ul element with varying widths using flex. Specifically, I want the first two items in the ul to be 60% width while the last two items should be 40%. However, my flex-basis property doesn't seem to be working as expected. ...

Is it feasible to modify a JavaScript value through the PHP GET method?

My HTML file contains the following JavaScript code: var a=["","#"] I want to append a value after the # symbol by specifying that value in the website URL. For example: site.com/#value Therefore, the updated JavaScript code will be: var a=["","#va ...

My code gets disrupted when I switch between ids and classes

I'm currently learning about javascript and jquery, attempting to implement various scripts. I successfully executed the following script: jQuery(document).ready(function($) { var scroll_start = 0; var startchange = $('#homepage-header' ...

Using JSON to serialize form data before sending it in HTML

I am in the process of developing a system that requires redirecting a user to a C# application using a form that POSTs data as a serialized JSON string along with the user. The form would be structured like this: <form action="c#methodLocation" metho ...

Tips for creating a hidden tab that only appears when hovered over

When hovering over the link tag .cat-link a.navlink, each subcategory tab .subcategories div is displayed. However, I would like to hide all tabs initially and have them appear only when hovered over with the mouse. Once the mouse is removed, I want the t ...

Global variable appears undefined in Angular 2 view, yet it is still displaying

I'm running into issues with my Angular 2 code. Inside my ts file, I have the following: import { Test } from '../../../../models/test'; import { TestService } from '../../../../services/test.service'; import { Job} fr ...

Replicating a row in a table without disrupting a button within the row

As a novice in the world of coding, I am currently embarking on a project to revamp an existing website. The task at hand involves creating a table with a built-in save/edit feature, which I have successfully implemented. However, I am facing a roadblock w ...

Achieving perfect center alignment for the middle element with flexbox

When it comes to the layout below, my objective is to always keep the middle item centered within the container div. This means that the left and right items should be aligned to the far left and right of the container respectively. The current styling fo ...

Utilizing Custom Script Tag Types in Visual Studio for Enhanced HTML Template Functionality and Improved Syntax Highlighting

Currently, I am utilizing Visual Studio 2012 for editing HTML and JavaScript. My approach involves inserting templates using partial views in inline script tags (view code below). The use of AngularJS, a Javascript framework, dictates that the type must be ...

Guide on showcasing jQuery variable values in PHP on a single page

I have some JavaScript and PHP code that I need help with. I want to assign a jQuery variable value to a PHP variable called $nicks, and then echo the value of $nicks on the same page. <script type="text/javascript"> var axel = 131.5678466; < ...

Pressing the 'Enter' key within a textarea in a JQuery

This question seems fairly straightforward. I have a text area where hitting "enter" submits the content. Even though I reset the text to "Say something..." after submission, the cursor continues to blink. Is there a way to require the user to click on ...

Are the maps intersecting within the field of vision?

I have 2 components in my angular application each showing a map from mapbox. Here is the code for one of the components: Component import { Component, OnInit } from '@angular/core'; import * as mapboxgl from 'mapbox-gl'; @Component( ...