Styling a table of contents with CSS can be a tedious task, especially when dealing with pesky

I need help refining a CSS table of contents I'm working on. Despite receiving assistance previously, the final result is still incorrect and requires multiple workarounds. An image comparing the original table of contents with my recreation attempt is provided below.

The issue lies in the text "A REVIEW OF THE PRINCIPAL QUESTIONS IN MORALS" wrapping after "IN" instead of after "QUESTIONS".

Below is the current CSS code:

.list li {
    position:relative;
    overflow:hidden;
    width:360px;
}
.list li:after {
    font-size:120%;
    content:"...............";
    text-indent:1px;
    display:block;
    letter-spacing:40px;
    position:absolute;
    left:1em;
    bottom:0px;
    z-index:-1;
    font-weight:bold;
}
.list li span {
    display:inline;
    max-width:100px;
    background-color:#fff;
    padding-right:12px;
}
.list li .number {
    float:right;
    font-weight:bold;
    padding-left:15px;
}
.two-lines {
    text-indent:-.9em;
}
.list .two-lines:after {
    text-indent: 1px;
}
.two-lines .number {
    bottom:0px;
    right:0px;
    padding-right: 1.2em;
}

The current CSS structure seems messy. A jsfiddle link for reference can be accessed here.

I am seeking advice on resolving the text wrapping issue while also improving the cleanliness of the CSS code. Any suggestions would be greatly appreciated.

Answer №1

Although this question is four years old, I acknowledge that this answer may not be relevant to you now. However, a simple <br> after "Questions" should resolve your wrapping issue.

The misalignment of your wrapping with the image is likely due to font variations and width differences. Unfortunately, achieving this effect purely through CSS without compromising responsiveness or multiuse code seems challenging. In this case, a hard-coded solution should suffice as it appears to meet your requirements.

.list li {
    position:relative;
    overflow:hidden;
    width:360px;
}
.list li:after {
    font-size:120%;
    content:"...............";
    text-indent:1px;
    display:block;
    letter-spacing:40px;
    position:absolute;
    left:1em;
    bottom:0px;
    z-index:-1;
    font-weight:bold;
}
.list li span {
    display:inline;
    max-width:100px;
    background-color:#fff;
    padding-right:12px;
}
.list li .number {
    float:right;
    font-weight:bold;
    padding-left:15px;
}
.two-lines {
    text-indent:-.9em;
}
.list .two-lines:after {
    text-indent: 1px;
}
.two-lines .number {
    bottom:0px;
    right:0px;
    padding-right: 1.2em;
}
<div style="width: 401px; padding-left: 90px">
    <div style="margin:25px 0 200px 0">
        <div style="text-align:center;font-size:150%;letter-spacing:.2em;margin-bottom:10px;margin-right:-.2em;">CONTENTS</div>
        <ul class="list" style="padding-left:22px;">
            <li style="margin:0 0 .6em 0;"><span>EDITOR&rsquo;S INTRODUCTION</span><span class="number">ix</span>
            </li>
            <li style="margin:0 0 .5em 0;"><span style="padding-left:.9em;">1. Historical</span><span class="number">ix</span>
            </li>
            <li style="margin:0 0 .5em 0;"><span style="padding-left:.9em;">2. Epistemology</span><span class="number">xii</span>
            </li>
            <li style="margin:0 0 .5em 0;"><span style="padding-left:.9em;">3. Epistemology of Morals</span><span class="number">xx</span>
            </li>
            <li style="margin:0 0 .5em 0;"><span style="padding-left:.9em;">4. Psychology of Morals</span><span class="number">xxvi</span>
            </li>
            <li style="margin:0 0 .5em 0;"><span style="padding-left:.9em;">5. The Moral System</span><span class="number">xxx</span>
            </li>
            <li style="margin:0 0 1.5em 0;"><span style="padding-left:.9em;">6. Morals and Theology</span><span class="number">xliii</span>
            </li>
            <li style="margin:0 0 .5em 0; padding-left:.9em;" class="two-lines"><span>A REVIEW OF THE PRINCIPAL QUESTIONS<br> IN MORALS</span><span class="number" style="padding-left:2em;">1</span>
            </li>
            <li style="margin:0 0 .5em 0;"><span style="padding-left:.9em;">INDEX</span><span class="number">297</span>
            </li>
    </ul>
</div>
</div>

You mistakenly used a </div> instead of a </ul>.

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

What is the best way to showcase nested array information from a JSON file on an HTML webpage?

