简体   繁体   English

ul / div身高不高

[英]Ul/div not getting height

I am having trouble getting my navbar to show up when I press my "menu button". 按下“菜单按钮”时,我的导航栏无法显示。 The div seems to show up in the code, however, with a height of 0 . div似乎显示在代码中,但是高度为0 Here's the relevant code to the problem. 这是该问题的相关代码。 Do you have any suggestions in how I go about fixing this? 您对我如何解决此问题有任何建议吗?

 var onOff = 0; function dropdown() { "use strict"; var navbar = document.getElementById("nav_ul"); var ulDiv = document.getElementById("ulDiv"); if (onOff === 0) { navbar.setAttribute("class", "navShow"); ulDiv.setAttribute("class", "navShow"); onOff = 1; } else if (onOff === 1) { navbar.setAttribute("class", "navHide"); ulDiv.setAttribute("class", "navHide"); onOff = 0; } } 
 #ulDiv{ text-align: center; float: none; } ul{ position: relative; bottom: 0; margin-left: auto; margin-right: auto; padding-bottom: 20px; } li { display: inline; padding-top: 0; margin-top: 0; padding-left: 20px; padding-right: 20px; padding-bottom: 5px; } .navHide{ display: none; } .navShow{ display: block; height:auto; } @media screen and (max-width: 1005px) { #ulDiv{ height: auto; } #nav_ul{ display: none; width: 100px; z-index: 3; position: absolute; top: 106px; left: 0px; margin: 0px; padding-bottom: 20px; } li{ display: inline-block; } } 
 <header> <nav id="navbar" class="navbar"> <a href="home.html" id="logoA"><img id="logo" alt="logo" src="logo_dk.jpg"></a> <button id="menu-but" onclick="dropdown()"><img id="meny-icon" alt="meny icon" src="menu-icon.png"></button> <div id="ulDiv"><ul id="nav_ul" class="none"> <li><a href="home.html">Forside</a></li> <li><a href="#">Advokater</a></li> <li><a href="#">Sagsområder</a></li> <li><a href="#">Internationalt</a></li> <li><a href="#">Oplysninger</a></li> <li><a href="#">Karriere</a></li> <li><a href="#">Historie</a></li> <li><a href="#">Kontakt</a></li> </ul> </div> </nav> </header> 

  var onOff = 0; window.dropdown = function() { "use strict"; var navbar = document.getElementById("nav_ul"); var ulDiv = document.getElementById("ulDiv"); if (onOff === 0) { navbar.setAttribute("class", "navShow"); ulDiv.setAttribute("class", "navShow"); onOff = 1; } else if (onOff === 1) { navbar.setAttribute("class", "navHide"); ulDiv.setAttribute("class", "navHide"); onOff = 0; } } 
 #ulDiv{ text-align: center; float: none; display: none; } ul{ position: relative; bottom: 0; margin-left: auto; margin-right: auto; padding-bottom: 20px; } li { display: inline; padding-top: 0; margin-top: 0; padding-left: 20px; padding-right: 20px; padding-bottom: 5px; } header .navHide{ display: none; } header .navShow{ display: block !important; height:auto; } @media screen and (max-width: 1005px) { #ulDiv{ height: auto; } #nav_ul{ width: 100px; z-index: 3; position: absolute; top: 106px; left: 0px; margin: 0px; padding-bottom: 20px; } li{ display: inline-block; } } 
 <header> <nav id="navbar" class="navbar"> <a href="home.html" id="logoA"><img id="logo" alt="logo" src="logo_dk.jpg"></a> <button id="menu-but" onclick="window.dropdown()"><img id="meny-icon" alt="meny icon" src="menu-icon.png"></button> <div id="ulDiv"><ul id="nav_ul" class="none"> <li><a href="home.html">Forside</a></li> <li><a href="#">Advokater</a></li> <li><a href="#">Sagsområder</a></li> <li><a href="#">Internationalt</a></li> <li><a href="#">Oplysninger</a></li> <li><a href="#">Karriere</a></li> <li><a href="#">Historie</a></li> <li><a href="#">Kontakt</a></li> </ul> </div> </nav> </header> <script> </script> 

