Unexpected behavior when changing height of a md-button

Struggling to adjust the height of an md-button has been quite frustrating for me. It's been hard-coded to be 25px high within the <button-container> element, but the hover animation still overflows this set height, as shown here: https://i.sstatic.net/1xTT1.png

Adding a 25px height to the buttons themselves seems to cause an offset in the content, like this: https://i.sstatic.net/dOxGg.png

Does anyone know how to write a style that can correct this behavior? It's puzzling why hard-coding a height into the button results in the text dropping to the bottom.

Below is my HTML:

<div id="buttons-container">
    <button 
        md-button
        id="add-track-button" 
        (click)="addTrack()"
    >
        <md-icon>add</md-icon> 
        <span>Add Track</span>  
    </button>

    <button 
        md-button
        id="delete-track-button"
        [disableRipple]="true"
        [disabled]="this.tracksArray.length === 0"
        (click)="toggleDeleteTrackMode()"
    >
        <md-icon>delete</md-icon> 
        <span>Delete Tracks</span>
    </button>

    <button 
        md-button
        id="add-marker-button"
        [disableRipple]="true"
        (click)="toggleAddMarkerMode()"
    >
        <md-icon>add</md-icon> 
        <span>Add Marker</span>
    </button>

    <button 
        md-button
        id="add-frame-span-button"
        [disableRipple]="true"
        (click)="toggleAddFrameSpanMode()"
   >
        <md-icon>add</md-icon> 
        <span>Add Span</span>
    </button>
</div>

Below is my CSS:

#buttons-container {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: nowrap;
    height: 25px;
    color: black;
    background-color: grey;

    button {
        font-size: 10px;
        // If this line is commented out, the text is aligned fine but the hover animation overflows
        // If it isn't, the content offsets to the bottom like in the picture above
        height: 25px;
        padding: 0px 2px;

        md-icon {
            font-size: 18px;
            height: 18px;
            width: 18px;
        }
    }

    #add-marker-button {
        md-icon {
            color: $marker-color;
        }
    }

    #add-frame-span-button {
        md-icon {
            color: $frame-span-color;
        }
    }
}

Answer №1

To achieve the desired outcome, you can utilize the properties min-height, max-height, and line-height.

Below is an example of inline styling:

<md-button style="min-height:25px;background-color:yellow">Button 1</md-button>
<md-button class="custom-button" style="min-height:25px;max-height:25px;background-color:red; text-align:center;line-height:25px">Button 2</md-button>

For a demonstration, check out the live example on CodePen.

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

Tips on updating the highlighted color of the item currently selected in NavBarDropdown using react-bootstrap

I've been utilizing the react-bootstrap NavDropDown component from this source. Although I initially set it up correctly, I'm struggling to customize the background color of the navdropdow-items when they are in their normal or active (selected) ...

Is it possible for an HTML file to not recognize an external CSS stylesheet?

I've been trying everything, but I can't seem to get these two documents to work together. I'm confident that the CSS file is linked correctly with the right file name. I decided to give it a shot after watching this coding blog tutorial on ...

How can you incorporate a unique font using a CSS class within a bootstrap class declaration?

Is it possible to add a CSS class to a pre-existing bootstrap class on a webpage? For example, I know how to add a custom font to a bootstrap page, but I only want to change the font of a specific line while keeping the rest of the text with the default fo ...

Issue with Div Element Not Expanding When Populated

I am facing an issue with a stack of nested divs, each having a specific ID for CSS styling. However, the outermost DIV tag is only expanding to a predetermined height value instead of automatically adjusting to fit its contents. This is a problem because ...

Is there a way for me to display a gif similar to 9GAG on my

I'm looking to implement a feature on my website that allows me to pause and play a gif, similar to the functionality on 9gag. Can anyone provide guidance on how I can achieve this? I understand that I need to use both .jpg and .gif files, but my at ...