students.json { "students": [ { "studentname": "Rohit Kumar", "grade": "A", "student": [ { "SNo": "1", "Subject": "Maths", "Concept": "Numbers" }, { "SNo": "2", ...

Performance Issues Arise with Rapid Clicking [jQuery]

Having trouble with a gallery script I created that includes thumbnails, a large image, and navigation arrows. When you rapidly click on thumbnails or arrows during the transition, it causes delays in the process. The more clicks you make, the more noticea ...

Display identical text using JavaScript filter

My search filter highlight is currently displaying [object Object] instead of <mark>match values</mark> when replacing the values. This is the code I am using: this.countries.response.filter((val) => { const position = val.value.toLowerCa ...

translating xpath code into css styling

Can you help me with converting this xpath to css? By.xpath("//div[@id='j_id0:form:j_id687:j_id693:j_id694:j_id700']/div[2]/table/tbody/tr/td"); I've tried a couple of options, but none of them seem to work: By.cssSelector("div[@id=&apos ...

What is the best way to add a color swatch image using Javascript?

I'm facing a challenge in Shopify where I need to assign corresponding background images to color swatches. Currently, my icons are set up with the correct links for each color, but they are missing their respective images, similar to this example. I ...

React - Render an element to display two neighboring <tr> tags

I'm in the process of creating a table where each row is immediately followed by an "expander" row that is initially hidden. The goal is to have clicking on any row toggle the visibility of the next row. To me, it makes sense to consider these row pa ...

Create a div element using JQuery mobile

I am experiencing an issue where a div on my webpage is supposed to refresh every 3 seconds, but the CSS is not being rendered correctly after each refresh. Below is the code I am using: HTML: <div id="statusbar"></div> JavaScript: $( docu ...

Showcasing a separate website within an iframe

My iframe is not displaying the other website on my webpage. Can anyone suggest an alternative method using either iframe, div or simple JavaScript to achieve this? Any help would be greatly appreciated. I have attempted using an iframe but it doesn' ...

Design featuring a fixed top row and a scrollable bottom row

I need to divide a div container into two vertical sections, one occupying 60% of the space and the other 40%. The top div (60%) should always be visible, while the bottom div (40%) should be scrollable if it exceeds its limit. I have tried different app ...

Are you facing a problem with the navigation buttons for playing the next and previous

After setting the title of the video, it initially appears for a brief moment but then disappears once each video has finished playing. Interestingly, everything functions as expected when the play-next/prev buttons are not activated. However, if I rapid ...

Is there a way in Python to extract the Address IDs that contain 'ACT' from this turtle file?

As a newcomer to the Semantic Web, I am eager to extract address IDs containing 'ACT' from a webpage, save the information in RDF structure, and store it in a database for future reference. Here is the code snippet I have used: import requests ...

What is the best way to zip two arrays of different lengths so that they can be looped through in a Django

Two arrays are at my disposal: First array: ['Tan','Goh','Tio'] Second array: [['Honda','Toyota','Proton'],['Toyota'],['Proton','Lambo']] Is there a way to merge ...

I'm trying to integrate a chatbot into my website using Node-RED. Can someone guide me on how to utilize the Bluemix Tone Analyzer to analyze the tone of the user

Creating a chat bot to ask psychological questions and analyze how a person is feeling has been my recent project. I managed to set up a chat bot in Bluemix, following a tutorial on integrating it into Node Red: https://github.com/watson-developer-cloud/no ...

Incorporating both an href link and PHP code using a single click event on a submit button

After exploring various forums, I am still struggling to solve this issue. Can someone please assist me in understanding how to achieve this? When I click the submit button, it currently directs me to a file location via a link without any issues. Howeve ...

how can I pass a group of values as an argument in math.sum function?

Using math.js for convenience, I was intrigued if I could utilize the math.sum method to calculate the sum of a collection of input values. For example, something along the lines of: Here's a snippet of code to help visualize my concept: $(documen ...

How come the <script> element is showing up in the <body> tag even though I initially declared it outside the <body>

I'm currently working on web projects through the Odin Project and I want to follow the software engineering process by taking small steps and testing them. Specifically, I'm interested in seeing the output of document.querySelector("body"). I kn ...

Tips for implementing a jQuery plugin on specific elements within an HTML page

I've been experimenting with the jQuery extension for searchable dropdowns available at this link. While I am impressed with its functionality, I'm looking to apply it selectively to specific elements on my webpage rather than all of them. Is the ...

Customize Joomla content in a component by using CSS within a template that I personally designed

Is there a way to customize the text content of a component in Joomla by editing the body text? The CSS properties for #content are adjusting padding, margin, border, width, height, and background but not affecting font attributes... Inside index.php < ...

Employ the CSS pseudo-element :before within a UL element to generate a vertical line

I'm currently working on a vertical menu with the capability of having submenus. My aim is to include a vertical line using CSS pseudo-element ::before along with border. The challenge I'm encountering is that the CSS is applying to the entire m ...

The Bootstrap 5 navigation bar fails to expand properly on mobile devices

I am currently developing a website using Bootstrap 5, but I am facing an issue with the navbar. The problem occurs when viewing the website on mobile devices as the navbar does not expand properly. @import url('https://fonts.googleapis.com/css2?famil ...