What's the best way to expand the right side of .li following a left offset of -20px

My nested list structure looks like this...

https://i.sstatic.net/sggVx.png

What you see is a recursive ul/li setup...

<div class="family d-block">
   <span class="pb-2"> <small class="text-muted">Family:</small><br>
   </span> 
   <span class="small">
      <span><img
         src="https://www.google.com/s2/favicons?domain=wpp.com" width="12"
         class="mr-2"><a
         href="http://www.example.com/organisation/wpp/">WPP</a></span>
      <ul>
         <li><img
            src="https://www.google.com/s2/favicons?domain=null" width="12"
            class="mr-2"><a
            href="http://www.example.com/organisation/wpp/24-7-realmedia/"
            title="View all products in 24/7 realmedia">24/7
            realmedia</a>
         </li>
         <li><img
            src="https://www.google.com/s2/favicons?domain=akqa.com" width="12"
            class="mr-2"><a
            href="http://www.example.com/organisation/wpp/akqa/" title="View
            all products in akqa">akqa</a></li>
         <li>
            <img
               src="https://www.google.com/s2/favicons?domain=groupm.com"
               width="12" class="mr-2"><a
               href="http://www.example.com/organisation/wpp/groupm/" title="View
               all products in GroupM">GroupM</a>
            <ul>
               <li><img
                  src="https://www.google.com/s2/favicons?domain=finecast.com"
                  width="12" class="mr-2"><a
                  href="http://www.example.com/organisation/wpp/groupm/finecast/"
                  title="View all products in Finecast">Finecast</a></li>
               <li><img
                  src="https://www.google.com/s2/favicons?domain=null" width="12"
                  class="mr-2"><a
                  href="http://www.example.com/organisation/wpp/groupm/group-m-entertainment/"
                  title="View all products in group m entertainment">group m
                  entertainment</a>
               </li>
               <...more list items...>
            </ul>
         </li>
         <...more list items...>
      </ul>
   </span>
</div>

... Now with i) bullets removed and ii) each list item shifted to the left (as I thought the original indentation was excessive)...

.family ul {
  list-style: none;
}
.family ul li {
  position:relative;
  left:-20px;
}

However, the issue with shifting list items left is that the text width does not extend to the right edge, causing premature wrapping.

By toggling the left: -20px; property, the difference becomes clear...

https://i.sstatic.net/uLRIY.gif

So, how can I fix the text width extension issue on the right side (highlighted in red)?

I am open to changing the current method of left-shifting list items, as long as the effect is retained.

I am also willing to use Bootstrap 4/flex classes if they can address this problem.

Answer №1

Understanding your query, it seems altering the strategy as shown below (with visual indicators for clarity) is what you need. Consider adding some basic ARIA attributes for accessibility;

<nav role="navigation">
   <ul role="tree">
      <li role="treeitem">Parent</li>
      <li role="treeitem">Parent
         <ul role="tree">
            <li role="treeitem">Child</li>
            <li role="treeitem">Child</li>
         </ul>
      </li>
      <li role="treeitem">Parent</li>
   </ul>
</nav>

Hoping this tweak is beneficial. Cheers!

.family ul {
  list-style: none;
  border: red 1px dotted;
  margin: 0;
  padding: 0;
}

