Positioning an image alongside a row in a table

Looking to incorporate images alongside each row in a table using Html and CSS, similar to the example image below:

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

The desired placement for the images is depicted by the red crosses: positioned on the right side of each row without creating an additional column.

Wondering what would be the most effective approach to achieve this design.

Answer №1

If you're looking to add a custom style to the last child element using CSS, you can use the :last-child selector in combination with the :after pseudo-element.

tr td:last-child::after {
  content: '';
  display: inline-block;
  position: absolute;
  height: 1em;
  width: 1em;
  background: url("http://www.gentleface.com/i/free_toolbar_icons_16x16_black.png") no-repeat center;
}
<table>
  <thead>
    <th>1</th>
    <th>2</th>
  </thead>
  <tb>
    <tr>
       <td>1</td>
       <td>2</td>
   </tr>
   <tr>
     <td>1</td>
     <td>2</td>
   </tr>
  </tb>
</table>

Answer №2

Another idea could be to add a new column with a table header that appears blank.

<table style="width:100%">
  <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>  </th> -- This space intentionally left blank 
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>Icon here</td>
  </tr>
</table>

You can use CSS to style it in a way that separates it from the rest of the table visually.

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

Vanilla JavaScript: Enabling Video Autoplay within a Modal

Can anyone provide a solution in vanilla JavaScript to make a video autoplay within a popup modal? Is this even achievable? I have already included the autoplay element in the iframe (I believe it is standard in the embedded link from YouTube), but I stil ...

Updating the appearance of a non-declared HTML child component on-the-fly using Angular

Trying to dynamically adjust the style of an unspecified div is causing some trouble. Using Angular and PrimeNG, invisible divs are being generated that I cannot access through inline styles. The objective is to allow a user to input a width as a string (5 ...

Why do my Wix-hosted images appear fine on desktop but not on mobile? What steps should be taken to correct this issue?

My website is finally live! I included several links to images hosted on various websites. Everything looks great on desktop, but when viewed on mobile, all the images hosted on Wix are not displaying properly. Instead, a text box appears saying "respons ...

Adjusting the size of a DIV with a CSS background as the browser window is

This issue seems simple, but I've been struggling to find a solution. <div class="bg"> <div class="container2"> <p> Test content goes here </p> </div> </div> I am facing an issue ...

Is there a way to manipulate the appearance of a scroller using JavaScript?

I'm intrigued by how fellow front-end developers are able to customize the scrollbar shape on a webpage to enhance its appearance. Can anyone guide me on using JavaScript to accomplish this? ...

Tips on how to change an image tag into a CSS selector

I need to change this tag to a WebElemet using CSS Selector instead of Xpath. I attempted with Xpath as shown below: panelSectionTitle.find( By.cssSelector( "img.aw-layout-right[style='']" ) ) <img style="" class="aw-layout-right" height="2 ...

Tips for creating a phone number placeholder that stays in place on a form

I'm looking to display the phone number format as a placeholder in the input field, without it disappearing as the user types. The standard HTML placeholder disappears as the user starts typing. I want the placeholder to remain visible and guide the ...

The marquee's position is reset the first time text is loaded dynamically from an API

In my angular project, I'm implementing a marquee feature to display data fetched from an API. However, I've noticed a strange issue where after a page reload, the marquee starts from right to left but once it reaches the end of the div, it reset ...

What is the best way to ensure that any words exceeding the line length automatically move to the next line?

My webpage width is currently set to 100vw and adjusts responsively as the viewport size changes. However, there seems to be a slight issue where certain words overflow without being pushed to the next line, causing a small horizontal scroll: https://i.s ...

What's the best way to constrain a draggable element within the boundaries of its parent using right and bottom values?

I am currently working on creating a draggable map. I have successfully limited the draggable child for the left and top sides, but I am struggling to do the same for the right and bottom sides. How can I restrict the movement of a draggable child based o ...

Dynamic text displayed on an image with hover effect using JavaScript

Currently, I am in the process of developing a website for a coding course that is part of my university curriculum. The project specifications require the use of JavaScript, so I have incorporated it to display text over images when they are hovered over ...

When hovering over the menu list, the background-color of the text area remains the same

I am facing an issue with my list menu. The hover effect changes the background color only in the box area, but not in the text area. I would like to figure out a way to make both areas change color on hover: Here is the code snippet: <div class="se ...

The symbiotic partnership between JSF bean and the dynamic capabilities of HTML

As I develop my project in JSF using Primefaces 4.0 and a Tomcat 7 server, I encounter the need to retrieve an image from a MS SQL database and apply clickable areas on it. The coordinates for each area are also obtained from the database. Unfortunately, t ...

Personalized jQuery Slider with automatic sliding

I am currently working on creating my own image slider without relying on plugins. 1st inquiry : How can I achieve horizontal animation for the slider? 2nd inquiry : I want the images to cover both the height and width of their container while maintainin ...

Is there an issue with my Regex pattern for extracting link elements when scraping content?

I'm currently facing an issue with my VB.NET scraper. The scraper is designed to extract all links from an HTML string that I have already retrieved, and upon inspection, the links are present. It appears that the problem lies within my regex expressi ...

What steps should I take to set up my React project in order to eliminate .html extensions from the html files within the public

Currently, I am tackling a project that involves integrating a React app with a static website. Simply converting the HTML to JSX is not feasible because the website utilizes custom CSS that React cannot easily render without significant refactoring. I ha ...

Updating the CSS link href in ASP.NET using code behind

I'm struggling with changing the CSS href in the code-behind of my .ASPX page. I've tried various methods but haven't found a solution that works as intended. HTML Markup: <link id="linkCSS" runat="server" href='/css/1.css' re ...

What is the best way to add a character within a YouTube JSON link?

Fetching json data from a link, the youtube format in the link is http:\/\/www.youtube.com\/watch?v=UVKsd8z6scw. However, I need to add the letter "v" in between this link to display it in an iframe. So, the modified link should appear as ht ...

Exclusively for Numerical Input with Number Keys

A customer on a website requires a Zip Code field that only accepts 5-digit numbers and triggers the numeric keypad on iOS and Android devices. It should also be compatible with external number pads on laptops. I've tried various approaches like keyC ...

How to avoid clipping in Bootstrap 4 when a row overflows with horizontal scrolling

In order to allow for horizontal scrolling of all contained columns, I created a row using the row class. To implement this feature, I followed advice from a contributor on Stack Overflow. You can view their answer by following this link: Bootstrap 4 hori ...