Issues with the width of Table TD cells not being responsive

I'm having trouble adjusting the width of my dropdown menu columns. I've tried various methods, but can't seem to get each column to be 200px wide as desired.

.dropbtn {
  background-image: url("../sliki/meni.png");
  width: 220px;
  height: 60px;
  border: none;
  cursor: pointer;
  display: inline;
}
.dropdown {
  position: relative;
  display: inline-block;
}
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
.dropdown-content a {
  color: black;
  padding: 10px;
  text-decoration: none;
  display: block;
}
.dropdown-content a:hover {
  background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
  display: block;
}
.dropdown:hover .dropbtn {} #uslugibn {
  background-image: url("../sliki/banner.png");
  width: 100%;
  height: 300px;
}
#meninav {
  background-color: #41c2ac;
  height: 60px;
  margin: 0;
}
#meninav li {
  display: inline-block;
}
<div class="dropdown" style="float:left;">
  <button class="dropbtn"></button>
  <div class="dropdown-content" style="left:0;">
    <table>
      <tr>
        <td style="width:200px;">
          <a href="#">Берово</a>
          <a href="#">Битола</a>
          <a href="#">Богданци</a>
          <a href="#">Валандово</a>
          <a href="#">Велес</a>
          <a href="#">Виница</a>
        </td>
        <td style="width:200px;">
          <a href="#">Гевгелија</a>
          <a href="#">Гостивар</a>
          <a href="#">Дебар</a>
          <a href="#">Делчево</a>
          <a href="#">Демир Капија</a>
          <a href="#">Демир Хисар</a>
        </td>
        <td style="width:200px;">
          <a href="#">Кавадарци</a>
          <a href="#">Кичево</a>
          <a href="#">Кочани</a>
          <a href="#">Кратово</a>
          <a href="#">Крива Паланка</a>
          <a href="#">Куманово</a>
        </td>
        <td style="width:200px;">
          <a href="#">Крушево</a>
          <a href="#">Македоснки Брод</a>
          <a href="#">Македонска Каменица</a>
          <a href="#">Неготино</a>
          <a href="#">Охрид</a>
          <a href="#">Пехчево</a>
        </td>
        <td style="width:200px;">
          <a href="#">Прилеп</a>
          <a href="#">Пробиштип</a>
          <a href="#">Радовиш</a>
          <a href="#">Ресен</a>
          <a href="#">Свети Николе</a>
          <a href="#"><strong>Скопје</strong></a>
        </td>
        <td style="width:200px;">
          <a href="#">Струга</a>
          <a href="#">Струмица</a>
          <a href="#">Тетово</a>
          <a href="#">Штип</a>
        </td>
      </tr>
    </table>
  </div>
</div>

Answer №1

When the alignment of your table is off, sometimes it's best to apply adjustments cell by cell. However, I have found that this simple solution consistently resolves the issue:

table{
   table-layout: fixed;
   width: 100%;
}

Check out the live example here

Answer №2

To solve the issue, simply include the width property for the anchor element within the td.

td > a {
  width: 200px;
}

See it in action here: https://jsfiddle.net/7b8h12mz/

Answer №3

All the previous responses have provided the solution to this issue.
To elaborate on why this behavior occurs: tables are designed to maximize the amount of content they can display within the space available, even if it means disregarding certain styling specifications like width.

In this particular scenario, the table's parent element is absolutely positioned, which nullifies its width in the layout calculations. As a result, the table's grandparent container—containing only a 220px wide button—is effectively limited to that same width since it is an inline-block element.

Consequently, the table attempts to fit itself within this constrained width set by its container, prioritizing content over specified dimensions. This is why it appears to ignore its width properties and extends beyond its intended boundaries, causing overflow within its containing element.

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

How can I resolve the vertical adjustment issue of Bootstrap 5 input group on mobile devices?

My current issue involves using Bootstrap 5.2.3 to create an input group that displays a set of spans with the ".input-group-text" class alongside inputs with the ".form-control" class. While this setup works well on a computer screen, it does not adjust c ...

Overlapping Dropdown Javascript Menus

To achieve the desired effect in the header, I need to create two expandable dropdown menus for the first two titles. My coding experience is limited, especially when it comes to javascript and jquery. Currently, I have managed to create the effect for one ...

Disabling the @import cache feature in LessCSS Assetic

I'm facing a minor issue that is robbing me of precious time. Currently, I am using the assetic plugin with the lesscss filter in my symfony2.1 project. The problem lies in Assetic not detecting changes in imported files when using the @import functi ...

