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

Encountering a problem with the multi-page template structure in jQuery Mobile

As a newcomer to Phonegap, I am utilizing jQuery Mobile and HTML5 for the development of an Android app. The app consists of three pages: the first page, index.html, displays a list of contents; the second page holds text content as well as a header with b ...

Send information using AJAX within a .NET integrated browser

In our current setup, we utilize a .NET embedded browser to showcase an HTML page that is generated by applying an XSLT file to an XML file using .NET. This process results in HTML content displayed within the embedded browser through the DocumentText prop ...

Using different CSS classes interchangeably in AngularJS

Imagine you have a list with an unknown number of items, ranging from one to potentially dozens. You want to display five CSS classes in a regular alternating pattern. What would be the most effective approach to achieve this? Here is some sample HTML cod ...

The browser is not displaying the HTML correctly for the Polymer Paper-Menu component

I attempted to implement a paper-menu, but I am facing issues with the rendered HTML and its interaction. When I click on a menu item, the entire list disappears due to the paper-item elements not being properly placed inside a key div within the paper-men ...

Utilizing React JS Styled-Components to Import Images from the Public Directory

I've been attempting to set the image as a background-image from the public folder using styled-components. I've tried the following: import styled from "styled-components"; import Background from 'process.env.PUBLIC_URL + /images/ ...

Using Vue to alter data through mutations

Greetings! I am currently in the process of developing a website for storing recipes, but as this is my first project, I am facing a challenge with modifying user input data. My goal is to create a system where each new recipe added by a user generates a u ...

In PHP, the symbol "!=" is used to compare if a string is not equal to a

Seeking feedback on why setting a string variable prevents me from calling it within a function. For instance: $name = "name"; $quote_name = "'".$name."'"; //echo of $name = name //echo of $quote_name = 'name' In PHP, I encounter iss ...

Is there a way to activate the width styling from one class to another?

I have these 2 elements in my webpage: //1st object <span class="ui-slider-handle" tabindex="0" style="left: 15.3153%;"></span> //2nd object <div id="waveform"> <wave style="display: block; position: relative; user-select: none; he ...

Can you provide instructions on creating a small border at the center of an h1 heading?

What is the best way to create a small border in the center of an h1 text element? ...

Navigating through Frames using Selenium in C#

I am facing an issue with using Selenium on this site. The elements I need to interact with are within a 'frame' that is inside a 'frameset'. Here is the relevant HTML snippet: <frameset rows="0%, 95%" frameborder="0" frameSpacing=" ...

The mobile navigation panel fails to open

I have a menu that I would like to toggle hide/show by adjusting its top position. Before logging in, the menu is structured as follows: <div class="lc"> <h1><a href="./"><img src="logo.png" /></a></h1> <a h ...

Images within links appear with blue lines underneath them

Currently, I am in the process of adding links to a footer by using <img> tags with SVG images. However, I am encountering an issue where there are small blue lines under the icons. After searching online, it seems that you need to add this CSS code: ...

The layout causes issues with responsiveness on the Flask app page

I'm currently in the process of developing a web application and I've implemented a navbar.html file as the layout for each page using the following code: eachpage.html : {% extends 'navbar.html' %} {% block body %} <div class=" ...

Appending a row to a table will not trigger events in Select2

Despite several attempts, I can't seem to get the select2:select event working on dynamically added rows in a table using select2. The event only works on the original row. Unfortunately, I don't have any additional details about this issue. COD ...

Optimizing VueJS applications with browser caching features for faster loading

I've encountered an issue with my VueJS app. After running npm run build, a new set of dist/* files are generated. However, when I upload them to the server (replacing the old build) and try to access the page in the browser, it seems to be loading th ...

Creating triangular side tabs with borders using CSS and HTML styling

I'm looking for a way to create triangle side navigation tabs similar to this example. I attempted using :after pseudo-element in my CSS: .tabs input + label:after{ content:""; float:left; position:absolute; top:0; right:-12px; width:0; height:0; bor ...

The tooltip is obscured by the table row

I'm having trouble with a simple CSS fix and can't seem to figure out why. The z-index and overflow visibility properties are not working as expected. I just need 'In Progress' to be displayed above everything else. Some things I' ...

Ways to prevent scrolling in Angular 6 when no content is available

I am developing an angular 6 application where I have scrollable divs containing: HTML: <button class="lefty paddle" id="left-button"> PREVIOUS </button> <div class="container"> <div class="inner" style="background:red">< ...

What could be the reason behind React's decision to not convert JSX to an HTML component and instead return [object Object]?

Please locate the specified console log within the code snippet provided below. This particular console log outputs a string value, indicating that an object is not being passed in this instance. However, despite this, React fails to recognize the JSX an ...

Is there a way to enhance the appearance of a TextField in JavaFX to resemble the sleek design of Android or material UI?

Is there a way to create a window like this in JavaFX? Take a look at the textfield shown in the image below... I recently came across the Jphonex framework that allows for this type of display. However, when I package it into a Jar file and try to run it ...