Designed radio buttons failing to activate when focused using a keyboard

I'm facing an issue with radio input buttons that I've dynamically added to a div using jQuery. They function properly when clicked with a mouse, but do not get activated when using the keyboard tab-focus state. NOTE: To style the radio buttons ...

The h3 tag listener is not functioning as expected

I'm seeking assistance with the listeners for my pomodoro clock, specifically for minBreak and plusBreak. Oddly enough, the listeners for minWork and plusWork in jQuery are functioning properly, but the ones for minBreak and plusBreak are not. Any ins ...

When the canvas is dragged, an item within it suddenly leaps or bounces

I've noticed that when I drag the canvas using -webkit-transform: translate(x,y), an element on the canvas jumps. Are there any suggestions for addressing this issue? ...

Unusual behavior exhibited by dynamic code in iframe

When trying to retrieve a dynamic height iframe, I implement the code below. In the <head> area <script language="javascript" type="text/javascript"> function adjustIframe(obj) { obj.style.height = obj.contentWindow.document.body.scrollHeight ...

The progress bar is visually enhanced with a border style that doubles as a background color

While experimenting with a jsfiddle to create an animated progress bar, I stumbled upon something peculiar. I had a single CSS rule applied to the progress tag: progress { border:2px solid #ccc; } Prior to adding this CSS rule, the progress bar looke ...

How come the previous sibling element appears on top when the initial sibling is set to a position of absolute?

I have encountered an issue with two sibling sections. I applied position:absolute to the first section, but the second section is overlapping it. Even after trying to use position:relative on the second section, the problem persists. https://i.stack.imgur ...

Content within a Row of a Data Table

Hello! I am just starting to learn JavaScript and jQuery. Can you help me with an issue I am experiencing? Basically, I have a table and I need to identify which tr contains a td with the text "Weekly", "Daily", or "Monthly". Once I locate that specific t ...

Ways to showcase tooltip text for an unordered list item?

When creating an unordered list, each element's text corresponds to a chapter name. I also want to include the description of each chapter as tooltip text. The Javascript code I currently have for generating a list item is: var list_item = document.c ...

How to dynamically load a component in Angular 5 and open a sidenav

Hey there! I recently created this project on StackBlitz check it out here! I'm looking for ways to dynamically load components inside a sidenav. For example, from the NavigatoComponent, I want to open the sidenav on click with the Acomponent load ...

Embed a video onto a webpage using HTML and ensure it is responsive by implementing Bootstrap's grid

I am currently using the mPurpose-master bootstrap theme, which offers a feature allowing the placement of 3 blocks in a row that are fully responsive. <div class="section"> <div class="container"> <div class="row"> ...

Positioning elements within a Bootstrap column: Fixed versus Absolute positioning

Striving to maintain the absolute positioning of the right column as users scroll through the left column has proven to be a challenging task. Despite exploring various solutions from stackoverflow and google, none seem to effectively address this issue. ...

Retrieve CSS hover values using jQuery

When the page is loaded, I need to execute a function that retrieves the CSS background image settings as well as the hover background image setting, which I intend to use in a different way. The only technique I have come across requires an actual mouseo ...

Is it possible to prevent the fade out of the image when hovering over the text after hovering over the div or image, causing the text to fade in?

Using React and CSS. I have set up my application to display a faded image on hover, with text that fades in over it. However, I am facing an issue where touching the text with my cursor removes the fade effect. Does anyone have a solution for preventing ...

What is the process for marking a form field as invalid?

Is it possible to validate the length of a field after removing its mask using text-mask from here? The problem is that the property "minLength" doesn't work with the mask. How can I mark this form field as invalid if it fails my custom validation met ...

Is it possible to move the login button to the right side of the screen?

I'm attempting to move the Login menu all the way to the right on the navigation bar. Currently, all the menu items are aligned to the left and I need to align the Login menu to the right. However, I'm unsure of where to begin. The navigation me ...