Photo not completing the table

Hey there, I'm currently working on creating a table to showcase some products but I am struggling with ensuring that the images display at the correct size. Any assistance on this matter would be greatly appreciated.

#tbldesktops {
  width: 100%;
  height: 100%;
  margin-top: 50px;
}

#tbldesktops tr :nth-child(3) {
  width: 60%;
}

#tbldesktops tr :nth-child(1) {
  width: 15%;
}

#tbldesktops,
td {
  text-align: left;
  border: 1px solid black;
  border-collapse: collapse;
  background-color: #fde981;
  font-size: 12pt;
  height: 8vh;
}

#tbldesktops th {
  color: #fde981;
  background-color: #4f41dc;
  border: 1px solid black;
  border-collapse: collapse;
}

.productimg {
  height: auto;
  width: 100%;
}
<table id="tbldesktops">
  <tr>
    <th class="pctype" colspan="3">Desktop Computers</th>
  </tr>
  <tr>
    <th>Image</th>
    <th>Model</th>
    <th>Description</th>
  </tr>
  <tr>
    <td><img class="productimg" src="https://via.placeholder.com/200.jpg" alt="product name"></td>
    <td>Product</td>
    <td>Description</td>
  </tr>
</table>

I have attempted various methods such as setting the width and height manually, however, nothing seems to work. Here is the fiddle https://jsfiddle.net/w5rvdzk1/1/

Answer №1

Your CSS

#tbldesktops tr :nth-child(1) {
  width: 15%;
}

Targets the <img> within the table, as it is indeed the first child of the <td> and because it holds greater specificity than .productimg, its styles take precedence.

To fix it, revise the selector to

#tbldesktops tr > :nth-child(1) {
  width: 15%;
}

for enhanced functionality

#tbldesktops {
  width: 100%;
  height: 100%;
  margin-top: 50px;
}

#tbldesktops tr > :nth-child(3) {
  width: 60%;
}

#tbldesktops tr > :nth-child(1) {
  width: 15%;
}

#tbldesktops,
td {
  text-align: left;
  border: 1px solid black;
  border-collapse: collapse;
  background-color: #fde981;
  font-size: 12pt;
  height: 8vh;
}

#tbldesktops th {
  color: #fde981;
  background-color: #4f41dc;
  border: 1px solid black;
  border-collapse: collapse;
}

.productimg {
  height: auto;
  width: 100%;
}
<table id="tbldesktops">
  <tr>
    <th class="pctype" colspan="3">Desktop Computers</th>
  </tr>
  <tr>
    <th>Image</th>
    <th>Model</th>
    <th>Description</th>
  </tr>
  <tr>
    <td><img class="productimg" src="https://via.placeholder.com/200.jpg" alt="product name"></td>
    <td>Product</td>
    <td>Description</td>
  </tr>
</table>

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

Chrome DevTools automatically translates all HEX color codes into their corresponding RGB values

Chrome DevTools now automatically converts all HEX colors to RGB values, even if the color is set in CSS or using DevTools. Is there a way to prevent this conversion? I know about the method of holding down Shift + clicking the color icon to convert color ...

Submit data from one form to another form located within an iframe

I am currently using a JX Browser that allows content to be displayed in an iframe. My goal is to automatically transfer the username and password of a user logging into my ticketing software to another form within an iframe. The page within the iframe is ...

insert a new DOM element into an array using jQuery

Looking at the code snippet below: a_ajouter = $('.question'); hidden_div.push(a_ajouter); console.log(hidden_div); Upon examining the output in the console, instead of a DOM object being added to the div as intended, it shows &apo ...

Is there a way to switch an input's appearance to resemble that of a label?

Looking to customize my input fields to resemble labels at first, then apply editable styles with angular.js upon button click. Utilizing bootstrap for my project, wondering if there is a built-in class that can be toggled on and off for these inputs? ...

How can I display a pre-existing div with a dropdown button?

I have individual div elements for each type of clothing item (shirt, pant, suit) that I want to display when the corresponding service is selected. This means that when I click on one of them, only that specific div will be shown. I am looking for a solut ...

