Error arising from CSS positioning with dynamically generated images

My challenge is displaying dynamic images from a database alongside details like color, name, and size, with a hover effect that shows a border.

  1. Whenever I hover over one image, the other images shift to the right or left. I want them to stay in place.
  2. There is unwanted space between some of the pictures on the left or right side.

I have tried multiple solutions to fix these issues but to no avail. Please help.

Here is the HTML code within a PHP function:

<table id='o4_img_w<?php echo $picid  ?>' style="margin-right:10px; margin-bottom: 60px; float: left">
  <tr>
    <td>
      <span style="position: relative; top: -100px" ><?php  echo "$pro_col";   ?></span>
      <span><img src='images/sales/<?php echo $picname  ?>' style='width: 150px'></span>
      <span style="position: relative; top: 15px; left: -100px" ><?php  echo "$pro_name";   ?></span>
    </td>
  </tr>
</table>

Javascript within the PHP function for the hover effect:

<script type="text/javascript">

    $(document).ready(function () {

         $("#o4_img_w<?php echo $picid;    ?>").hover(function () {
           $(this).css({
             'border': 'solid black 1px',
             'paddingBottom': '30px'
           });

    }, function () {

        $(this).css({
          'border': 'none'
        });

    });});

</script

Answer №1

<table id='o4_img_w<?=$picid?>' style="border: solid transparent 1px; margin-right:10px;margin-bottom: 60px; float: left">    
<!-- your table stuff -->

<script type="text/javascript">
    $(document).ready(function () {
         $("#o4_img_w<?=$picid?>").hover(function () {
           $(this).css({
             'border-color':'black',
             'paddingBottom':'30px'
           });

    }, function () {
        $(this).css({
          'border-color': 'transparent'
        });
    });});

</script>

For hiding the border, you can use either transparent or rgba (0,0,0,0) as the border-color.

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

What is typically regarded as the optimal size for a full-screen background image?

What is the ideal image size for a full-screen background? I currently have an image that is 1920x1080 pixels, but I'm unsure if that's suitable for desktop screens. Can you provide guidance on this? ...

The functionality of both P and H1 tags seems to be malfunctioning

Can someone help me with changing the font family and size of my paragraphs and headings (p and h1)? Any assistance would be greatly appreciated. Feel free to review my code for any other errors as it has been a while since I last coded. html, body { ma ...

When the CSS grid is equipped with a sticky left column, it will horizontally scroll if the grid's width exceeds 100% of its containing element

I am facing an issue with a CSS grid layout that has sticky left and right columns as shown below: .grid { display: grid; grid-template-columns: repeat(10, 200px); } .grid > div { border: 1px solid black; background-color: white; } .sticky- ...

Ways to conceal the TippyJS tooltip so it doesn't show up on video embeds

My website has tooltips enabled, but I am looking to hide the tooltip pop-ups that appear specifically over youtube video embeds. Upon inspecting the webpage, I found the code snippet below that is associated with youtube videos: <div data-tippy-root id ...

tips for concealing the sorting icon in the DataTables header upon initial load

Is there a way to initially hide the datatable sorting icon upon loading, but have it display automatically when clicking on the header? I've been searching for a solution without success. https://i.sstatic.net/o2Yqa.png ...

Quicker loading times for background images when creating PDFs using wkhtmltopdf

As I work on generating a 5-page PDF from my HTML file using wkhtmltopdf, everything seems to be running smoothly. However, I've encountered an issue when it comes to the time it takes to complete this task, especially when a background image is inclu ...

Obtain the bootstrap CSS file

In all my various projects, I have been utilizing Bootstrap 3 and now I am interested in incorporating Bootstrap 4 cards into my work. However, I am struggling to locate the cards in a css format rather than the scss format. I personally don't think ...

Arranging components in a horizontal layout on Jquery mobile

I'm completely new to Jquery mobile and I'm having trouble getting these elements aligned. Here's my code, but I need the two icons to line up horizontally with the caption "Heading". <h3>Heading</h3> <img src="../re ...

Striving to implement a dynamic expand and collapse animation feature for a card in ReactJS

I'm attempting to create an expand and collapse animation effect on a card without relying on bootstrap or any external libraries. I have tried adding a transition property but it doesn't seem to work when the button is clicked. Here is the comp ...

Tips for dynamically retrieving a CSS file for an HTML page

With multiple html pages containing the same navbar, I made the decision to place the navbar in its own file called navbar.html and use ajax with jquery.get() to dynamically load it onto each page. This prevents redundant code across all pages. Currently, ...

What is the recommended image size for Next.js websites?

According to documentation: The width of the image, in pixels. Must be an integer without a unit. The height of the image, in pixels. Must be an integer without a unit. https://nextjs.org/docs/api-reference/next/image Different devices come in various ...

Designing a logo atop a Jquery tab

In the layout I have designed, there is a header followed by a jQuery Tab navigator. The tabs have padding on the left side, and I want the header image to overlap this area. Currently, the image is hidden behind the tab panel. Which CSS property can be us ...

My divs are multiplying twice as fast with every iteration of the Javascript For Loop

Recently, I developed a script that generates a series of fields based on a number provided by the user (k). Initially, I had a script that would create the correct number of fields. However, I decided to arrange them like vectors on the screen, so I made ...

What is the best way to increase the height of an image beyond the limits of its container, causing it to overlap with other elements

My challenge involves creating a horizontal scrolling list of movie posters. I want the posters to grow in size when hovered over, expanding outside of their container and overlapping other elements. I attempted to use 'position: absolute' on the ...

Alter the background shade of an item as it is added or removed from a multi-select list and transferred to another list

Is there a way to visually represent the movement of items between two multi-select lists? I have one list on the right and one on the left, and when objects move from right to left, I want them to have a red background (indicating removal) and if they mov ...

Python: parsing comments in a cascading style sheet document

I am currently working on extracting the first comment block from a CSS file. Specifically, I am looking for comments that follow this pattern: /* author : name uri : link etc */ and I want to exclude any other comments present in the file, such as: /* ...

How to Create a DataTable Responsive Feature Where All Columns Collapse on Click, Except the Last One?

I am currently utilizing the DataTables library to generate a responsive table. I am aiming to create a feature where all columns in the DataTable can toggle between collapse and expand states when clicked, with the exception of the last column. Below is a ...

Arranging links in a horizontal line (JSFiddle)

CodePen: https://codepen.io/example/abc123 I am attempting to align the elements "Favourite", "0", and "Reply" next to each other so they appear as: Favourite 0 Reply ...

Different methods to incorporate Glyphicons without relying on Bootstrap CSS

For a recent client project, I utilized basic HTML and CSS. However, the client expressed a desire for Glyphicons to be included in the website menus. Attempting to incorporate Glyphicons with Bootstrap CSS posed challenges as it affected other aspects of ...

Creating dynamic text overlay on images using CSS with adjustable position

I have a collection of 11 divs, with 8 containing images and 3 displaying ':'. https://i.sstatic.net/Vfljg.png All 11 boxes are enclosed within a class called "timer", structured as shown below: <div class="timer"> <div><img&g ...