Expanding the size of a div with a Font Awesome icon

Examining this snippet of HTML:

<div _ngcontent-c1="" class="attach">
   <div _ngcontent-c1="" class="image">
      <img _ngcontent-c1="" id="0" src="...">
    </div>
    <i _ngcontent-c1="" class="fa fa-trash"></i>
</div>

Accompanied by the following SCSS code:

.attach {
  display: inline-block;
 i {
    position: relative;
    right: 50%;
    opacity: 0;
    z-index: 2;
    padding: .5em;
    color: #efefef;
    background: gray;
    border-radius: 3em;
   }
  .image {
     display: inline-block;
   }
  img {
     z-index: 1;
     border-radius: 1em;
     width: 100px;
     height: 100px;
    }
 }
.attach:hover {
 cursor: pointer;
 filter: brightness(80%);
  i {
    opacity: 1;
  }
}

The concern is that the size of the attach div is expanding. There is an image example here: https://i.sstatic.net/8W4Yd.png

Another reference image can be found here: https://i.sstatic.net/e37xY.png

Thus, the question arises on how to prevent the enlargement of the div?

Answer №1

If you encounter the same issue, I was able to resolve it by setting the image as a background-image of the div, along with the following CSS rules:

background-size: cover;
width: 100px;
height: 100px;
text-align: center;

Afterwards, simply center the Font Awesome icon in the middle of your div using position: relative and adjusting percentages accordingly.

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

Resizing the elements within an iframe: Troubleshooting problems with embedding Bandcamp players

My goal is to embed a Bandcamp music player on my WordPress blog page, but I'm facing a challenge. The maximum width of the current player is 700px and I need it to be 900px. After consulting with someone at Bandcamp, they directed me to the old versi ...

When is it necessary to create a script that will dynamically apply a .current class (similar to active) to an element?

Creating a navigation menu 'component' - after researching some examples, I noticed that many of them utilize controllers and JavaScript to dynamically include a .current (active-like class). One example is the navigation bar on https://www.googl ...

Is there a way to add user-input text to a .txt file in an ASP.NET MVC project?

Currently engrossed in a project involving user input from the 'categoryDescription' text box to be appended to an existing text file named 'category.txt' located in the 'app_data' folder. As a newcomer to ASP.NET MVC, I find ...

Placing authentic photographs above a vector graphic (SVG)

Currently, I am working on creating SVG rectangles that symbolize a farmer's field. I was wondering if it is possible to include an actual image of a field in the rectangle to give it a more realistic and authentic appearance. Below is a sample code f ...

The annoying Facebook "add a comment" popup refuses to close

Occasionally, the "add a comment" popup (iframe) in Facebook's Like plug-in fails to close and obstructs access to the content underneath. This issue has been noted while using Chrome 21 and Firefox 15. To replicate this problem, you can visit the fo ...

Adding a symbol to a button

My goal is to add an icon to this button using JavaScript: <button id="chat5" onclick="updateChatId('{{ element.pk }}')" class="btn btn-secondary" style="background-color: maroon; border-color: transparent; border-radius: 15px; height: 60px; ...

What causes the appearance of a slight space between a child element positioned absolutely and its parent element with borders? All the margins, padding, and positions have been assigned a value of

I have encountered a peculiar issue that I managed to recreate in a simplified version. In my scenario, the parent element has the CSS property position: relative, while the child element with the ::after pseudo-element has position: absolute and all direc ...

Several treeviews for selecting data

I need some help with a specific assignment. The back end code is all set, but I'm struggling with the UI component. The task requires two tree views, one on the left and one on the right. The left tree view will contain states with multiple children, ...

HTML and CSS site lacking responsiveness

I am new to HTML and I have created a page that looks good on desktop, but it is not responsive on mobile devices. Can someone please help me with my HTML and CSS code? .link-menu { color: black; } .topbar-p ...

What steps do I need to take to extract the date and month from a single datepicker using the code below?

<div class="col-md-3 pull-left" style="padding:9px"> <input type="text" id="datepicker" class="form-control"> </div> The HTML and C ...

What is the best way to utilize clip() in html canvas when using text as a path?

I have written the code below, which is close to what I am trying to achieve but doesn't quite get there. My goal is to fill text in multiple colors, currently it is only in #FF00FF. Check out the Playground I suspect the issue lies in my lack of kn ...

Mastering the art of effortlessly displaying icons in a slideshow

I'm interested in creating an automated slideshow of icons. You can view an example on the website linked below by scrolling down to the footer section. Do you have any recommendations for how I could achieve this? My project utilizes nextjs and tailw ...

Images failing to appear

I am currently working on a basic webpage. All the text is showing up correctly, but for some reason, the icon I'm trying to display is not appearing. The icon is supposed to be from the ionicons framework. I've double-checked the path to the io ...

What is the proper way to ensure a pull right display appears correctly?

This is the code I am currently using .tag-container.bottom-border.col-middle h1.text-center {{ tag.name }} button.btn.btn-follow.pull-right(ng-hide="hasFollowed" ng-click="tagArticles.followTag()") Follow I am trying to align the tag name in th ...

Angular - Dynamically change the height of an input element based on its content's length

I'm looking to automatically adjust the height of my input text based on its content. I have a solution that works when the user is actively typing, triggering the (input) event and calling my adjustHeight function to update the input element's h ...

Regular expression to ignore the expression if it is found within a table

Looking to capture an expression, but only if it's not within a table using Ruby. hello. <p> <b> 1 capture </b> </p> <table class="tb1"> <tr> <td> <p> <b> 1 don't capt ...

Tips for creating a deepCss selector for an input Textbox in Protractor

When I attempt to use sendKeys in an input textbox with Protractor, the element is located within a shadow-root and there are three separate input textboxes. ...

What is the process of displaying an image in PHP?

As I start learning HTML, PHP, and MySQL, I have managed to log into my database using PHP and execute a query. Now, I am eager to enhance the visual display by showing an image instead of just text or numbers. The 'result' variable will contain ...

The combination of two equal height elements with absolutely positioned child elements

I have a website that features a side-bar navigation and a main content pane, both enclosed within a container element. The content has its own unique background styling, while the menu adopts the background of the parent container. In situations where th ...

"Customizable rectangular container with jagged edges created with Scalable Vector Graphics

Currently, I am undertaking a small project that involves creating a box with rough edges around some text. To achieve this effect, I am utilizing an SVG with unique edges similar to the design found at this link: (except mine is in SVG format). My goal ...