Align icons in the center of a container and add a hovering animation effect with scaling

I'm having some trouble figuring out what's causing the issue here. The transform:translate property seems to be creating a strange effect when hovering over the element.

If you could take a look at this codepen, that would be really helpful!

https://codepen.io/kuromicho/pen/LYxrQPv

CSS

.row {
  max-width: 600px;
  margin: 0 auto;
  border: 1px solid black;
  
}
.col {
  display: block;
  width:50%;
  float: left;
  border: 1px solid red;
  }
.big-icon {
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  transition: scale 0.2s;
}

.big-icon {
  font-size: 300%;
  color: #e67e22;
}

.big-icon:hover {
  transform: scale(1.15);
}

HTML:

<head>
    <link rel="preconnect" href="https://fonts.gstatic.com" />
    <link
      
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"
    />

  </head>
  <body>
    <div class="row">
      <div class="col">
            <ion-icon name="infinite-sharp" class="big-icon"></ion-icon>
        </div>
       <div class="col">
            <ion-icon name="cart-sharp" class="big-icon"></ion-icon>
        </div>
     </div>
    
  </body>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
  <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="177e78797e74787964572239233927">[email protected]</a>/dist/ionicons.js"></script>
</html>

Answer №1

I noticed that the big-icon class was defined twice in your CSS. I made some adjustments at the end of the CSS file by commenting out or deleting certain lines. Please review those changes carefully:

* {
  margin: 0;
  padding: 0;
  box-sizing: inherit;
}

html {
  box-sizing: border-box;
  font-size: 62.5%;
  height: 100vh;
}

body {
  font-size: 20px;
  font-family: "Lato", "Arial", sans-serif;
  font-weight: 400;
}

.row {
  max-width: 600px;
  margin: 0 auto;
  border: 1px solid black;
  
}

.col {
  display: flex;
  justify-content: center;
  width: 50%;
/*   float: left; */
  border: 1px solid red;
  
}

.big-icon {
/*   position: relative; */
/*   left: 50%; */
  font-size: 300%;
  color: #e67e22;
/*   transform: translateX(-50%); */
  transition: transform 0.2s ease;
}


.big-icon:hover {
  transform: scale(1.15);
}

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

Present a two-column layout using row formatting in Bootstrap with Angular

In my component file, I have an arrayData containing 4 datas, and I am trying to display them in two columns across two rows. <div class="row"> <div class="col-md-6" *ngFor="let cat of myArrayData; let index=index"> <div clas ...

Optimizing Your HTML/CSS/JavaScript Project: Key Strategies for Modular

When it comes to web frontend projects (html/css/javascript), they are often perceived as more complex to read and maintain compared to Java/C#/C/C++ projects. Is it possible to outline some optimal strategies for enhancing the readability, modularizatio ...

Sass includes line-specific comments to indicate where a certain definition is located

There seems to be a strange occurrence when I save my file and it's generated by Compass. Each declaration is followed by a comment indicating the line of the sass file, like this: /* line 55, ../sass/app.scss */ In addition, my config.rb file conta ...

Display additional information upon hovering without disrupting the neighboring elements

When I hover over a component, I want to display more details and scale it up. However, this action ends up displacing the surrounding components. Take a look at the screenshot for reference: https://i.sstatic.net/ElXvk.jpg Below is the code snippet wher ...

Unable to modify the appearance of an HTML element when injected via a Chrome extension

I am currently developing a unique chrome extension that uses Ajax to inject custom HTML into the current tab. This extension appends a <div> element to the body, and now I need to manipulate it using JavaScript. Specifically, I want it to dynamical ...

What is the process for modifying two IDs simultaneously?

I'm struggling to include more than one ID in my CSS. I want the box border to have four different hover effects and three gradient buttons (e.g., play, pictures, etc.). Here is my HTML: <h2><a id="hover-1" href="">Hov ...

toggle visibility of <li> elements using ng-repeat and conditional rendering

I have an array of color IDs and codes that I'm utilizing with ng-repeat in the <li> tag to showcase all colors. However, I only want to display colors where the color code is less than 10, hiding any colors where the color code exceeds 10. Addi ...

Identifying the loaded CSS with jQuery

My HTML page dynamically loads specific CSS files based on screen width (for PC, tablets, and phones): <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" media="all" href="css/style.css" &g ...

Issues with CSS media queries not being responsive in Safari

Can anyone shed light on why media queries are not functioning properly in Safari? Here is an example: body { background-color:black; } @media screen and (min-width: 1024px) and (max-width: 1300px) { body { background-color:red; } } ...

I recently applied a CSS style to a webform, which is functioning properly on the master page but not on a specific webform

I have implemented CSS on my master page and it is displaying properly, however, when I try to apply the same CSS to a specific web form, the styles are not showing up. Even though I have added the necessary icon code to this web form, the icon is not vis ...

Aligning table elements for optimal responsiveness

Need a hand with my HTML email code. I'm struggling to center the "resort boxes" when viewed on smaller screens like phones. Tried everything but can't crack it. Appreciate any help! https://i.sstatic.net/V6Rdr.jpg <html> <head> ...

CSS that relies on the presence of a specific class

I'm a CSS novice and I have encountered a scenario where I need to apply a CSS class only when another class is not present. <div class="border-solid p-2 bg-white mt-1 h-fit" [ngClass]="SOME_CONDITION ? 'tile-con ...

Determine the location of a character based on its index position

Is it feasible to identify the precise x and y coordinates of the character at position 24 (e.g., '-') in this overflowing multi-line text? ...

CSS: the height of html and body is set to 100%, yet the divs do not automatically adjust their height

My dilemma lies in the realm of web development. Specifically, with the CSS properties affecting the height of my div elements. html, body { width: 100%; height: 100%; } Despite specifying a height of 20% for my div element, div { height: 20%; } I am e ...

Adding a style to table data within a table row

I am facing an issue with the following code: <tr> <td class="someclass"> <input /> </td> ... <td> </td> <td> </td> .. </tr> I am looking to override t ...

What is the best way to overlay an SVG line on top of a CSS style?

Is there a way to make SVG lines appear on top of CSS-styled elements in my HTML file? I have a white background SVG created with JavaScript using d3, and I am adding CSS-styled rectangles on top of it. However, I also want SVG lines (created with JavaScri ...

How can I centrally align my navigation bar using CSS?

I've been working on a navigation bar for my website for a few days now. However, I'm having trouble centering it and using margin auto doesn't seem to be working. Here's the HTML code I have: <!DOCTYPE html> <html> < ...

Enhance your picture links with a:hover box-shadow styling

I've been struggling to add a box shadow on hover to a Facebook icon image. I assumed it would be straightforward, but as always, I was wrong. I'm working with a child theme in WordPress because I recently started, thinking it would be an easy wa ...

Adjusting the height of the divs on the right side of a 2x2 grid: Easy steps to follow

I have implemented a 2x2 grid in my HTML and CSS code: <div className="gameScreen"> <GameTable seats={seats} /> <ChatBox socket={socket} username={username} /> <InfoTable numPlayers={numPlay ...

Construct a Product Showcase Page" (FreeCodeCamp) - Issue "Incurred upon clicking a .nav-link button in the navigation panel

Hi there! I've been working on a page programming task, but I'm having trouble with the "№5 “When I click a .nav-link button in the nav element, I am taken to the corresponding section of the landing page.” error. Can anyone help me figure ...