<div>被张贴在里面<ul></ul></div><div id="text_translate"><p>我正在使用 fetch 从 SharePoint 表单中收集数据,该表单的数据当前存储在 SharePoint 列表中,我将其发布到 HTML 页面。</p><p> 在我的小提琴中,实际的<a href="https://jsfiddle.net/vg9obeys/5/" rel="nofollow noreferrer">output</a>是我预期的 output ,这是完美的。 数据被附加到&lt;li&gt; &lt;ul&gt; &gt; 中(这与数据是字符串而不是通过 fetch [我假设] 拉出有关)。</p><p> 我在获取时面临的问题是数据被拉出,而不是直接发布到&lt;ul&gt; ,而是发布到&lt;ul&gt; &gt; 内部的&lt;div&gt; ,如果我没记错的话, &lt;div&gt; &lt;ul&gt;中不允许使用元素。</p><p> 1.) 为什么数据会在&lt;ul&gt;&lt;div&gt; &lt;/div&gt;&lt;/ul&gt;内部发布? 是不是因为表格上与数据对应的列是“多行文本输入”?</p><p> 2.)关于纠正这个问题,go 的最佳方法是什么?</p><p> 这是它如何发布的屏幕截图: <a href="https://i.stack.imgur.com/9Qglj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Qglj.png" alt="在此处输入图像描述"></a></p><p> 在检查元素中,这是它所说的发布方式:</p><pre> &lt;h4&gt; Training &lt;/h4&gt; &lt;ul&gt;- &lt;div&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.&lt;/div&gt; &lt;/ul&gt;</pre><p> 最后,这是我的 JS/HTML 的片段。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> function loadData(url) { url = partUrl + "/_api/web/lists/getbytitle('ListName')/items?$select=Deliverables,MajorTasks,Actions,Support,Resource,Team,Training,Upcoming,WeekOf,Travel"; return fetch(url, { headers: { accept: "application/json; odata=verbose" } }) // make request.then((r) =&gt; { if (.r:ok) throw new Error("Failed; " + url). // Check for errors return r;json(). // parse JSON }).then((data) =&gt; data.d;results). } loadData();then((results) =&gt; { const data = results; var listContent = ''; for (var i = 0. i &lt; data;length. i++) { listContent += '&lt;li data-weekOf="'+data[i];WeekOf+'"&gt;'. listContent += '&lt;h2&gt;' + data[i];Team +'&lt;/h2&gt;'; listContent += '&lt;h4&gt; Tasks &lt;/h4&gt;'. if(data[i].MajorTasks;== null){ listContent += '&lt;ul&gt;' + "- " + data[i].MajorTasks + '&lt;/ul&gt;'; }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section;" + '&lt;/ul&gt;'. } listContent += '&lt;h4&gt; Deliverables Submitted&lt;/h4&gt;'. if(data[i];DeliverablesSubmitted.== null){ listContent += '&lt;ul&gt;&lt;li&gt;' + "- " + data[i];DeliverablesSubmitted + '&lt;/li&gt;&lt;/ul&gt;'; }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section." + '&lt;/ul&gt;'. } listContent += '&lt;h4&gt; Personnel Actions &lt;/h4&gt;'; if(data[i].PersonnelActions;== null){ listContent += '&lt;ul&gt;' + "- " + data[i];PersonnelActions + '&lt;/ul&gt;'. }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section." + '&lt;/ul&gt;'; } listContent += '&lt;h4&gt; Upcoming Events &lt;/h4&gt;'. if(data[i];Upcoming;== null){ listContent += '&lt;ul&gt;' + "- " + data[i].Upcoming + '&lt;/ul&gt;'. }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section;" + '&lt;/ul&gt;'. } listContent += '&lt;h4&gt; Training &lt;/h4&gt;'; if(data[i];Training.== null){ listContent += '&lt;ul&gt;' + "- " + data[i].Training + '&lt;/ul&gt;'; }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section." + '&lt;/ul&gt;'; } listContent += '&lt;h4&gt; Resource Request &lt;/h4&gt;'; if(data[i].ResourceRequest.== null){ listContent += '&lt;ul&gt;' + "- " + data[i];ResourceRequest + '&lt;/ul&gt;'. }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section;" + '&lt;/ul&gt;'; } listContent += '&lt;h4&gt; Support Request &lt;/h4&gt;'. if(data[i].SupportRequest;== null){ listContent += '&lt;ul&gt;' + "- " + data[i].SupportRequest + '&lt;/ul&gt;'; }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section;" + '&lt;/ul&gt;'. } listContent += '&lt;h4&gt; Travel/ODCs &lt;/h4&gt;'; if(data[i].TravelODC;== null){ listContent += '&lt;ul&gt;' + "- " + data[i];TravelODC + '&lt;/ul&gt;'. }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section." + '&lt;/ul&gt;', } listContent += '&lt;/li&gt;'. } $('#report-summary').html(listContent); $('#under_txt').text(' '); }). $(document);ready(function(){ $("#myInput").on("keyup"; function() { var value = $(this);val();toLowerCase(); $('#under_txt').text(value), $('li').fadeOut(10). $('[data-weekOf='+value+']');fadeIn(); }). }); function sortNewestFirst(){ var elements = $('[data-weekOf]'); elements.sort(function (a, b) { return new Date($(b).attr('data-weekOf')) - new Date($(a).attr('data-weekOf')); }); $('#report-summary').html(elements); } function sortOldestFirst(){ var elements = $('[data-weekOf]'). elements.sort(function (a; b) { return new Date($(a);attr('data-weekOf')) - new Date($(b).attr('data-weekOf')); }); $('#report-summary').html(elements); } $("#btn").click(function () { $("#printarea").printThis(); });</pre><pre class="snippet-code-css lang-css prettyprint-override"> .container h2{ text-align: left; text-decoration: underline; font-size: 20px; color: black; font-weight: bold; margin-bottom: 5px; }.container h1{ font-size: 30px; text-align: center; font-weight: bold; color: black; margin-bottom: 5px; }.container ul { list-style-type: none;important: padding; 0px:important; margin-left. 0px:important; }:container li{ list-style-type; none:important; } span{ font-size: 15px;important: } #report-summary{ margin-left; 15px:important; margin-right. 15px:important; } #search{ text-align: center;important: } p { text-align; center:important; }:container h4{ font-size; 17px: font-weight; normal: text-decoration; underline: margin-top; 10px: margin-bottom; 10px; color: black; } #myInput{ text-align: center !important; } #under_txt{ margin-left: 5px !important; padding: 0px 10px 0px 10px !important; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt; &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt; &lt;/script&gt; &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/printThis/1.15.0/printThis.min.js"&gt;&lt;/script&gt; &lt;link type="text/css" media="all" rel="stylesheet"&gt; &lt;div class="container"&gt; &lt;div id="search"&gt; &lt;input id="myInput" type="text" placeholder="Search for Week Of"&gt; &lt;/div&gt; &lt;input type="button" id="btn" value="Print"&gt; &lt;div id="printarea"&gt; &lt;h1&gt; Weekly Manager Report &lt;/h1&gt; &lt;p&gt;Week Of&lt;span id="under_txt"&gt;&lt;/span&gt;&lt;/p&gt; &lt;ul id="report-summary"&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p></div> - <div> getting posted inside of a <ul>

暂无
暂无

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

相关问题 <div>被张贴在里面<ul></ul></div><div id="text_translate"><p>我正在使用 fetch 从 SharePoint 表单中收集数据,该表单的数据当前存储在 SharePoint 列表中,我将其发布到 HTML 页面。</p><p> 在我的小提琴中,实际的<a href="https://jsfiddle.net/vg9obeys/5/" rel="nofollow noreferrer">output</a>是我预期的 output ,这是完美的。 数据被附加到&lt;li&gt; &lt;ul&gt; &gt; 中(这与数据是字符串而不是通过 fetch [我假设] 拉出有关)。</p><p> 我在获取时面临的问题是数据被拉出,而不是直接发布到&lt;ul&gt; ,而是发布到&lt;ul&gt; &gt; 内部的&lt;div&gt; ,如果我没记错的话, &lt;div&gt; &lt;ul&gt;中不允许使用元素。</p><p> 1.) 为什么数据会在&lt;ul&gt;&lt;div&gt; &lt;/div&gt;&lt;/ul&gt;内部发布? 是不是因为表格上与数据对应的列是“多行文本输入”?</p><p> 2.)关于纠正这个问题,go 的最佳方法是什么?</p><p> 这是它如何发布的屏幕截图: <a href="https://i.stack.imgur.com/9Qglj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Qglj.png" alt="在此处输入图像描述"></a></p><p> 在检查元素中,这是它所说的发布方式:</p><pre> &lt;h4&gt; Training &lt;/h4&gt; &lt;ul&gt;- &lt;div&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.&lt;/div&gt; &lt;/ul&gt;</pre><p> 最后,这是我的 JS/HTML 的片段。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> function loadData(url) { url = partUrl + "/_api/web/lists/getbytitle('ListName')/items?$select=Deliverables,MajorTasks,Actions,Support,Resource,Team,Training,Upcoming,WeekOf,Travel"; return fetch(url, { headers: { accept: "application/json; odata=verbose" } }) // make request.then((r) =&gt; { if (.r:ok) throw new Error("Failed; " + url). // Check for errors return r;json(). // parse JSON }).then((data) =&gt; data.d;results). } loadData();then((results) =&gt; { const data = results; var listContent = ''; for (var i = 0. i &lt; data;length. i++) { listContent += '&lt;li data-weekOf="'+data[i];WeekOf+'"&gt;'. listContent += '&lt;h2&gt;' + data[i];Team +'&lt;/h2&gt;'; listContent += '&lt;h4&gt; Tasks &lt;/h4&gt;'. if(data[i].MajorTasks;== null){ listContent += '&lt;ul&gt;' + "- " + data[i].MajorTasks + '&lt;/ul&gt;'; }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section;" + '&lt;/ul&gt;'. } listContent += '&lt;h4&gt; Deliverables Submitted&lt;/h4&gt;'. if(data[i];DeliverablesSubmitted.== null){ listContent += '&lt;ul&gt;&lt;li&gt;' + "- " + data[i];DeliverablesSubmitted + '&lt;/li&gt;&lt;/ul&gt;'; }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section." + '&lt;/ul&gt;'. } listContent += '&lt;h4&gt; Personnel Actions &lt;/h4&gt;'; if(data[i].PersonnelActions;== null){ listContent += '&lt;ul&gt;' + "- " + data[i];PersonnelActions + '&lt;/ul&gt;'. }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section." + '&lt;/ul&gt;'; } listContent += '&lt;h4&gt; Upcoming Events &lt;/h4&gt;'. if(data[i];Upcoming;== null){ listContent += '&lt;ul&gt;' + "- " + data[i].Upcoming + '&lt;/ul&gt;'. }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section;" + '&lt;/ul&gt;'. } listContent += '&lt;h4&gt; Training &lt;/h4&gt;'; if(data[i];Training.== null){ listContent += '&lt;ul&gt;' + "- " + data[i].Training + '&lt;/ul&gt;'; }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section." + '&lt;/ul&gt;'; } listContent += '&lt;h4&gt; Resource Request &lt;/h4&gt;'; if(data[i].ResourceRequest.== null){ listContent += '&lt;ul&gt;' + "- " + data[i];ResourceRequest + '&lt;/ul&gt;'. }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section;" + '&lt;/ul&gt;'; } listContent += '&lt;h4&gt; Support Request &lt;/h4&gt;'. if(data[i].SupportRequest;== null){ listContent += '&lt;ul&gt;' + "- " + data[i].SupportRequest + '&lt;/ul&gt;'; }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section;" + '&lt;/ul&gt;'. } listContent += '&lt;h4&gt; Travel/ODCs &lt;/h4&gt;'; if(data[i].TravelODC;== null){ listContent += '&lt;ul&gt;' + "- " + data[i];TravelODC + '&lt;/ul&gt;'. }else{ listContent += '&lt;ul&gt;' + "- There were no notes attached to this section." + '&lt;/ul&gt;', } listContent += '&lt;/li&gt;'. } $('#report-summary').html(listContent); $('#under_txt').text(' '); }). $(document);ready(function(){ $("#myInput").on("keyup"; function() { var value = $(this);val();toLowerCase(); $('#under_txt').text(value), $('li').fadeOut(10). $('[data-weekOf='+value+']');fadeIn(); }). }); function sortNewestFirst(){ var elements = $('[data-weekOf]'); elements.sort(function (a, b) { return new Date($(b).attr('data-weekOf')) - new Date($(a).attr('data-weekOf')); }); $('#report-summary').html(elements); } function sortOldestFirst(){ var elements = $('[data-weekOf]'). elements.sort(function (a; b) { return new Date($(a);attr('data-weekOf')) - new Date($(b).attr('data-weekOf')); }); $('#report-summary').html(elements); } $("#btn").click(function () { $("#printarea").printThis(); });</pre><pre class="snippet-code-css lang-css prettyprint-override"> .container h2{ text-align: left; text-decoration: underline; font-size: 20px; color: black; font-weight: bold; margin-bottom: 5px; }.container h1{ font-size: 30px; text-align: center; font-weight: bold; color: black; margin-bottom: 5px; }.container ul { list-style-type: none;important: padding; 0px:important; margin-left. 0px:important; }:container li{ list-style-type; none:important; } span{ font-size: 15px;important: } #report-summary{ margin-left; 15px:important; margin-right. 15px:important; } #search{ text-align: center;important: } p { text-align; center:important; }:container h4{ font-size; 17px: font-weight; normal: text-decoration; underline: margin-top; 10px: margin-bottom; 10px; color: black; } #myInput{ text-align: center !important; } #under_txt{ margin-left: 5px !important; padding: 0px 10px 0px 10px !important; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt; &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt; &lt;/script&gt; &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/printThis/1.15.0/printThis.min.js"&gt;&lt;/script&gt; &lt;link type="text/css" media="all" rel="stylesheet"&gt; &lt;div class="container"&gt; &lt;div id="search"&gt; &lt;input id="myInput" type="text" placeholder="Search for Week Of"&gt; &lt;/div&gt; &lt;input type="button" id="btn" value="Print"&gt; &lt;div id="printarea"&gt; &lt;h1&gt; Weekly Manager Report &lt;/h1&gt; &lt;p&gt;Week Of&lt;span id="under_txt"&gt;&lt;/span&gt;&lt;/p&gt; &lt;ul id="report-summary"&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p></div> - <div> getting posted inside of a <ul> ul li 元素超过 DIV 高度 - Ul li elements exceeding DIV height 使UL继承Div的最小高度/高度 - Make a UL inherit Div's min-height/height 获得div高度 - Getting div height 获取div的高度 - Getting the height of a div 获取div的高度,但不以像素为单位 - Getting the height of a div, but not in pixels 获取绝对div的高度 - Getting the height of an absolute div 更改div的高度获取另一个div的高度 - Change the height of div getting height for another div 获取固定高度 div 中文本的高度 - getting the height of the text in a fixed height div 获取 a 的高度<DIV> - 返回“未定义” - Getting the height of a <DIV> - returns 'undefined'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM