What is the best way to show a table with 100% width in the Chrome browser?

I am currently working on debugging and expanding an express application that showcases a dataset through a series of nested tables on a webpage. Initially, all the CSS resided within style tags in the head section of the HTML file, and the tables were displaying flawlessly across the entire width of the page. The CSS snippet below was responsible for controlling the element's width that we are attempting to showcase:

li.dir span {
    color: black;
    cursor: auto;
    -webkit-box-sizing: border-box ;
    -moz-box-sizing: border-box ;
    box-sizing: border-box ;
    width: 100%;
}

However, after moving the CSS to its separate file and removing the style tags, the style declaration width:100% no longer takes effect.

Upon inspecting the element in question using DevTools, I observed that both Chrome and IE are removing the width:100% attribute from the li.dir span class.

https://i.sstatic.net/7NPzi.png

Realizing that the width is dictated by the parent element, I tried adding the style="width:100%" property to each parent element in an attempt to force this specific style attribute, yet I still couldn't pinpoint where to ensure this particular CSS property works.

The primary div governing the table's placement in the body is provided below:

<div id="url"></div>
<div class="create"></div>

The challenge lies in the fact that the application dynamically inserts DOM elements. Somehow, Chrome automatically adds a style="display: inline-block attribute to an anchor tag acting as the parent to my table data. Despite modifying the only instance in my HTML file with this attribute to width:100%, it persists.

I suspect that display:inline-block is inherited from Bootstrap, but I cannot confirm this.

Below is a snippet of my code pertaining to the parent element insertion. Notice that I'm striving to remove display: inline-block to achieve width:100%. Though display: inline-block isn't explicitly present in my code, it seems to be added by default. How can I eliminate it? Kindly review the code:

table += 
'<ul>' + 
    '<li class="dir" id="' + title + '">' + 

         // Anchor tag under scrutiny
        '<a id="' + title + 'focus" style="width: 100%;"></a>' + 
        title + 
        '<span>' + 
            '<ul>' + 
                '<li id=\"' + title + "Table" + '\"></li>' + 
            '</ul>' + 
        '</span>' + 
    '</li>' + 
'</ul>';
}
tabobj.push(title);

An inspection in DevTools reveals the following:

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

Why does it function as intended when the CSS is contained within a style tag in the same HTML file but fails when placed in a separate CSS file?

Furthermore, how can I eliminate the default display:inline-block setting that Chrome and IE seem to be inserting?

If you can provide any guidance on this matter, I would greatly appreciate it. Thank you!

For reference, here is the project on codePen: https://codepen.io/lopezdp/pen/GEzwmP

Answer №1

After a bit of investigating, I was able to track down the problem and find a solution that worked.

Big thanks to everyone who helped point me in the right direction. The snippet below illustrates the HTML code change I made to fix the issue:

'<div id="' + title + 'focus" style="width: 100%; display: none; overflow: auto;"></div>'

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 the technique to enable this div to be clickable?

I am trying to make each "card" of a WordPress plugin clickable on my website. I have inserted a Pure JS element with the following code: document.getElementsByClassName('fc_card-container').onclick = function() {alert('It works!');} ...

Is there a way to determine the remaining time or percentage until document.ready is reached?

My usual approach is to display a loading animation like this: $('#load').show(); $(document).ready(function(){ $('#load').hide(); }); where the <div id="load"> contains just an animated gif. However, I've been conside ...

Experiencing difficulties with running the prefixer script in npm

I'm facing issues while trying to run prefix CSS despite having installed the necessary npm packages like prefixer and postcss-cli in my development environment. When attempting to run the prefixer for my CSS file, I encountered some errors. Here&apos ...

Trying to update React and Electron, encountering the error message "global is not defined"

I have an Electron + React app that has not been updated in a couple of years, initially utilizing the following packages: "@rescripts/cli": "^0.0.13", "@rescripts/rescript-env": "^0.0.11", "electron": &quo ...

The Bootstrap carousel comes with a brilliant feature! Conceal those 'previous' and 'next' buttons when you reach the first and last slide. However, it seems like the 'slide' event is not functioning as

I have implemented a standard Bootstrap carousel on my website: <div id="myCarousel" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#myCarousel" data- ...

Differences in HTML animations can be seen when comparing Google Chrome to Microsoft Edge. Looking for a workaround for autoplay to ensure

My intro video animation is facing recording difficulties due to the autoplay policy in Google Chrome. It seems nearly impossible to capture it accurately. If only autoplay could function for an offline HTML file, my issue would be resolved. Unfortunately ...

incorporating a personalized HTMLElement using Typescript

Hey there! I'm fairly new to using Angular and could use some help. I'm trying to insert a custom HTML element onto a page when a button is clicked, but I'm struggling to figure it out. Here are my HTML and TypeScript files: TypeScript Fil ...

Merge the elements of one array with the elements of another array simultaneously

Can a function be created that combines each value from two arrays, even if the arrays are of different lengths? For example: arr1 = ["apple", "banana", "cherry"]; arr2 = ["pear", "kiwi", "orange"] mergedArr= ["applepear", "applekiwi", "appleorange", " ...

Converting JSON to JS in Django results in an error: SyntaxError indicating a missing colon after the property

I'm trying to figure out how to incorporate a JSON file into a script. I've been unsuccessful in loading it from the filesystem, so I created a view that serves the JSON data directly to the page like this: def graph(request, d): ...

Arranging an array in alphabetical order, with some special cases taken into consideration

Below is a breakdown of the array structure: [{ name: "Mobile Uploads" }, { name: "Profile Pictures" }, { name: "Reports" }, { name: "Instagram Photos" }, { name: "Facebook" }, { name: "My Account" }, { name: "Twi ...

Calculating the total length of an SVG element using React

Looking to animate an SVG path using React (similar to how it's done in traditional JavaScript: https://css-tricks.com/svg-line-animation-works/), but struggling when the path is created using JSX. How can I find the total length of the path in this s ...

What is the best way to retrieve text from the p tag and input it into the text field?

Looking to resolve a situation where two identical IDs exist and need to implement some JQuery. The objective is for the input value to automatically update itself based on changes in the text of the p tag. $(document).ready(function(){ ...

I am unable to employ the useMutation or useQuery features in Apollo Client 3.0

import { useMutation } from '@apollo/client';; function LockedBlog() { const [lockedBlog] = useMutation(LOCKED_BLOG); }; class EditBlog extends Component { state = { ...initialState }; index.js import React from "react"; im ...

Apollo Client is not properly sending non-server-side rendered requests in conjunction with Next.js

I'm facing a challenge where only server-side requests are being transmitted by the Apollo Client. As far as I know, there should be a client created during initialization in the _app file for non-SSR requests, and another when an SSR request is requi ...

Navigating through nested JSON arrays in JavaScript involves looping through multiple dimensions

I am facing difficulty finding the correct solution to my issue here. I am trying to iterate through the nested Products arrays in order to display each Product name. Can this be achieved with my current code, or should I consider rewriting it to make qu ...

Determine the percentage using jQuery by considering various factors

I am facing an issue with the following code snippet: <script type="application/javascript"> $(document).ready(function () { $("#market_value").on("change paste keyup", function() { var market_value = par ...

Having trouble loading services within my Angular controller

After developing my Angular application, I added some basic code to my controller which is displayed below. Now, I am attempting to include two services that I created in my services.js file. This file is being loaded in my index.html and required within m ...

What is the best way to include a span within a select option element to display a flag beside each option?

I'm currently working on a dropdown menu that allows users to easily select their preferred language. I'm facing an issue with incorporating flags using https://github.com/lipis/flag-icon-css for each option. Can someone please assist me with thi ...

Strategies for efficiently updating specific objects within a state array by utilizing keys retrieved from the DOM

I am trying to figure out how to use the spread operator to update state arrays with objects that have specific ids. Currently, I have an array called "todos" containing objects like this: todos: [ { id: "1", description: "Run", co ...

Tips for automatically collapsing the Bootstrap 4 Sidebar on smaller devices

I am currently working on some code and have successfully hidden the sidebar using a collapse button. However, I am looking to make it collapse only for small devices, similar to how the bootstrap navbar functions. <link href="https://stackpath.boots ...