Optimize top margin spacing for Ant Design Tag component

I'm currently utilizing the antd Tag component, which comes with the property display: inline-block; causing some unwanted top margin. I am looking for a way to eliminate this extra margin without having to introduce an additional container for the tags. Below is my attempt at fixing the issue:

const Container = styled.div`
  font-size: 0;
  letter-spacing: 0;
  word-spacing: 0;
  background-color: red;
  height: 100px;
`;

ReactDOM.render(
  <Container>
    <Tag>Tag 1</Tag>
    <Tag>Tag 2</Tag>
    <Tag>Tag 3</Tag>
  </Container>,
  document.getElementById("container")
);

Are there alternative methods to address this issue aside from using an extra tag container?

Link to view the implementation on codesandbox.

This image depicts the problem without the fix (showing a 2 px margin above the tags).

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

And here is how it looks after applying the fix.

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

Answer №1

To eliminate the additional top spacing, consider applying vertical-align: top to each inline-block Tag component.

The height of a line box is determined by specific rules outlined in the line height calculations section. I have included the necessary CSS for the .ant-tag selector if you wish to customize the line box height for Tag components.

You can access the fixed CodeSandbox by visiting this link.

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

Utilizing the Calc() method within CSS specifically for adjusting the padding on the left and top sides

I am currently working on a website using HTML and SASS. My design includes a fixed header and aside sections. header{ width: 100%; box-shadow: 0 0 4px rgba(0,0,0,.25); position: fixed; z-index: 5; top: 0; ...

Update the button color to transform it from a dull grey when disabled to a vibrant shade

I am trying to modify the button color in my script from grey to green when it transitions from disabled to enabled status. Despite using both the disabled and enabled properties in my CSS and incorporating vue.js (which I am not very familiar with), the c ...

The printed Bootstrap web page is being truncated

I have a unique dynamic webpage created with Bootstrap that needs to be printable. I am implementing media queries for styling the page when printing: /** Custom Print Styles **/ @media print { header, .menu, footer { display: none; ...

Close the gap in the CSS for the image tag

I am facing an issue. Whenever I include an img Tag in my HTML File, there is a Gap around the tag. It is neither margin nor padding. I wonder what it could be? Could someone please assist me in removing the gap with CSS? <img src="../images/modules/ ...

Design a sleek and modern form using Bootstrap 4 that mirrors the aesthetics of the forms found in Bootstrap 3

Is there a way to create a form using BootStrap 4 that resembles the easily customizable forms from BootStrap 3? I am looking to have a bold, right-aligned label within a specific column size (e.g. col-sm-4), with an input field next to it whose width is c ...

What is the best way to position text in the center of a pie chart using Nivo for ReactJS?

Struggling to center the text with my pie chart on novio.rocks for my react project. Any tips or suggestions are appreciated! Check out the demo here. ...

What is the method to display the width of a drop-down menu when using overflow:hidden?

Are there any solutions available for displaying a dropdown menu while using overflow in bxslider? The div currently has overflow:hidden to properly display the carousel. Any ideas on how to resolve this issue with z? .member{ position: absolute; ...

The preflight response for CORS does not allow the header field content-type in .NET React

Seeking assistance with CORS implementation in React and .NET integration I have been struggling for a few days now trying to resolve the CORS issue in my React app when making POST requests to a basic .NET webAPI. The GET implementation works fine, but I ...

Identify the font style of the text box and ensure that the contenteditable feature matches the appearance of the

I'm struggling to style a contenteditable element to resemble a regular textbox on my website. Can anyone help me identify the font used in this picture? I've tried several but none seem to match perfectly. https://i.sstatic.net/2aAbb.jpg The co ...

How to apply background images to LI elements using CSS

I've been experimenting with CSS-generated tabs to display an active state of an arrow underneath the tab. I tried using the background position properties to position the image for the hover event, but it would extend beyond the predefined boundaries ...

Tips for structuring an object map with flow type to ensure that each value includes a corresponding key

In an attempt to correctly type (using Flow) a helper function called createReducer for Redux, I have utilized the code from redux-immutablejs as my starting point. I am following the recommendations from the flow documentation on typing Redux reducers, b ...

Creating test code for a custom hook utilizing recoil involves following specific steps to ensure the functionality

Currently, I am working on creating a test code using Jest for a custom hook within my web application. The custom hook utilizes Recoil for state management but unfortunately, an error message appears whenever I try to run the command npm run test. The sp ...

Having trouble with ReactJS not fully rendering Bootstrap 4 components

I recently came across a Bootstrap 4 template for a navbar with login functionality on this website and decided to convert it into code. Here is the resulting code: import React, {Component} from 'react'; class HeaderComponent extends Component ...

Styling your components with Material-UI Theming and Styled Components

I am currently delving into Gatsby and experimenting with building components using Material-UI and Styled Components while applying my custom theme. I managed to successfully apply a theme by following the Gatsby configurations for the Material-UI plugin ...

Tips for showing an Inline Autocomplete element

Is there a way to display the Autocomplete component inline alongside other React MUI components? Referring to the example of countries from the documentation: https://codesandbox.io/s/countryselect-material-demo-2g0jeu?fontsize=14&hidenavigation=1&a ...

Error with invoking the .click() method in jQuery and problem with calling a

Using an image button to trigger a function with the .click() jQuery event handler. Upon clicking the button, it displays a log message but does not show the alert message. The alert message only appears when clicking on the edge of the button. Any help ...

Tips for integrating semantic HTML with React components

As a newcomer to react, I am eager to establish a strong foundation before delving deep into the language and risking having to backtrack later on. I am curious about how to incorporate semantic HTML in react. Elements such as <header>, <nav>, ...

The import error that you are encountering states that the 'fade' feature is not being exported from the '@material-ui/core/styles' module

I have exhausted all possible solutions I could find on the internet. I made sure to upgrade all dependencies and packages using yarn - as shown in the package.json below: "dependencies": { "@date-io/date-fns": "^1.3.13", ...

Empty space on the side of the menu bar

In my current project, I am working on creating a menu bar with the container named #menu. The CSS for this container includes properties such as border: 0px; margin: 0 auto; position: relative; display: inline-block; width: 100%. However, I encountered a ...

How can I implement the ctx.session.$create method in an API with Blitz.js?

I'm currently integrating the blitz.js login API into a Flutter project. To do this, I've created a /api/auth/login.ts file with the code snippet below: import { getAntiCSRFToken, getSession, SecurePassword } from "@blitzjs/auth" import { auth ...