Ways to incorporate spacing between icons while keeping them aligned in a row using simple code, without the need for additional styles.js or similar dependencies

Is there a way to add padding in between icons while keeping them in the same row without using external styles.js?

<Card.Body>
       <a href={item.facebookPage}><Button  > <i class="fab fa-facebook-square fa-3x"></i></Button></a>
       <a href={item.instagram}><Button variant='warning'> <i  class="fab fa-instagram fa-3x"></i></Button></a>
       <a href={item.twitter}><Button variant='primary'> <i  class="fab fa-twitter fa-3x"></i></Button></a>
       <a href={item.youtube}><Button variant='danger'> <i  class="fab fa-youtube fa-3x"></i></Button></a>
        <a href={item.linkedIn}><Button variant='light'> <i  class="fab fa-linkedin-in fa-3x"></i></Button></a>
  </Card.Body>

The current appearance of the icons can be seen here: https://i.sstatic.net/bGZ6A.png

Answer №1

Hey there! Trying to achieve either margin or padding for the spacing between icons and borders, I'll explain both options.

If you prefer to have space between icons, you can add the following code in your css file or style tag in your html:

Card.Body a{
   display:inline-block;
   margin-right:1em;
}

Alternatively, if you want padding around your icons, you can use the following code:

Card.Body a{
   display:inline-block;
   padding:0.5em;
}

or

Card.Body a{
   display:inline-block;
   padding-left:0.5em;
   padding-right:0.5em;
}

Be cautious with padding as it may shrink the size of the icons under certain circumstances. Hopefully, this solution works for you.

Answer №2

To create spacing between elements without affecting the spacing before or after, you can utilize CSS first and last-child pseudo classes.

This code snippet adds 2em spacing between the elements by assigning margin left and right of 1em each to the middle elements, a right margin only to the first element, and a left margin only to the last element:

cardbody a {
  margin-left: 1em;
  margin-right: 1em;
}
cardbody a:first-of-type {
  margin-right: 1em;
}
cardbody a:last-of-type {
  margin-left: 1em;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<cardbody>
       <a href={item.facebookPage}><Button  > <i class="fab fa-facebook-square fa-3x "></i></Button></a>
       <a href={item.instagram}><Button variant='warning'> <i  class="fab fa-instagram fa-3x" ></i></Button></a>
       <a href={item.twitter}><Button variant='primary' > <i  class="fab fa-twitter fa-3x" ></i></Button></a>
       <a href={item.youtube}><Button variant='danger' > <i  class="fab fa-youtube fa-3x" ></i></Button></a>
        <a href={item.linkedIn}><Button variant='light' > <i  class="fab fa-linkedin-in fa-3x" ></i></Button></a>
</cardbody>

Note: I couldn't make the format Card.Body work as a tag with or without React, so for this demo, it has been simplified to cardbody.

Answer №3

The previous answer was adequate, but I aimed to achieve the same result with a simpler code structure. By including className='mx-2' within the button element, it successfully accomplished the task.

  <Card.Body>
     <a href={item.facebookPage}><Button className='mx-2' > <i class="fab fa-facebook-square fa-3x "></i></Button></a>
     <a href={item.instagram}><Button variant='warning' className='mx-2'> <i  class="fab fa-instagram fa-3x" ></i></Button></a>
     <a href={item.twitter}><Button variant='primary' className='mx-2'> <i  class="fab fa-twitter fa-3x" ></i></Button></a>
     <a href={item.youtube}><Button variant='danger' className='mx-2'> <i  class="fab fa-youtube fa-3x" ></i></Button></a>
     <a href={item.linkedIn}><Button variant='light' className='mx-2'> <i  class="fab fa-linkedin-in fa-3x" ></i></Button></a>
       </Card.Body  >

As a result, the buttons now display as shown in the image below: https://i.sstatic.net/gHvip.png

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

The defaultLocale in NextJS does not match the configured locale

Recently, I set up my next.config.js file using the default Next JS 10 locale routing in this way: module.exports = { i18n: { locales: ['nl-NL', 'en-GB'], defaultLocale: 'nl-NL', localeDetection: false, }, ... ...

Sample code for table_class_list and table_row_class_list is provided below:

I am excited to start using the newest version of the TinyMCE plugin, with its enhanced features. I experimented with the URL to understand how the table plugin functions. In the example provided, I noticed two classes named Dog and Cat, each associated ...

Displaying a menu item based on a boolean value in the conditional rendering

In my menuItem component, I have two items from the mui library (version 0). I am looking to implement a condition where, upon data loading, if the status is "failed" then the download button should be greyed out. See the menuItems code snippet below: cons ...

Is it possible to dynamically import a .json file using Webpack?

I am currently utilizing React Intl to support multiple languages (as shown in the example below) and within my App setup, I am importing the following: import { addLocaleData } from 'react-intl'; import locale_en from 'react-intl/locale-da ...

Uploading Images with CKEditor in a React Application

Looking to integrate CKEditor with react (redux) for text editing and image uploading. While the text editor is working fine, I am encountering an issue with the image uploader. When selecting an image, an error occurs as shown in the screenshot below. Be ...

The outcome varies significantly when using Chrome versus Firefox version 10.2

Check out this cool CSS text effect I created: .inset-text { background-color: #666666; -moz-background-clip: text; -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: rgba(255,255,255,0.5) 0 3px ...

"Building a dynamic form with ReactJS, Redux Form, and Material UI - Implementing an

Currently working on a nested form framework that utilizes the redux form and material UI framework. The components have been developed up to this point - https://codesandbox.io/s/bold-sunset-uc4t5 My goal is to incorporate an autocomplete field into the ...

Apply a class using [ngClass] based on an HTML condition within the local scope

In the past, I have utilized [ngClass] to assign classes based on the Boolean value of a variable in the JavaScript/TypeScript. However, I am now curious if it is achievable to apply [ngClass] based on a local HTML boolean value instead? For example: < ...

What is the significance of a React Functional Component returning JSX.IntrinsicElements?

I stumbled upon this React functional component in a particular documentation import React, { useState, useEffect } from 'react'; import { fabric } from 'fabric'; interface ITextProps { id: string; options: fabric.ITextboxOptions; ...

The React TypeScript MUI Autocomplete is giving an error: "Type 'Product[]' cannot be assigned to type 'readonly never[][]"

Having trouble with a ReactJS useEffect hook in an Autocomplete field while using Typescript version 4.9.5. The VS code editor is flagging an error on the line options={products}. Any assistance on resolving this issue would be greatly appreciated. You c ...

React.js not displaying image

Here's my App.js File I am trying to display an image from the MongoDB database. Click here to view the image stored in MongoDB The images are stored as Binary data in MongoDB How can I display the image on the React page? import React,{useState} fr ...

Tips for creating a scrolling iFrame that moves with the background

I have recently created a website with a unique design feature. The background image acts as a border surrounding the main content, which is located within an iFrame. However, I've encountered an issue where scrolling the iFrame does not affect the ba ...

The menu remains open after selecting a menu item on mobile devices

Hey everyone, I could really use some assistance :) I'm currently working on a Gatsby and React portfolio, and I've run into an issue with the menu not collapsing when clicking on a menu item on mobile devices. It works perfectly fine on desktop ...

Sending sanitized data to the React render() function

When utilizing react-datagrid to display my documents table, I encountered an issue with initializing the render() scope with complete data. It consistently initializes with no data present. This is the datagrid code snippet: 'use strict'; va ...

The issue arises in Ag Grid React when checkboxSelection property is set to true, preventing the ability to select or deselect rows while

As a newcomer to Ag grid, I am interested in creating a tabular structure with checkbox selection. Here is how I am utilizing Ag grid React to build the table: import React, {useState} from 'react'; import { AgGridReact } from 'ag-grid-react ...

The CSS "ul" selector targets unordered lists in HTML

How can I target the ul elements highlighted below in my HTML markup without using a class or id for reference? Here is the relevant portion of my HTML code: <div id="mainmenu"> <ul class="menu"> <li class="item-472"> < ...

Export data from a dynamically generated table to an Excel file with SheetJS

I have been dynamically adding rows to an HTML table and I am trying to save the content of the table into an xlsx file using SheetJs. However, the generated file is currently empty. Is there a way to achieve this when the table content is added in this ...

Passing properties from a parent component to a child component in a React TypeScript application

I'm currently facing an issue with passing props to my component. It seems like I am unable to pass the 'Commune' due to it having a name property. Does anyone have any suggestions on how I can pass Commune.name as a prop to my component? ...

What is the best way to turn off default CSS styling in KendoUI?

I am facing an issue in my application where I am using global CSS definitions for "INPUT", "SELECT", and other elements. The problem arises when I try to incorporate KendoUI widgets, as they override my default CSS styles. For instance, my CSS code looks ...

Unrecognized Hook Usage in ReactJS Crash Course for Novices

I'm currently attempting to follow a tutorial on YouTube, which can be found at https://youtu.be/tbvguOj8C-o?t=33570 However, I've encountered an issue in the video from this point onwards until the next code update (approximately one minute in) ...