Reduce the Row height by reducing the free space at the top and bottom of the row, without changing the font size?

1 Answer 999 Views
Grid
Yuri
Top achievements
Rank 1
Yuri asked on 17 Nov 2021, 08:37 AM
I use Grid together with Grid ToolBar with default settings. But my users complain that the row height is noticeably higher than the height of the Grid ToolBar. Excessive line height reduces the amount of useful information on the page and this is bad. There is a lot of extra free space in the Grid row at the top and bottom. Changing the rowhight parameter does not give the desired result. Is there an easy way to reduce the Row height by removing excess free space at the top and bottom of the row, without changing the font size?
fpsoft
Top achievements
Rank 2
Iron
commented on 18 Jul 2023, 09:31 PM

I only add that the link "how to easily calculate it." gives access denied. Thank you.
Dimo
Telerik team
commented on 19 Jul 2023, 05:46 AM

The link currently works on my side in two different browsers. In any case, you can search for "css specificity wars" in Google Images and you will see the information in lots of other places.

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 17 Nov 2021, 03:00 PM | edited on 22 Nov 2021, 12:32 PM

Hi Yuri,

  • The Grid data cells have paddings and line-height that you can override to reduce their height.
  • At some point, the cell height may depend on command buttons, because they are higher than plain text. Command buttons have vertical margins, paddings and line-height that affect the cell height.

The easiest and fastest way to tweak a component appearance is:

  1. Inspect the HTML output and applied CSS styles with the browser's DOM inspector.
  2. Find out all elements and styles that affect the appearance you want to change. Sometimes an element may apply default browser styles.
  3. Know about CSS Specificity and how to easily calculate it.
  4. Apply your custom CSS styles with higher specificity.

The following example is extreme, because it reduces the cell and button height to a minimum. The only thing it doesn't touch is font-size. However, it demonstrates the idea.

Another important thing to keep in mind is how CSS Isolation (scoped styles) works with Blazor components, if you are using this feature.

div.k-grid td,
.k-grid td.k-command-cell {
    padding-top: 0;
    padding-bottom: 0;
    line-height: 1;
}

.k-grid td.k-command-cell .k-button {
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
    line-height: 1;
    height: auto; /* for icon buttons */
}

Finally, you can set a custom Class for the Grid and use it instead of ".k-grid", if you want to target specific Grid instances.

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Yuri
Top achievements
Rank 1
commented on 17 Nov 2021, 03:50 PM

Thanks, but it looks like it only works in the direction of increase
I tried out three options on the standard example Grid
Option 1 Default

Option 2 Decrease – no visible changes

<style>

    .k-grid td {

        padding: 1px 1px;

    }

 </

style>

Option 3 Magnification - changes are noticeable

<style>

    .k-grid td {

        padding: 50px 50px;

    }

 </style>


Dimo
Telerik team
commented on 17 Nov 2021, 03:59 PM

In this case the table cells are expanded by the buttons. You need to reduce their size as well. Buttons have margins, paddings, line-height and font-size. You can inspect the HTML output and styles in the browser's DOM inspector, and decide what to override to match your preferences.
Yuri
Top achievements
Rank 1
commented on 17 Nov 2021, 04:12 PM

Thank you, but can you tell me the easiest way to change the margins at the top and bottom for the standard "Edit" "Delete" buttons for this example
Dimo
Telerik team
commented on 18 Nov 2021, 06:50 AM

Check my edited answer above.
Yuri
Top achievements
Rank 1
commented on 18 Nov 2021, 09:25 AM

Thank you very much. This is almost what I need, but there is one strange effect
I have set the style

<style>
    div.k-grid td,
    .k-grid td.k-command-cell {
        padding-top: 1px;
        padding-bottom: 1px;
        line-height: 1px;
    }

        .k-grid td.k-command-cell .k-button {
            margin: 1px;
            padding-top: 1px;
            padding-bottom: 1px;
            line-height: 1px;
        }

I got a result that suits me (16 lines per page)

But if I remove the text "Edit" on the edit button, the changes I need will disappear (I will get only 11 lines on the page) What additional changes do I need to make?

 

Dimo
Telerik team
commented on 22 Nov 2021, 12:32 PM

This is because icon buttons (with no text) have an explicit height style to match regular text buttons. Have you tried using the browser's DOM inspector to find this out? Let me know if our built-in styling is difficult to inspect, or if our blog post is difficult to follow.

A height: auto; style in the button rule above will override the theme style immediately.

Yuri
Top achievements
Rank 1
commented on 22 Nov 2021, 05:39 PM

In my case, it was enough for me to add font-size to the style you proposed

  .k-grid td.k-command-cell .k-button {
        margin: 1px;
        padding-top: 1px;
        padding-bottom: 1px;
        line-height: 1px;
        font-size: 10px;
    }

Thanks for the helpful clarifications

Tags
Grid
Asked by
Yuri
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or