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:

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

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:

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

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

Offspring of the superior element resting above another element

I'm dealing with a unique situation involving the Z-INDEX property. Check out my HTML setup below. <div class="player"> <div class="player-line"> <div class="player-handle"></div> <!-- /.player-handle --> </d ...

The Vuetify rating system seems to be having trouble displaying

I've integrated the Vuetify rating component into my app (https://vuetifyjs.com/en/components/ratings#ratings), but I'm facing an issue. Despite having Vuetify 1.5.5 installed and working with other components like buttons, the stars in the ratin ...

"Obtain a DOM element within an Angular directive by using the jQuery find method

When inspecting the DOM, I can see the element anchor tag present but cannot retrieve it using jquery.find(). The console returns a length of 0, preventing me from initializing angular xeditable on that element. angular.module('built.objects') ...

Using more than one class at a time is causing issues

Essentially, I have a div and I want to create an exercise where I apply three different classes using vue.js. I attempted to use v-bind:class, specifically :class, but can I bind a class directly from CSS? This is what I tried: html <div :style="[my ...

Ensure that the file exists before including it in the $routeProvider template for ng-include

Using Angular routes, I have set up a system where the slug from the URL determines which file to load. The code looks like this: $routeProvider.when("/project/:slug", { controller: "ProjectController", template: function($routeParams){ return & ...

Attempting to extract the text within a table row cell by clicking on the cell directly following it

I am trying to extract the data from a table row when I click on a specific div within that row HTML: <td class="ms-cellstyle ms-vb2">10</td> <td class="ms-cellstyle ms-vb2"> <div class="ms-chkmark-container"> <div ...

Tips for retrieving formatted text layout from the database

I recently encountered an issue when adding text to my MySQL database using a textarea. The format of the text, including newlines and spaces, was saved in the database but not displayed as such when viewed directly. When I retrieve this string from the da ...

Styling is lost in FancyBox popup when loading Partial View

I've been attempting to incorporate a partial view into my MVC project using fancybox. It seems to be loading the content correctly, mostly anyway, as it tends to cut off part of the page and loses all styling from the view upon loading. Even after i ...

Tips for creating a responsive div that contains both an image and description, including automatically resizing the image to fit the

#content { background-color: #ACAE4C; float: right; display: inline-block; padding: 0; } <div id="content"> <div class="pic"></div> <div class="desc"></div> </div> I need assistan ...

"Encountering problem with Angular HTTP services: the requested URL is not

Attempting to send data to API servers is resulting in a 404 error. Testing it on Postman shows that everything works fine. JSONP is being used for posting data due to cross-domain issues. The console displays the following: GET http://myapi.com/registrat ...

How to eliminate undefined values from a dropdown selection in AngularJS

Blockquote When choosing a material from the column, the first option is showing as undefined. How can I remove undefined from the drop-down list? What changes need to be made in the HTML/JSON data for this to work properly? Blockquote var app = ang ...

The concept of CSS inheritance within div elements

I've been researching extensively about the concept of CSS inheritance, but I have come across a puzzling question that remains unanswered. Consider the code snippet below: <!DOCTYPE HTML> <html> <head> <style type="text/css"> ...

Create a dynamic calendar by integrating dates with Javascript and an HTML table

Recently, I decided to delve into web design again and embark on a challenging project for my father's baseball business. The main task at hand is creating a detailed calendar using HTML tables. After spending a considerable amount of time perfecting ...

choose particular column in every row from the table's header class name

Every <th> in a table has a class, while the <td> elements do not. Is there a way to style all corresponding <td> elements with the same styles as their <th> counterparts using only plain css without any script? Furthermore, since ...

Broaden the default className attribute of the component

Greetings! I'm currently using Bootstrap with React and I am trying to figure out how to extend my component by passing className props deeper. Within my atom component, I have two separate files. The first one contains the component declaration. B ...

Can markers be positioned on top of scroll bars?

Looking for a way to display small markers on the scrollbar of an overflow: scroll element, similar to features found in IDEs and text editors like this one: https://github.com/surdu/scroll-marker. I've considered using a pointer-events: none overlay ...

The mystery of the Accordion Effect: A Next.js/React.js issue where it slides up but refuses to

After implementing a custom accordion using next.js, I encountered an issue where the slide animation worked successfully when moving up and out upon clicking the button. However, when trying to move it back down into the content, it did not animate as exp ...

Angular JS enabling multiple subscriptions to trigger multiple events simultaneously

Currently, I am developing an application and facing a challenge while trying to integrate AngularJS with a third-party JavaScript library. To establish communication between the two, I have implemented the pubsub method using Mediator JS. The issue arise ...

Providing a BR tag with a distinctive on-screen look (prior to the break happening)

After coming across this particular inquiry, I discovered that in the past, styling the line break (BR) tag with CSS was not possible. Nevertheless, thanks to the latest browsers, this limitation is a thing of the past now. My aim is to give certain line b ...

adjusting the space between lines for paragraphs with exceptionally large text

Utilizing Bootstrap allows for the adjustment of paragraph font sizes to appear quite large, mimicking the size and style of a heading without the need for an actual heading level HTML tag. I am hesitant to use a genuine <H2> tag to alter the visual ...