.family ul li {
  border: green 1px dotted;
  margin-left: 1rem;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">


<div class="family d-block">
   <span class="pb-2"> <small class="text-muted">Family:</small><br>
   </span> 
   <span class="small">
      <span><img
         src="https://www.google.com/s2/favicons?domain=wpp.com" width="12"
         class="mr-2"><a
         href="http://www.example.com/organisation/wpp/">WPP</a></span>
          <ul>
          (Nested list of organizations within the WPP family)
          </ul>
   </span>
</div>

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

`Using Twitter Bootstrap in mobile app development with javascript`

I have been utilizing Twitter Bootstrap 2.3 on one of my websites and I appreciate its responsiveness and use of media queries for mobile devices. However, I have noticed a lack of mobile-specific features, particularly linked listviews. In order to addres ...

Creating interactive <td> elements in HTML with JavaScript editor capabilities

Currently, I am working on creating an editable table feature and managed to find a good example to follow. However, I have encountered some issues along the way. <td contenteditable="true" class="hover" onBlur="saveToDatabase(this,'question' ...

A div positioned to the left is placed beneath another div

I am faced with a design challenge involving two divs. The first div is floated left, while the second div is floated right. In order to achieve a responsive layout, I need the first div to go under the second div when the viewport changes. Both divs conta ...

Ensure that both the div element and its contents are restricted to a maximum width of

I'm having trouble arranging the display of information next to a plant image. I want to ensure that the information stays on the right side of the image when the screen reaches a specific minimum width. The issue arises when the information includes ...

A guide on transforming a 1-dimensional array into a 2-dimensional matrix layout using Angular

My query revolves around utilizing Template (HTML) within Angular. I am looking for a way to dynamically display an array of objects without permanently converting it. The array consists of objects. kpi: { value: string; header: string; footer: string }[] ...

"Enhance Your Video Experience with a Personalized Play Button

Is it possible to customize the play icon for an embedded YouTube video? I came across a post discussing this topic: Can I change the play icon of embedded youtube videos? However, when trying to use something transparent as the new play button, the origin ...

Description positioned along the edge of the image

Is it achievable in Bootstrap 4.1 to have the caption aligned with the image margin as displayed in the image below? Illustration of aligning caption with image Following the sample at getbootstrap.com, there exists a discrepancy between the caption and ...

The like button animation works perfectly for individual posts, but for multiple posts, only the like button on the first post

Having an issue with the like button code on a single news feed. The button works for the first post, but when clicking on other posts, it only affects the first post button. I am using post UI and looping the UI based on the total post count without Javas ...

Issues with button hover causing background transition difficulties

I've been trying to achieve a smooth background image transition upon hovering over my buttons. Despite searching for solutions in various posts, I haven't been successful in applying any of them to my code. I realize that J Query is the way to ...

Is it possible to refresh the chat-box using PHP?

I recently created a chat box application using PHP, but I'm facing an issue with its automatic reload functionality. Is there a way to implement auto-reload in PHP itself, or would it be better to restructure the system to utilize AJAX? Additionally, ...

Enhancing websites with font-awesome icons and upgrading from older versions to the latest

Seeking guidance on updating our project to use the latest Macadmine theme. The transition from Font Awesome 3 to Font Awesome 4 requires changing all icons to their proper names. I came across a helpful resource at https://github.com/FortAwesome/Font-Aw ...

Enhance your user interface with an interactive Bootstrap dropdown using Angular

I have a program where users can choose from 3 options such as: Hi, Hello and Hey. Currently, when a user selects one of the values, they receive a message saying that they need to "select a value." I am struggling to figure out how to update the ng-model ...

What is the best way to make an HTML table with a static header and a scrollable body?

Is there a way to keep the table header fixed while allowing the table body to scroll in an HTML table? Any advice on how to achieve this would be greatly appreciated. Thanks in advance! ...

Is there a way to ensure that this ajax code functions seamlessly with all types of HTML files?

Currently, I am facing a challenge with an ajax call that retrieves data from a database, which I need to load into an HTML file. The issue lies in the fact that I have various HTML files and I am unaware of their contents. Despite spending countless hour ...

Extracting data from a tiered website within a specialized niche

I am currently attempting to scrape data from the webpage: "https://esco.ec.europa.eu/en/classification/skill_main". Specifically, I want to click on all the plus buttons under S-skills until no more plus buttons can be found, and then save the page source ...

an issue encountered while trying to print a webpage styled with CSS

Users are given the option to print the current page on the website by clicking on a menu element: <li> <a href="#" onClick="window.print()"> <i class="icon-print"></i> Print Page </a> </li> The page contai ...

Tips on how to hold off the display of webpage content until all elements, including scripts and styles, have fully loaded

I have a variety of div elements set up like this - <div id='1' class='divs_nav'>My Dynamic Content</div> <div id='2' class='divs_nav'>My Dynamic Content</div> ... <div id='149' c ...

The CSS styles for a:link, a:active, and a:visited do not seem to work with

My page contains the following CSS rule: a:link,a:active,a:visited{text-decoration:none;} I have encountered an issue where this rule is not working as expected. To apply the rule within a div with the id="test", I had to modify the rule like this: #tes ...

Tips for keeping certain webpages from showing up in Google search results

I recently launched a website that allows users to create their own profiles. The problem is, when someone links to their profile from their website or blog, it ends up showing in Google searches for my site. Unfortunately, the only person who has done thi ...

Safari IOS experiencing issue with element disappearing unexpectedly when input is focused

I am facing a situation similar to the one discussed in the question (iOS 8.3 fixed HTML element disappears on input focus), but my problem differs slightly. My chatbox iframe is embedded within a scrollable parent, and when the iframe is activated, it exp ...