Instructions for launching an Android app from a website

Is it possible to invoke my app from HTML? For instance, I am able to successfully call a webpage from my app using this code. android code: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "myDomain.com"))); ...

Incorporating HTML/PHP elements into JQuery

I am currently working on a website project for a manufacturing company that involves PHP, HTML, CSS, and JQuery. My goal is to create a seamless user experience where they can easily contact sales representatives for quotes and other information by clicki ...

Shifting hues of dots within a grid according to the passing of time

As a newcomer to the world of coding, I have conceptualized an idea for a visually appealing clock. My goal is to visually represent the passage of time throughout the day. To achieve this, I have devised a grid system where each dot on the grid represents ...

I'm not entirely sure why I keep getting the error message stating "Cannot read property 'innerHTML' of null"

Having an issue with my JavaScript code where I am trying to insert a new table row into the HTML but keep getting an error message that says "Uncaught TypeError: Cannot read property 'innerHTML' of null" <!DOCTYPE html> <html lang=" ...

Angular 10 is displaying a message indicating that a font has not been

I'm facing an error in my Angular project when trying to add a font to the SCSS file. How can I resolve this issue? style.scss: @import "~@angular/material/theming"; @include mat-core(); $PWP-primary: mat-palette($mat-indigo); $PWP-accent: ...

Emphasize specific lines within a textarea

I am facing a challenge with a textarea dedicated to validating telephone numbers. My goal is to highlight the lines that contain invalid telephone numbers by adding two asterisks in front of them. However, I'm struggling to figure out how to highlig ...

The <th> and <td> elements retrieved from the database do not align properly in their respective index positions

Hey fellow Developers, I'm currently working on a School Management System and I have two tables in the database - one for Subjects and another for storing scores obtained in those subjects, called 'scores'. My goal is to display subject nam ...

Turn off drag and drop functionality and activate selection in HTML

Recently, I encountered a strange issue where selected text became draggable and droppable onto other text, causing it to concatenate. To resolve this problem, I added the following code: ondragstart="return false" onmousedown="return false" However, thi ...

What could be causing AngularJS to truncate my URL in the search bar?

Currently, I am in the process of setting up a state provider for a CRUD website. One issue I encountered is that when I navigate to www.mysite.com/posts/mypost, the URL gets shortened to www.mysite.com/mypost and does not trigger the controller as intend ...

Attempting to connect JQuery to a different page through a data attribute connection

I am currently working on a slider that connects slides from an external page through data attributes. Here is the setup: Main Page <div id="sitewrapper"> <section class="sliderwrapper"> <div id="slider" data-source="slides-pa ...

Generate fresh input fields with distinct identifiers using JavaScript

My challenge is to dynamically create new empty text boxes in JavaScript, each with a unique name, while retaining the text entered in the previous box. I struggled with this for a while and eventually resorted to using PHP, but this resulted in unnecessar ...

Obtaining the element ID with Selenium WebDriver in cases of dynamic IDs

I am encountering an issue with the drop-down image element. I have attempted various methods to select the element, but none of them seem to be working. This may be due to the fact that both elements are identical and their IDs are dynamic. I did manage ...

`Changing the iframe content dynamically with next and previous buttons: a step-by-step guide`

function displayPDF(fileSlNo){ var data = { pageMode: "PDF_DISPLAY", fileSlno: fileSlNo }; var d = $.param(data); var request = $ .ajax({ type: "GET", url:"folderNavigation.do?"+d, dataType : "TEXT", success: functio ...

What is the best way to create pages that showcase 10 posts each?

Currently, I am facing a challenge with displaying 100 posts using the Fetch API on one single page. I am looking for a way to create separate pages where each page would showcase only 10 posts. Below is my existing JavaScript code: fetch('htt ...

Tips for retrieving the distance from the top of a specific div element and transferring it to another div

How can I add margin-top based on the tab that is clicked? Specifically, when TAB 4 is selected, I want the content to remain in the same position from the top. ...

Issues with functionality of JavaScript calculator in HTML forms

Currently, I am working on creating a basic perimeter calculator specifically designed for a projector screen. This code is intended to take the response from a radio button input and the diagonal length in order to accurately calculate the perimeter base ...

Retrieve the child DIV element within its sibling without using an identifier

I have a setup similar to the following: <div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title">Tiger128 (v2)</h3> </div> <div class="panel-body"> <inp ...