简体   繁体   English

如何在Chrome中以100%的宽度显示表格

[英]How do I display a table at width:100% in Chrome

I am debugging and extending an express app that displays a data set in a series of nested tables on a page. 我正在调试和扩展一个Express应用程序,该应用程序在页面上的一系列嵌套表中显示数据集。 Originally, all of the CSS was in style tags in the head tag of the HTML file and the tables displayed fine across 100% of the width of the page. 最初,所有CSS都位于HTML文件的head标签中的style标签中,并且表格在页面宽度的100%上显示良好。 When the CSS was on the same page it worked and this is the CSS being used to govern the width of the element we are trying to display: 当CSS位于同一页面上时,它可以工作,这是用来控制我们试图显示的元素宽度的CSS:

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

Now that I have taken off the style tags and moved the CSS to its own file, the width:100% style does not display. 现在,我已经脱掉了样式标签,并将CSS移到了自己的文件中,现在不会显示width:100%样式。

I have inspected the element in question inside of DevTools and when I look at the li.dir span class, Chrome and IE both eliminate the width:100% attribute. 我检查了DevTools内部有问题的元素,当我查看li.dir span类时,Chrome和IE都消除了width:100%属性。

这就是DevTools中span标签的类

I know that width is governed by the parent element so I have tried adding the style=width:100% property to each of the parent elements in order to try to brute force this particular style attribute but I still cant seem to find where to make this particular CSS property work. 我知道宽度是由父元素控制的,所以我尝试将style = width:100%属性添加到每个父元素中,以尝试强行使用此特定样式属性,但我似乎仍然找不到在哪里制作这个特殊的CSS属性。

Here is the parent div that governs where the table is created in my body: 这是父div,它控制在我的身体中创建表的位置:

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

The issue I have found has to do with the fact that the app is inserting DOM elements dynamically. 我发现的问题与应用程序动态插入DOM元素有关。 Somehow, Chrome is adding a style="display: inline-block attribute to an anchor tag that is acting as the parent to my table data. The problem is that I cannot find where this is being added because when I change the only place in my HTML file with this attribute to width:100% it still appears. Chrome莫名其妙地向作为表数据父级的锚标记添加了style =“ display:inline-block属性。问题是我找不到添加的位置,因为当我更改其中唯一的位置时我的HTML文件的width:100%属性仍然显示。

My guess is that display:inline-block is being inherited from bootstrap, but that's just a guess. 我的猜测是display:inline-block是从bootstrap继承的,但这只是一个猜测。

Here is my code dealing with the insertion of the parent element. 这是我的代码,涉及父元素的插入。 As you can see, I am trying to eliminate the display: inline-block in order to have width:100%. 如您所见,我正在尝试消除display:inline-block,以使其具有width:100%。 I don't have display: inline-block in my code, but yet it is being added somehow by default. 我没有显示:在代码中内联代码块,但是默认情况下会以某种方式添加它。 How do I get rid of it? 我如何摆脱它? Take a look at my code: 看一下我的代码:

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

         // This is the anchor tag in question
        '<a id="' + title + 'focus" style="width: 100%;"></a>' + 
        title + 
        '<span>' + 
            '<ul>' + 
                '<li id=\"' + title + "Table" + '\"></li>' + 
            '</ul>' + 
        '</span>' + 
    '</li>' + 
'</ul>';
}
tabobj.push(title);

Here is what it looks like in DevTools: 这是DevTools中的样子:

一个带有display:inline-block的'a'标签,它不应该在这里!

Why would it work in my class when it's in a style tag in the same HTML file but not in a separate CSS file? 当它在同一HTML文件中的样式标签中但不在单独的CSS文件中时,为什么在我的班级中可以工作?

Also, how do I get rid of that display:inline-block setting that Chrome and IE seem to be adding by default???? 另外,如何摆脱Chrome和IE默认添加的display:inline-block设置????

Please let me know if you can help me on this one and thanks! 请让我知道您是否可以在这一方面帮助我,谢谢!

Here is a link to the project on codePen: https://codepen.io/lopezdp/pen/GEzwmP 这是在CodePen上的项目链接: https ://codepen.io/lopezdp/pen/GEzwmP

So I tracked it down and started trying different solutions and I was able to solve it. 因此,我找到了它,并开始尝试其他解决方案,并且能够解决它。

Thanks for the help in figuring out what direction to take. 感谢您帮助我们确定应采取的方向。 The folowing anchor tag shows what I changed to my HTML in order to solve this issue: 以下锚标记显示了为解决此问题而对HTML所做的更改:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM