Exploring the challenges of applying styles to buttons using the :first-child and :last-child selectors, especially when

I successfully applied rounded corners to the first and last elements of a styled button using CSS.

Here is how it looks:

The issue arises when I dynamically insert new buttons using Angular's ng-if. The new buttons disrupt the rounded corners of the first and last child elements. For example, here is the same image with additional buttons added under specific conditions:

As shown in the image above, introducing dynamic buttons through ng-if causes problems with the rounding.

How can I modify the code so that the rounded corners of the first and last children remain intact even when dynamic buttons are added or removed? I prefer not to manage two separate lists based on ng-if, but instead maintain one list with conditional elements.

The original HTML code snippet:

<div id="flyoutmenu" style="float:left">
                <ul>
                    <li>
                        <a href="" ng-click="sliderChanged(1)"> <i class="ion-plus-circled"></i></a>
                    </li>
                    <li>
                        <a href="" ng-click="sliderChanged(-1)"> <i class="ion-minus-circled"></i></a>
                    </li>
                    <span ng-if="isDragabillyOn">
                        <li>
                            <a href="" ng-click="hideMonitor(monitor.Monitor.Id)"> <i class="ion-close-circled"></i></a>
                        </li>
                        <li>
                            <a href="" ng-click="toggleStamp()"> <i class="ion-pin"></i></a>
                        </li>
                    </span>
                </ul>
            </div>

The CSS styles being used:

#flyoutmenu ul {
    list-style: none;
    margin: 0;
    padding: 0;
    color: white;
    z-index: 99;
    font-size: 0.7em;
    font-family: sans-serif;
    text-transform: uppercase;
}

#flyoutmenu ul li a i {
    font-size: 2.5em;
    font-family: sans-serif;
    text-transform: uppercase;
}

#flyoutmenu li {
    display: inline-block;
    margin-bottom: .2em;
    padding: 0.7em;
    margin-right: 4px;
    line-height: 100%;
}

#flyoutmenu li:first-child {
    /*background: rgba(192, 57, 43, 0.7);*/
    background: rgba(108, 122, 137, 0.7);
    -webkit-border-radius: 5px 0 0 5px;
}

#flyoutmenu li:only-child {
    /*background: rgba(192, 57, 43, 0.7);*/
    background: rgba(108, 122, 137, 0.7);
    -webkit-border-radius: 5px 5px 5px 5px;
}

#flyoutmenu li:last-child {
    -webkit-border-radius: 0 5px 5px 0;
}


/* Ensure this rule follows last-child */

#flyoutmenu li:only-child {

    background: rgba(108, 122, 137, 0.7);
    -webkit-border-radius: 5px 5px 5px 5px;
}

#flyoutmenu li:nth-child(n+2) {
    background: rgba(108, 122, 137, 0.7);
    z-index: -1;
}

Answer №1

Ensure all list items share the same parent by removing the span. Then include ng-if directives within each list item.

                    <li ng-if="isDragabillyOn">
                        <a href="" ng-click="hideMonitor(monitor.Monitor.Id)"> <i class="ion-close-circled"></i></a>
                    </li>
                    <li ng-if="isDragabillyOn">
                        <a href="" ng-click="toggleStamp()"> <i class="ion-pin"></i></a>
                    </li>

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

Navigating within two containers using the anchorScroll feature in AngularJS

I am trying to create a page with two columns of fixed height. The content in each column is generated using ng-repeat directive. Is it possible to implement scrolling within each column to a specific id using AngularJS? Code <div> Scroll to a p ...

Twofold Arrow Styling in CSS

Can someone help me achieve this design: https://i.stack.imgur.com/eBQ1a.png I am attempting to create a double arrow using just one class. I have tried various methods, but nothing seems to be working for me. If anyone has any suggestions or can point ...

CSS does not have the capability to style child elements

Having trouble changing the text for child elements when applying CSS classes to parent elements. Is there a specific reason why this is happening? Take a look at my current code: <Box //not affecting all child elements ...

Is it better to use relative or absolute resource scripts in an AngularJS application?

My project involves building a single-page JavaScript app using AngularJS. In order to achieve this, the index.html file has a specific structure: <html> <head> <base href="/" /> ... </head> <body id="ng-app" ng-app="myAngularAp ...