The jQuery plugin embedded in the Joomla 3.2 module fails to load or function properly

Seeking help with a JavaScript issue on my Joomla website. I'm not an expert, so please bear with me. I am using a regular plugin (not a Joomla specific one) to display my portfolio. It should work like this: ... black.html This is how it shouldn&a ...

What measures can be taken to stop LESS partials from compiling independently?

When working with LESS, I utilize partials that are included (@include) into the main LESS stylesheet. A common issue I face is that each partial ends up compiling to its own CSS file, leading to project clutter. In SASS, if a file is named with an unders ...

The text entered in the textbox vanishes after I press the submit button

When a user selects a value in a textbox and clicks the submit button, the selected value disappears. <div class="panel-body" ng-repeat="patient in $ctrl.patient | filter:$ctrl.mrd"> <form> <div class="form-group"> ...

Deciding the source URLs for external iframes

Is it possible to detect the URL displayed in an iframe? How can we ensure that links within an iframe open in a new tab/window? Moreover, is there a way to achieve this even with the same-origin policy for external frames? If not, what causes this violat ...

IE and Firefox both render CSS styles in their own unique ways

When viewing my website acro.batcave.net on different browsers like IE (Windows 7, IE 11.x) and FF (Windows 7, FF 37.x), I noticed that it appears differently. Chrome seems to have the same display as FF. The CSS file can be found at acro.batcave.net/css ...

What is the best approach to creating a fully rounded capsule using CSS?

I've been having trouble creating a complete capsule in CSS and I'm not achieving the expected outcome. Can anyone assist me in resolving this issue? I am new to CSS. Below is my code: <style> #myStyle { position: relat ...

Unable to overlay a div on top of an image

Hello, I'm currently attempting to overlay a div on top of an image. Since the image needs to be responsive, it cannot be set as a background image. Here is the CSS I am using: #slider { margin:0 33%; width:67%; position:relative; } #sli ...

The contents of the div do not display when the button is pressed except in jsfiddle

I have written a script that triggers the appearance of a div where users can adjust the time settings for a timer. The functionality works perfectly on JSFiddle, with the div displaying as intended. However, when tested on other online IDEs such as Coding ...

Applying CSS text-shadow to an input field can cause the shadow to be truncated

I've encountered an issue when applying text-shadow to an input field, where the shadow appears to clip around the text. Here is the CSS code I used: @import url('https://fonts.googleapis.com/css2?family=Jost:ital,wght@0,100..900;1,100..900& ...

Enlarge the div with a click

I was looking for a solution on how to make a div expand when clicked using jQuery I came across a tutorial that seemed simple and perfect, but I couldn't get it to work when I tried to replicate the code. Do you know if this code is still valid wit ...

How come the element is not appearing in the div even though it should be there?

The placement of the image and select menu within the same div element may be causing a display issue where only the first image is shown correctly and the select menu appears outside. Why does this occur? <body> <div style="height: 1080px; ...

Execute various settimeout or display functions on various elements of a webpage

Just a heads up, I'm not really experienced in development. More on the newbie side of things, but eager to learn. I've been looking for an answer to my question, but so far haven't come across anything that fits my specific situation. It m ...

Tips for resolving the need to manually set h-100 to HTML and BODY tags and addressing centering problems

When I don't set my HTML and BODY tag to have the class "h-100," they display at a height of around 210 pixels. This then requires me to also set lower-level elements with the h-100 class. I'm unsure how to resolve this issue without including t ...

Is the Piecemaker flash slider being obstructed by its container?

I am currently integrating the Piecemaker flash slider into my new project for the very first time. Unfortunately, I'm facing an issue where the animation is getting cut off by the dimensions of its container. I've been struggling to figure out h ...

I am unable to view the input appearing inside the input box on my React/HTML application

I have been developing a React app for building portfolios, but I am facing an issue where I cannot see any text that I type into my input boxes. Can someone please help me troubleshoot this issue? Any assistance would be greatly appreciated. I have made ...