What is the best way to create a 3-column nested list with only inner gutters and no external margins?

I'm currently facing an issue with aligning my nested list properly within the rest of my content. The website I'm working on uses semantic.gs grid, which you can view here: . The problem arises at the bottom where the nested list doesn't align with the black line above or the "slideshow" div. There appears to be a small gap on both the left and right sides of the outer lists, especially noticeable when resizing the browser window.

Any tips or tricks on how to address this issue? I tried using CSS3 columns to eliminate the gap, but they have compatibility issues across different browsers. Is there a workaround to make them work universally? Or perhaps another method to exclusively apply inner margins to the list items? Should I consider opting for CSS3 columns with a fallback for Internet Explorer instead?

Here's the HTML snippet:

<article id="memberContainer">
    <ul id="memberList">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
    </ul>
 </article>

CSS(/LESS) code:

 @columns: 12;
 @column-width: 81;
 @gutter-width: 19;
 @total-width: 100%;

    #memberContainer {
    .border;
    ul#memberList {
      .row(9);
      li {
        .column(3,9);
        margin-top: 1em;
      }
    }
  }

You can access the semantic.gs grid I'm utilizing from this link: https://github.com/twigkit/semantic.gs/blob/master/stylesheets/less/grid.less

Thank you for any assistance!

Answer №1

If you want to remove the margin from the first and last li elements, you can use the css3 selectors :first-of-type and :last-of-type.

Here is an example in less:

ul#memberList {
    li{
        &:first-of-type, &:last-of-type{
             margin-left:0; 
             margin-right:0;
        }
    }
}

You can find more information about these selectors here. The last of type selector works similarly.

Keep in mind that if you have a wrapped list, you need to know the number of elements per row upfront. In this case, you can use the nth-child selector or the nth-of-type selector.

For example:

ul#memberList {
    li{
        &:nth-of-type(3n){
            margin-left:0; 
            margin-right:0;
        }
    }
}

This should help you achieve your desired result.

Answer №2

Have you experimented with using :first-child and :last-child? You can find more information about them at (http://www.quirksmode.org/css/firstchild.html)

This is what I believe the code should look like:

ul#memberList {
    li{
        &:first-child, &:last-child{
             margin-left:0; 
             margin-right:0;
        }
    }
}

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 method for locating the innermost element of an HTML tree that has a specific class assigned

I am working on a project that involves a menu system. One of the features I am implementing is that when a tree within the menu is opened, it receives the "active" class. My goal now is to dynamically retrieve the deepest sub-menu within this structure ...

Trouble with executing select query on connected tables in MySQL

$sql=mysql_query("SELECT b.book_id,u.user_id,user_name,book_name,review_date,book_rating,review FROM tbl_books b,tbl_user u,tbl_book_reviews br WHERE b.book_id=br.book_id AND u.user_id=br.user_id ...

What is the best way to retrieve the previously chosen value from one dropdown and populate it into another dropdown when

I have 3 choices available. When the user selects the third option, a jQuery onchange event is triggered to send the variable to another PHP file for database validation based on the selected id. The challenge lies in how I can also include the variables f ...

Is it possible to center my content without needing to use a hover effect?

My layout consists of four columns, each contained within a different div. The fourth column is set to appear only upon hovering over it. However, when I mouseover the fourth column to make it appear, the data from the first column ends up transferring ove ...

What is the best way to create an HTML template with a table where the first column is divided into four cells and the second column only has one

Currently, I am working on a template using HTML and CSS. One issue that I am facing involves designing a table template with HTML and CSS. The specific problem occurs in the second row of the table where there are 4 cells in the first column and only one ...

Enhance conditional attributes for Meteor user sessions

Currently working with Meteor alongside Iron-router. I've recently made adjustments to be compatible with the 0.8 update, but I'm encountering some challenges. Instead of embedding conditional attributes within a div in HTML, I have transitioned ...

Display the current position of the caret in a field that cannot be edited

Can a virtual caret be displayed between two letter boundaries in HTML/CSS/JavaScript, for example in a regular div without using contenteditable=true? Imagine having the following: <div>Hello world</div> If I were to click between the "w" a ...

Conceal elements with a single click of a button

How can I use jQuery to hide all li elements with an aria-label containing the word COMPANY when the Search from documents button is clicked? Here is the HTML code: <ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content" id="ui-id-1" t ...

Is there a way to create automatic line breaks in this text?

Is there a way to automatically ensure the span spans multiple lines? I am working with HTML and CSS. Below is a modified version of my code, as some parts are in PHP: <div style='border: 1px solid; padding: 10px; margin-top: 5px;'> < ...

Firefox won't trigger the `beforeunload` event unless I interact with the webpage by clicking on it

In my quest to handle the beforeunload event in Firefox, I've encountered a small hurdle. It seems to be working smoothly, but only if the user physically interacts with the page by clicking on it or entering text into an input field. Below is the co ...

Learn how to incorporate a newly created page URL into a customized version of django-oscar

Just starting out with django-oscar and trying to set up a new view on the page. I've successfully created two pages using django-oscar dashboard, https://ibb.co/cM9r0v and added new buttons in the templates: Lib/site-packages/oscar/templates/osca ...

I seem to be having some issues with the functionality of .not() and it's

I am working on creating a menu that remains open for a set amount of time and then fades out if neither the parent nor the menu is hovered over. The goal is to have all other menus close when hovering over a new parent in the menu, but the current code k ...

What is the method for adjusting the border color of an ng-select component to red?

I am having an issue with the select component in my Angular HTML template. It is currently displaying in grey color, but I would like it to have a red border instead. I have tried using custom CSS, but I haven't been able to achieve the desired resul ...

How can I insert an image into a circular shape using HTML and CSS?

To achieve the desired effect, the image should be placed inside a circle with a white background. The image size should be smaller than the circle and centered within it. One possible way to accomplish this is: .icon i { color: #fff; width: 40px; ...

Contrasting the addition of an onClick listener through Jquery versus utilizing an HTML onclick attribute

I found this interesting piece of code that I want to share with you all: <!DOCTYPE html> <html> <head> <script type="text/javascript" src="jquery-1.12.4.js"></script> <title> HelloWorld JQuery </t ...

Appropriate application of section, article, and heading conventions

Recently, I created a complex liquid slider that serves as the header for my website. This slider contains various important content elements like heading tags (h-tags), paragraph tags (p-tags), and images. I found myself pondering whether each individua ...

The button is positioned at the bottom right within a div surrounded by text that flows around it seamlessly

Image Is there a way to position a button in the bottom right corner of a div with a fixed height that is filled with text where the text flows around the button? I have attempted using "float" and positioning the button, but I have not had any success. ...

Are there any performance implications when using an excessive number of background images in CSS?

My website seems to be running too slowly based on user reports. I suspect that the background images in CSS may be causing the issue. The site uses a custom build system to concatenate and compress all CSS, create CSS sprites automatically, resulting in ...

Shift the image down to the bottom of the sidebar

This is the code for my sidebar HTML, with the side navigation bar positioned on the left: #main-container { display: table; width: 100%; height: 100%; } #sidebar { display: table-cell; width: ...

In order to work with the optionSelectionChanges property of the MdSelect directive in Angular Material2, it

Within my application, there is a Material2 select dropdown widget containing several options. app.component.html <md-select placeholder="Choose an option" [(ngModel)]="myOption" (optionSelectionChanges)="setOptionValue(myOption)"> &l ...