"Trouble with Angular JS foreach loop: only the final item in the array

Struggling to loop through each item object in a JSON data set and evaluate its value using angular.forEach(). However, only the last item is being returned, making it impossible to perform any meaningful evaluation. Oddly enough, when using console.log(), ...

Encountering a peculiar problem with the Bootstrap Carousel where the first slide fails to load

There seems to be an issue with the bootstrap carousel where the first slide appears empty initially, but once you slide to the second slide it starts working fine. Navigating through all slides is still possible. <div id="mediakit_carousel" class="car ...

Arrange text and a button side by side in a table cell using an Angular directive and an HTML template

I have successfully implemented an Angular search function on my project. You can find it here to allow users to search for courses. The search function uses a read-more directive that displays a preview of the description and keywords before allowing use ...

Converting CSS code into JavaScript

I am currently working with the following code: .mr15 > * margin-right: 15px &:last-child margin-right: 0 I need help translating this code to Javascript. Should I use JQuery or pure Javascript for this scenario? Thank you. ...

Guide to linking a label to a checkbox without utilizing the "for=id" method

Below is the code snippet I am currently working with: <li><input type="checkbox" id="checkboxThree" value="Alergia3" ><label for="checkboxThree">Alergia 1</label></li> <li><inp ...

Adding an overlay to a material UI table row: Step by step guide

My code is rendering a row in the following format: `<TableRow key={row.name} > <TableCell>{row.empId}</TableCell> <TableCell>{row.userId}</TableCell> <TableCell>{row.name}</TableCell> <TableCell>{r ...

Two CSS Issues - One specific to mobile devices, the other unique to Chrome browser

Having trouble with the top banner not stretching all the way on iPhone. Any solutions? Here's a screenshot for reference: Below is the CSS applied to the div: #banner { background-color: #F7F7F7; background-size: cover; box-shadow: 0 0 ...

Ways to solely add effect to background image without affecting text

I'm on a quest to find a way to create a CSS effect that only applies to an image, excluding the letters and buttons. I need to establish a rule in my CSS without altering the current structure. The issue arises when my code ends up applying the effec ...

The white-spaces in Quill JS do not retain their original formatting

I recently integrated Quill JS editor into my website. During testing, I noticed that any text inputted after a white space gets emitted when alerting the content. Below is the HTML code snippet: <div id="postCommentEditor" class="postCo ...

The modal popup will appear in the center of the screen when the scrollbar is positioned at the top

I have a modal popup that is not consistently displayed in the center of the screen, regardless of the scrollbar position. I always want it to render at the center so the user doesn't need to scroll to see it. Below is the code I am currently using: ...

Dynamically updating the scroll area in Ionic using real-time data

Hello, I am currently working on an Ionic project and have created a code pen for it. At the moment, the code pen just displays an image with two buttons for zooming in and out. However, I have encountered an issue. When I click on zoom in and scroll to ...

Issue with tile size or alignment in Safari

Recently, while creating my portfolio on CodePen, everything was running smoothly except for one little hiccup - Safari. http://codepen.io/tpalmer75/pen/FijEh (SASS for just one .item element) .item width: calc(100% / 3) display: inline-block height ...

Whenever the Web Developer console in Firefox is activated, Angular.js experiences a sudden malfunction and stops functioning properly

I'm encountering a strange issue with Angular.js (1.2.27) where it fails to function properly when the web developer console is open in my Firefox browser and I refresh the page. The problem persists even if I open the console while Angular.js is alre ...

Pressing the icon will trigger a top-sliding dropdown mobile menu to appear

How can I ensure my mobile dropdown menu slides in from the top when the user clicks the "header-downbar-menu" icon and slides out to the top when clicked again? Currently, the button only shows the menu but I am struggling with writing the JavaScript for ...

Transforming the mui stepper connection into a progress bar is simple. Each step contains individualized content to guide you through the process

Is there a way to make the MUI stepper connector act as a progress indicator? I have step content and connectors as separate divs, but I'm having trouble styling them. Any assistance would be greatly appreciated! ...

Utilizing Jquery-Menu-Aim to assign values to child scopes

Currently, I am in the process of developing a directive for jQuery-menu-aim. While my current implementation is functioning as intended, I can't help but feel that finding and setting values on the child scope seems like a workaround. You can view m ...