zero-padding 相关问题


错误 | prefect.flow_runs.runner - 流程运行进程退出,状态代码:-7

我在运行脚本时收到此完美错误。错误如下: 0%| | 0/2070 [00:00 我在运行脚本时收到此完美错误。错误如下: 0%| | 0/2070 [00:00<?, ?it/s]09:36:01.917 | ERROR | prefect.flow_runs.runner - Process for flow run 'auspicious-butterfly' exited with status code: -7 09:36:02.057 | INFO | prefect.flow_runs.runner - Reported flow run '1f314ccd-1472-4373-bb1b-4b3b6265b29a' as crashed: Flow run process exited with non-zero status code -7. 不知道为什么。任何帮助将不胜感激。 我和 Prefect 也有同样的错误。您有什么版本的 Prefect? Reported flow run 'bbaa6e16-bf5f-44ff-a31b-d68645f74bb1' as crashed: Flow run process exited with non-zero status code -7. Process for flow run 'xi5-zeon' exited with status code: -7


为什么 .className = .... 不起作用,而 classList.add() 却起作用?

.youtube-文本{ 字体系列:Arial; 字体大小:更大; } .订阅按钮{ 字体系列...</desc> <question vote="0"> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; .youtube-text { font-family: Arial; font-size: larger; } .subscribe-button { font-family: &#39;Arial Narrow Bold&#39;; font-size: large; color: white; background-color: black; padding-left: 12px; padding-top: 12px ; padding-bottom: 12px ; padding-right: 12px; border-radius: 20px; } .is-subscribed { font-family: &#39;Arial Narrow Bold&#39;; font-size: large; color: black; background-color: white; padding-left: 12px; padding-top: 12px ; padding-bottom: 12px ; padding-right: 12px; border-radius: 20px; } &lt;/style&gt; &lt;title&gt; &lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;p2&gt;Youtube Subscribe Button&lt;/p2&gt;&lt;br&gt;&lt;Br&gt; &lt;button class = &#39;subscribe-button&#39; onclick=&#34; subscribeButton(); &#34;&gt;Subscribe&lt;/button&gt; &lt;script async&gt; function subscribeButton() { const subButton = document.querySelector(&#39;.subscribe-button&#39;); if (subButton.innerHTML === &#39;Subscribe&#39;){ subButton.innerHTML = &#39;Subscribed&#39;; subButton.classList.add(&#39;is-subscribed&#39;); } else { subButton.innerHTML = &#39;Subscribe&#39;; subButton.classList.remove(&#39;is-subscribed&#39;); } } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; .youtube-text { font-family: Arial; font-size: larger; } .subscribe-button { font-family: &#39;Arial Narrow Bold&#39;; font-size: large; color: white; background-color: black; padding-left: 12px; padding-top: 12px ; padding-bottom: 12px ; padding-right: 12px; border-radius: 20px; } .is-subscribed { font-family: &#39;Arial Narrow Bold&#39;; font-size: large; color: black; background-color: white; padding-left: 12px; padding-top: 12px ; padding-bottom: 12px ; padding-right: 12px; border-radius: 20px; } &lt;/style&gt; &lt;title&gt; &lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;p2&gt;Youtube Subscribe Button&lt;/p2&gt;&lt;br&gt;&lt;Br&gt; &lt;button class = &#39;subscribe-button&#39; onclick=&#34; subscribeButton(); &#34;&gt;Subscribe&lt;/button&gt; &lt;script async&gt; function subscribeButton() { const subButton = document.querySelector(&#39;.subscribe-button&#39;); if (subButton.innerHTML === &#39;Subscribe&#39;){ subButton.innerHTML = &#39;Subscribed&#39;; subButton.className = &#39;is-subscribed&#39;; } else { subButton.innerHTML = &#39;Subscribe&#39;; subButton.className = &#39;subscribe-button&#39;; } } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>你好, 我刚刚开始使用 JS,想知道我遇到的这个问题。顶部的代码有效,底部的代码无效,第一次单击时,它确实将类更改为已订阅,但是当我按下按钮,它给出了一个错误,并且不再改变它,我只是想知道为什么会这样。</p> </question> <answer tick="false" vote="0"> <p>默认的 DOM elemnt 对象没有名为 <pre><code>className</code></pre> 的属性。将 classList 属性与 <pre><code>.add()</code></pre> 和 <pre><code>.remove()</code></pre> 方法结合使用。</p> </answer> <answer tick="false" vote="0"> <blockquote> <p>但是当我按下按钮时,它给出了一个错误并且不再改变它</p> </blockquote> <p>当您按下按钮时,代码会按类查找元素:</p> <pre><code>const subButton = document.querySelector(&#39;.subscribe-button&#39;); </code></pre> <p>但是该类没有这样的元素。当您设置 <em><code>className</code></em> 时,您<pre>删除了</pre>该类:</p> <pre><code>subButton.className = &#39;is-subscribed&#39;; </code></pre> <p>这<em>用</em><code>class</code><pre>替换了</pre>整个<pre><code>is-subscribed</code></pre>,而不是<em>添加</em>到类列表中。</p> </answer> </body></html>


swiftUI picker(Picker 中内容的填充不起作用)

无论如何都可以在选择器中“填充”内容。如Picker中的“Text”.padding() 选择器(选择:$picked){ ForEach(0...10, id: \...


C 中的结构填充

我读过有关 C 中结构填充的文章: http://bytes.com/topic/c/answers/543879-what-struct-padding 并在文章后写了这段代码,应该打印出 'struct pad' 的大小,如 16...


过多的padding导致NN模型精度下降

我训练了一个简单的神经网络模型来进行二元分类,并能够区分真假新闻 #创建模型的类 类 FakeNewsDetectionModelV0(nn.Module): ...


如何在 Rust 中指定与 const 泛型参数不同的类型?

我将为坐标创建一个通用类型。它应该能够指定每个轴的基数类型。 起初,我的代码如下所示: 使用 num::Signed; 结构坐标 我将为坐标创建一个通用类型。它应该能够指定每个轴的基数类型。 首先,我的代码如下所示: use num::Signed; struct Coordinate<Index: Signed> { x: Index, y: Index, } 另外,我希望它携带额外的绑定信息来帮助我检查实现中的访问,所以我写了这个。 use num::Signed; struct Coordinate<const Bound: isize, Index: Signed> { x: Index, y: Index, } 但是,即使Signed仅针对i8, ..., isize实现,我也不能简单地将Signed的值与isize进行比较。所以我转向这个: use num::Signed; struct Coordinate<const Bound: Index, Index: Signed> { x: Index, y: Index, } 当然,失败了。我想知道是否有任何可能的解决方案来解决这个问题。 您的第一个版本正朝着正确的方向发展,它只需要更多的特征界限: use num::Signed; #[derive(Debug)] struct Coordinate<const BOUND: isize, Index> where Index: Signed + PartialOrd + NumCast, isize: From<Index>, { x: Index, y: Index, } impl<const BOUND: isize, Index> Coordinate<BOUND, Index> where Index: Signed + PartialOrd + Copy, isize: From<Index>, { pub fn new(x: Index, y: Index) -> Option<Self> { if x >= Index::zero() && y >= Index::zero() && isize::from(x) < BOUND && isize::from(y) < BOUND { Some(Self { x, y }) } else { None } } } fn main() { dbg!(Coordinate::<10, i16>::new(5, 3)); dbg!(Coordinate::<10, i16>::new(5, 11)); } [src\main.rs:32] Coordinate::<10, i16>::new(5, 3) = Some( Coordinate { x: 5, y: 3, }, ) [src\main.rs:33] Coordinate::<10, i16>::new(5, 11) = None


填充区域显示的隐藏内容溢出,可以隐藏吗?

div{内边距:5px;溢出:隐藏;高度:20px} 某事某事某事某事某事某事 <style> div{padding:5px;overflow:hidden;height:20px} </style> <div class="container"> something something something something something something something something something something something something something something <div> 小提琴:https://jsfiddle.net/v21vgzfc/ 在CSS中是否可以使文本也隐藏在填充区域中而不添加另一层? 是的,我会使用边框而不是填充。像这样: div{ border:solid 5px #00f; overflow:hidden; height:20px } 我想请给div一个宽度 <style> div{padding:5px;overflow:hidden;height:40px; width:250px; background:#009} </style> 您可以通过使用边框而不是填充来解决此问题。 div { border: 5px solid blue; overflow: hidden; background-color: blue; height: 40px } 看看它是如何在 this Fiddle 中工作的。 U 应该在父元素内创建一个嵌套元素,并将 overflow: hidden 应用于该嵌套元素。 <div class="parent"> <div class="child"> <!-- Content here --> </div> </div> .parent { padding: 20px; overflow: hidden; } .child { overflow: hidden; }


将 2 个弹性列合并为 1 个交替的子列

我有一个有 2 列的弹性容器。 每列也是一个弹性容器,里面有许多盒子。 我有一个 flex 容器,有 2 列。 每列也是一个弹性容器,里面有许多盒子。 <div class="flex-container"> <div class="column left-column"> <div class="box boxA">Box A</div> <div class="box boxB">Box B</div> </div> <div class="column right-column"> <div class="box boxC">Box C</div> <div class="box boxD">Box D</div> <div class="box boxE">Box E</div> </div> </div> 我希望在移动视图中,2 列变成 1。 现在,我通过将 flex-direction: column 添加到 flex-container 来实现这一点,这使得 2 列彼此重叠(垂直,而不是 z 轴)。 .flex-container { display: flex; gap: 10px; padding: 10px; max-width: 800px; } .column { display: flex; flex-direction: column; flex: 1; gap: 10px; } .left-column { flex: 2; } .right-column { flex: 1; } .box { border: 1px solid lightgrey; border-radius: 8px; padding: 8px; } @media (max-width: 800px) { .flex-container { flex-direction: column; } } 但现在我还需要重新排列框的顺序,以便在移动视图中显示为 A、C、D、E、B。 我认为仅使用 CSS 无法实现这一点,因为它需要“破坏”弹性列。 这是我目前拥有的沙箱:https://codepen.io/marcysutton/pen/ZYqjPj 顺便说一句,这是在 React 应用程序中,所以我可能必须以编程方式重新排列框。 如果可能的话,我只是更喜欢使用 CSS 来做到这一点。 在下部宽度处使用 display: contents“破坏”包装 div,然后在 order 上使用 .boxB。 .flex-container { display: flex; gap: 10px; padding: 10px; max-width: 800px; } .column { display: flex; flex-direction: column; flex: 1; gap: 10px; } .left-column { flex: 2; } .right-column { flex: 1; } .box { border: 1px solid lightgrey; border-radius: 8px; padding: 8px; } @media (max-width: 800px) { .flex-container { flex-direction: column; } .column { display: contents; } .boxB { order: 2; } } <div class="flex-container"> <div class="column left-column"> <div class="box boxA">Box A</div> <div class="box boxB">Box B</div> </div> <div class="column right-column"> <div class="box boxC">Box C</div> <div class="box boxD">Box D</div> <div class="box boxE">Box E</div> </div> </div>


如何让div在透明背景上有纯色?

<!DOCTYPE html> <html lang="pl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="style.css"> </head> <body> <div id="bg"> <div id="topbar"></div> </div> </body> </html> body { background: url(bg.jpg); margin: 0; } #bg { background-color: black; margin: 0; padding: 0; height: 100vh; opacity: 0.7; } #topbar { background-color: gray; height: 80px; width: 100%; } Ive tried adding opacity: 1 to the topbar div and rgba with alpha: 1. The result: there是一个图像,其上有黑色背景,不透明度为 0.7,顶部栏的不透明度也为 0.7。 我的目标是实现较暗的图像作为背景和纯色顶栏 div #topbar位于#bg内部,因此调整#bg的不透明度也会影响#topbar。我要做的是省略不透明度并将背景颜色更改为透明黑色。 看起来像这样: body { background: url(bg.jpg); margin: 0; } #bg { background-color: rgba(0, 0, 0, 0.7); margin: 0; padding: 0; height: 100vh; } #topbar { background-color: gray; height: 80px; width: 100%; } 这样只有背景颜色是透明的,而不是整个元素。


Tiptap Lib。如何为 EditorContent 添加边框?

我很难编辑编辑器部分样式 我在 Recat 中使用 https://tiptap.dev/docs/editor/ Lib 现在我用这个渲染编辑器 我很难编辑编辑器部分样式 我正在使用 https://tiptap.dev/docs/editor/ Recat 中的 Lib 现在我用这个渲染编辑器 <EditorContent className='editor' editor={props.editor}/> 我的CSS .editor p{ margin: 1em 0; /* border: 1px solid #000; */ /* border-radius: 2px; */ } 未点击文本框时的结果 单击文本框时的结果 我想为此自定义 css 样式。有这方面的文档吗? Tiptap,Vue.js 的富文本编辑器框架。要向 EditorContent 组件添加边框,您可以使用 CSS 自定义样式。但是,请记住,Tiptap 不提供开箱即用的编辑器内容的直接样式,因此您必须将样式应用于 Tiptap 生成的 HTML 元素。🔥 以下是如何向 EditorContent 添加边框的示例: <template> <EditorContent :editor="editor" class="custom-editor-content" /> </template> <style scoped> /* Add your custom styles for the editor content */ .custom-editor-content { border: 1px solid #000; border-radius: 2px; padding: 10px; /* Optional: Add some padding for better aesthetics */ } /* Customize other elements as needed */ .custom-editor-content p { margin: 1em 0; } </style> 在此示例中,custom-editor-content 类应用于 EditorContent 组件,并且标记内的 CSS 规则的范围将仅影响该组件内的元素。🌟 🟢🟡🟣 您可以探索 Tiptap 文档: https://tiptap.dev/docs/editor/guide/styling


单击 p 标签旁边的按钮时获取 p 标签的内部文本(无 Jquery)

我有几个盒子,每个盒子都包含按钮和一个 元素,其内部文本是由 API 中的数据创建的。我在每个框上放置了一个 onclick(包裹 的 ) 我有几个盒子,每个盒子都包含按钮和一个 <p> 元素,其内部文本是由 API 中的数据创建的。我在每个框上放置了一个 onclick(包裹 <div> 元素和按钮的 <p>)。我希望每次单击该按钮时,位于该按钮旁边(位于同一 div 中)的 innerText 标签的 <p> 都会控制台日志。目前无法弄清楚,这就是我到目前为止所得到的: const containerShapes = document.getElementById("container-pock-shape") fetch("https://pokeapi.co/api/v2/pokemon-shape") .then(res => res.json()) .then(data => data.results.map(item => { return containerShapes.innerHTML += `<div class="shape-box" onclick="showName(event)"> <p>${item.name}</p> <button>Select</button> </div>` })) function showName(e) { console.log() } #container-pock-shape { display: flex; flex-wrap: wrap; } .shape-box { border: 2px solid red; display: flex; flex-direction: column; align-items: center; padding: 10px; width: 200px; } .shape-box p { background-color: grey; width: 100px; text-align: center; font-weight: 900; } <body> <div id="container-pock-shape"> </div> </body> 您可以使用最近的。当您需要 forEach 或正确使用地图时也不要使用地图 我还强烈建议授权(点击 div) const containerShapes = document.getElementById("container-pock-shape") fetch("https://pokeapi.co/api/v2/pokemon-shape") .then(res => res.json()) .then(data => containerShapes.innerHTML = data.results .map(({name}) => `<div class="shape-box"> <p>${name}</p> <button>Select</button> </div>`)); containerShapes.addEventListener("click", e => { const tgt = e.target.closest("button") if (tgt) console.log(tgt.closest("div.shape-box").querySelector("p").innerText) }) #container-pock-shape { display: flex; flex-wrap: wrap; } .shape-box { border: 2px solid red; display: flex; flex-direction: column; align-items: center; padding: 10px; width: 200px; } .shape-box p { background-color: grey; width: 100px; text-align: center; font-weight: 900; } <body> <div id="container-pock-shape"></div> </body> 要获取名称,由于事件位于整个 div 上,因此您需要使用 querySelector 并找到内部 <p> 元素并获取其文本。 const containerShapes = document.getElementById("container-pock-shape") fetch("https://pokeapi.co/api/v2/pokemon-shape") .then(res => res.json()) .then(data => data.results.map(item => containerShapes.innerHTML += `<div class="shape-box" onclick="showName(this)"> <p>${item.name}</p> <button>Select</button> </div>` )) function showName(box) { const name = box.querySelector('p').textContent; console.log(name); } #container-pock-shape { display: flex; flex-wrap: wrap; } .shape-box { border: 2px solid red; display: flex; flex-direction: column; align-items: center; padding: 10px; width: 200px; } .shape-box p { background-color: grey; width: 100px; text-align: center; font-weight: 900; } <body> <div id="container-pock-shape"></div> </body> 执行此操作的另一种方法是将单击事件仅添加到按钮,然后查找 closest 形状框,然后找到 <p>。 const containerShapes = document.getElementById("container-pock-shape") fetch("https://pokeapi.co/api/v2/pokemon-shape") .then(res => res.json()) .then(data => data.results.map(item => containerShapes.innerHTML += `<div class="shape-box"> <p>${item.name}</p> <button onclick="showName(this)">Select</button> </div>` )) function showName(button) { const name = button.closest('.shape-box').querySelector('p').textContent; console.log(name); } #container-pock-shape { display: flex; flex-wrap: wrap; } .shape-box { border: 2px solid red; display: flex; flex-direction: column; align-items: center; padding: 10px; width: 200px; } .shape-box p { background-color: grey; width: 100px; text-align: center; font-weight: 900; } <body> <div id="container-pock-shape"></div> </body> 嘿,我最近找到了解决此问题的简单方法(当然,如果您的文本不像按钮文本那样太长):您可以将内部文本作为元素的 id 提供。并且在事件处理程序中,您可以通过以下方式访问内部文本:这样:e.target.id希望这个解决方案可以帮助你:)


ASP.NET MVC 项目模板在移动设备上无法调整为 100%

我不明白为什么 Web .Net MVC 项目上的默认模板没有在移动设备中调整为 100% 宽度。 我在视图上使用数据表: @模型IEnumerable 我不明白为什么 Web .Net MVC 项目上的默认模板没有在移动设备中调整为 100% 宽度。 我在视图上使用数据表: @model IEnumerable<iziConference.Models.EventAttendee> <h2>Participantes.</h2> <br /> <button><a style="text-decoration: none" href='@Url.Action("Create", new { eventId = ViewBag.EventId })'>Criar Participante</a></button> <button id="at-btn-refresh"> Actualizar</button> <input id="eventId" type="hidden" value="@ViewBag.EventId"> <table id="at-attendees-list" cellpadding="10" border="1" class="row-border stripe"> <thead> <tr> <th>ID</th> <th>Tipo</th> <th>Nome</th> <th>Email</th> <th>Estado </th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr id="[email protected]_Id"> <td style="padding: 5px"> @Html.DisplayFor(modelItem => item.Attendee.Id) </td> <td> @Html.DisplayFor(modelItem => item.AttendeeType) </td> <td> @Html.DisplayFor(modelItem => item.Attendee.Name) </td> <td> @Html.DisplayFor(modelItem => item.Attendee.Email) </td> <td> @if (item.IsActive) { <button id="[email protected]_Id" class="at-btn-active-state active" data-attendee-id="@item.Attendee_Id" data-attendee-name="@item.Attendee.Name" data-active-new-state="false" data-show-confirmation-alert="true">Desactivar</button> } else { <button id="[email protected]_Id" class="at-btn-active-state inactive" data-attendee-id="@item.Attendee_Id" data-attendee-name="@item.Attendee.Name" data-active-new-state="true" data-show-confirmation-alert="true">Activar</button> } </td> </tr> } </tbody> </table> 由脚本加载: var _atteendeesList = "at-attendees-list"; $("#" + _atteendeesList).DataTable({ "paging": false, "info": false, "language": { "search": "Pesquisar:", "info": "Participantes inscritos: _PAGES_" } }); 使用默认的_Layout.cshtml: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>izigo Conference - Gestor de Conteúdos</title> <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> <meta name="viewport" content="width=device-width" /> @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") </head> <body> <header> <div class="content-wrapper"> <section id="login"> @Html.Partial(MVC.Account.Views._LoginPartial) </section> <div style="padding: 10px;"> @if (Request.IsAuthenticated) { <nav> <ul id="menu"> <li>@Html.ActionLink("Home", MVC.Home.Index())</li> <li>@Html.ActionLink("Participantes", MVC.Attendee.Index())</li> <li>@Html.ActionLink("Check-in", MVC.Checkin.Index())</li> </ul> </nav> } </div> </div> </header> <div id="body"> @RenderSection("featured", required: false) <section class="content-wrapper main-content clear-fix"> @RenderBody() </section> </div> <footer style="padding-left: 25px;"> <div class="content-wrapper"> <div class="float-left"> <p>&copy; @DateTime.Now.Year - <a href="https://www.izigo.pt/conference" target="_blank">izigo Conference</a> - <i>Powered by</i><a href="https://www.izigo.pt" target="_blank">izigo.pt</a></p> </div> </div> </footer> @Scripts.Render("~/bundles/jquery", "~/bundles/iziconference") @RenderSection("scripts", required: false) </body> </html> 研究了 dataTables 库的选项后,我找到了一个创建响应式解决方案的选项: 我已经包含了响应表结构和columnDefs的选项,以选择哪些选项在移动设备中保持可见: $("#" + _atteendeesList).DataTable({ "responsive": true, "columnDefs": [ { responsivePriority: 1, targets: 0 }, { responsivePriority: 2, targets: -1 } ], "paging": false, "info": false, "language": { "search": "Pesquisar:", "info": "Participantes inscritos: _PAGES_" } }); 我还必须在捆绑包中包含数据表扩展的 js 和 css 响应式库(可在此处下载:https://datatables.net/download/): bundles.Add(new ScriptBundle("~/bundles/iziconference").Include( "~/Content/Scripts/datatables.min.js", "~/Content/Scripts/dataTables.responsive.min.js")); // add-on bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/Styles/datatables.min.css", "~/Content/Styles/responsive.dataTables.min.css"));


从右到左打印表格单元格

我制作了一个表格,并希望第一个单元格从右侧开始,而不是默认从左侧开始。 我尝试更改 CSS 中的 float 属性,但似乎没有帮助。 这是代码: 我制作了一个表格,并希望第一个单元格从右侧开始,而不是默认从左侧开始。 我尝试更改 CSS 中的 float 属性,但似乎没有帮助。 这是代码: <table border="0" width="100%" cellspacing="0" align="center" class="result_table"> <tr align="right"> <th bgcolor="#cccccc" align="right">1</th> <th bgcolor="#cccccc" size="17">2</th> <th bgcolor="#cccccc">3</th> <th bgcolor="#cccccc">4</th> </tr> </table> <style> table.result_table { float:right; } </style> 任何人都可以建议一种方法来改变这张桌子的浮动吗? 正如评论中所建议的,您可以将方向性设置为从右到左(RTL)。但是,除非您的表格内容采用从右到左的语言,否则您还应该将表格内容元素中的方向性设置为从左到右。否则,它们继承 RTL 方向性,这在许多情况下会引起意外,因为方向性还设置整体文本方向性。这不会影响西方语言的正常文本,但会影响例如像“4 (5)”这样的内容,在 RTL 方向性下会显示为“(5) 4”。 因此,您应该设置 table.result_table { direction: rtl; } table.result_table caption, table.result_table th, table.result_table td { direction: ltr; } 有一种更简单的方法。您可以将 dir="rtl" 添加到表格中。 <table dir="rtl"> ... </table> 或者您可以使用 CSS 而不是使用 HTML 属性: <table style="direction:rtl"> ... </table> 我不确定这是否可以仅使用 CSS 来实现。如果使用 jQuery 适合您,这里有一个起始想法,可能会让您获得所需的结果: CSS: .result_table{float:left; width:100%; border-collapse:collapse; padding:0;} .result_table th{float:right; padding:0;} JS: var cols = $('.result_table th').length; var colWidth = 100 / cols; $('.result_table th').css({width:colWidth+'%'}) 示例 - jsFiddle


如何以 Svelte 方式设置导出和开槽零件的样式?

Svelte slot 的功能是否像 vanilla-js/dom 一样(我似乎无法让它工作)。 在 html/js 中我可以这样做: 身体{颜色:红色;} /* 从外部设置暴露部分的样式 */ ...</desc> <question vote="0"> <p>Svelte <pre><code>slot</code></pre>的功能是否像 vanilla-js/dom 一样(我似乎无法让它工作)。</p> <p>在 html/js 中我可以做:</p> <p></p><div data-babel="false" data-lang="js" data-hide="false" data-console="true"> <div> <pre><code>&lt;style&gt; body {color: red;} /* style exposed part from outside */ my-element::part(header) {color: green;} &lt;/style&gt; &lt;h1&gt;Hello World&lt;/h1&gt; &lt;my-element&gt; &lt;div slot=&#34;header&#34;&gt;&lt;strong&gt;Header&lt;/strong&gt;&lt;/div&gt; &lt;div slot=&#34;body&#34;&gt;Body&lt;/div&gt; &lt;/my-element&gt; &lt;script&gt; customElements.define(&#39;my-element&#39;, class extends HTMLElement { constructor() { super(); const shadowRoot = this.attachShadow({mode: &#39;open&#39;}); shadowRoot.innerHTML = ` &lt;style&gt; .container { border: solid 1px blue; padding: 5px; position: relative; &amp;:after { content: &#34;my-element&#34;; display: block; position: absolute; bottom: -.5em; right: 5px; border: inherit; background-color: white; padding: inherit; } } /* style inserted/slotted part from inside */ [part=&#34;body&#34;] ::slotted(div) { background-color: lightyellow; } &lt;/style&gt; &lt;div class=&#34;container&#34;&gt; &lt;header part=&#34;header&#34;&gt;&lt;slot name=&#34;header&#34;&gt;&lt;/slot&gt;&lt;/header&gt; &lt;hr&gt; &lt;div part=&#34;body&#34;&gt;&lt;slot name=&#34;body&#34;&gt;&lt;/slot&gt;&lt;/div&gt; &lt;/div&gt; `; } }); &lt;/script&gt;</code></pre> </div> </div> <p></p> <p>其中 <pre><code>h1</code></pre> 的全局样式为红色,标有 <pre><code>part=&#34;header&#34;</code></pre> 的元素从外部设置为绿色,插入 <pre><code>slot=&#34;body&#34;</code></pre> 的内容从内部(shadow dom)设置为绿色有浅黄色背景。</p> <p>我不知道如何在 svelte 中执行任何这种(受控)跨界样式? (例如,当使用 <pre><code>AppShell::part(content)</code></pre> 时,我收到错误:</p> <pre><code>[plugin:vite-plugin-svelte] C:/srv/svelte/yoda5/src/routes/+layout.svelte:23:18 Expected a valid CSS identifier C:/srv/svelte/yoda5/src/routes/+layout.svelte:23:18 21 | 22 | &lt;style&gt; 23 | AppShell::part(content) { | ^ </code></pre> </question> <answer tick="false" vote="0"> <p>这里有关于<a href="https://learn.svelte.dev/tutorial/slots" rel="nofollow noreferrer">老虎机的课程</a>。最好参考该工具的文档。 Svelte 的学习网站非常棒。</p> <pre><code>// Slotted component, say Test.svelte. &lt;div class=&#34;private-parent&#34;&gt; &lt;slot /&gt; &lt;/div&gt; &lt;style&gt; div.private-parent { color: blue; } &lt;/style&gt; </code></pre> <p>然后,您使用该组件:</p> <pre><code>&lt;script&gt; import Test from &#39;./Test.svelte&#39;; &lt;/script&gt; &lt;Test&gt; &lt;!-- This is the slot&#39;s content --&gt; &lt;p class=&#34;outside-style&#34;&gt;Hello!&lt;/p&gt; &lt;/Test&gt; &lt;style&gt; p.outside-style { color: darkred; } &lt;/style&gt; </code></pre> </answer> </body></html>


.NET MAUI、ios UseSafeArea 不工作 StackLayout、VerticalStackLayout 和 Grid

<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Test.Views.Activities.ActivityMapList" xmlns:maps="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps" xmlns:sensors="clr-namespace:Microsoft.Maui.Devices.Sensors;assembly=Microsoft.Maui.Essentials" xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls" ios:Page.UseSafeArea="False" Shell.NavBarIsVisible="False" Style="{StaticResource Key=DefaultPage}"> <ContentPage.Content> <StackLayout> <maps:Map VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> <x:Arguments> <MapSpan> <x:Arguments> <sensors:Location> <x:Arguments> <x:Double>36.9628066</x:Double> <x:Double>-122.0194722</x:Double> </x:Arguments> </sensors:Location> <x:Double>0.01</x:Double> <x:Double>0.01</x:Double> </x:Arguments> </MapSpan> </x:Arguments> </maps:Map> </StackLayout> </ContentPage.Content> </ContentPage> StackLayout 或 Grid 内的地图控件,iOS 的 SafeArea 为 false,如图所示。 你有什么解决办法吗? 我需要在地图上使用网格或堆栈布局 默认情况下.NET MAUI 将考虑安全区域。所以使用特定于平台的UseSafeArea就是禁用安全区域。目前,将 UseSafeArea 设置为 false 不会改变行为(尽管应该如此),这是一个错误。另请参阅 MAUI github 上的问题:https://github.com/dotnet/maui/issues/5856 您还可以设置 IgnoreSafeArea 属性来实现相同的目的。但是,它不再在 .NET 7 中工作,请参阅以下问题:https://github.com/dotnet/maui/issues/12823 要解决您的问题,您需要将 IgnoreSafeArea="True" 添加到您的 Grid 或 StackLayout 并将 ios:Page.UseSafeArea="False" 添加到您的页面。这应该不是必需的,但这是对我有用的解决方法。 有关在 iOS 上禁用安全区域的文档可以在此处找到:https://learn.microsoft.com/en-us/dotnet/maui/ios/platform-specifics/page-safe-area-layout?view=net-毛伊岛-7.0 您可以设置 Page Padding 值来实现。在OnAppearing方法中,设置页面的safeInsets,如下代码: protected override void OnAppearing() { base.OnAppearing(); DeviceSafeInsetsService d = new DeviceSafeInsetsService(); double topArea = d.GetSafeAreaTop(); double bottomArea = d.GetSafeAreaBottom(); var safeInsets = On<iOS>().SafeAreaInsets(); safeInsets.Top = -topArea; safeInsets.Bottom = -bottomArea; Padding = safeInsets; } 要获取 topArea 和 bottomArea 值,您应该编写平台代码。答案末尾附有有关此内容的更详细教程。 首先你可以在Project文件夹中生成一个新的类文件并将其更改为部分类。生成两个部分方法。 public partial class DeviceSafeInsetsService { public partial double GetSafeAreaTop(); public partial double GetSafeAreaBottom(); } 然后在iOS平台生成部分文件并实现。该文件位于 Project/Platform/iOS 文件夹中,我想提一下的是,该文件是一个部分文件,因此命名空间应与上面的文件相同。生成此文件时,请删除命名空间中的 .Platforms.iOS 后缀。 public partial class DeviceSafeInsetsService { public partial double GetSafeAreaBottom() { if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow(); var bottomPadding = window.SafeAreaInsets.Bottom; return bottomPadding; } return 0; } public partial double GetSafeAreaTop() { if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow(); var TopPadding = window.SafeAreaInsets.Top; return TopPadding; } return 0; } } 更多信息,您可以参考如何在.NET MAUI中编写特定于平台的代码和MauiPlatformCode示例代码 希望它对你有用。


React CSS 导入

在我的 Home.js 中我有以下代码 从“反应”导入反应; 导入'./Home.css'; 常量文本变体 = {...} 常量主页 = () => { 返回 ( ... 在我的 Home.js 中,我有以下代码 import React from 'react'; import './Home.css'; const textVariants = {...} const Home = () => { return ( <div id='home' className='page'> <motion.div className='text-wrapper' variants={textVariants} initial='initial' animate='animate'> <motion.div className='text-container' variants={textVariants}> <motion.h1 variants={textVariants}>NAME</motion.h1> <motion.h2 variants={textVariants}>An enthusiatic university student</motion.h2> </motion.div> </div> ); }; export default Home; 在 Home.css 中, .text-wrapper { max-width: 1366px; height: 100%; } .text-container { height: 100%; width: 50%; padding-left: 10%; h1 { letter-spacing: 10px; font-size: 50px; margin-bottom: -5%; } h2 { font-size: 80px; } } 我有 About.js 和 About.css 以及以下内容, import './About.css'; const About = () => { return ( <div id='about' className='page'> <div className='text-container'> <h1>About Me</h1> </div> </div> ); }; 但是 About.js 应用了 Home.css 中的内容,即 .text-container。我该如何避免这种情况?我不知道为什么 Home.css 被应用到 About.js 即使我没有导入它。 在React js中,任何根组件中导入的css文件适用于整个项目。 css 类可以在项目层次结构中的任何位置访问。 我们无法避免这种情况,因为文件被应用于根目录。您必须为不同的组件使用特定的类名称。 专业提示:创建可重用的组件,以便您可以将相同的类应用于每个相同的组件..


QWebEngineView:html 文件中的 href 不起作用

我有一个 test.html 文件,例如: 我有一个 test.html 文件,例如: <!DOCTYPE html> <html> <head> </head> <body> <a style="padding-right:5px" target="_blank" href="data/">Datadir</a> </body> </html> 包含 test.html 的目录如下: test.html data\ a.txt b.txt 我使用“file:///remote/us01home19/ktc/public_html/testLocalHref/test.html”并在firefox和chrome中单击Datadir,结果如下: 和: 我写了一个pyside2代码来做同样的事情,代码如下: from PySide2 import QtCore, QtWidgets, QtWebEngineWidgets import os import sys class CustomWebEnginePage(QtWebEngineWidgets.QWebEnginePage): # Store second window. external_window = None def acceptNavigationRequest(self, url, _type, isMainFrame): print(url, _type, isMainFrame) if _type == QtWebEngineWidgets.QWebEnginePage.NavigationTypeLinkClicked: if not self.external_window: self.external_window = QtWebEngineWidgets.QWebEngineView() self.external_window.setUrl(url) self.external_window.show() return False return super().acceptNavigationRequest(url, _type, isMainFrame) class MainWindow(QtWidgets.QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.browser = QtWebEngineWidgets.QWebEngineView() self.browser.setPage(CustomWebEnginePage(self)) # self.browser.setUrl(QtCore.QUrl("https://code.visualstudio.com")) self.browser.setUrl(QtCore.QUrl("file:///remote/us01home19/ktc/public_html/testLocalHref/test.html")) # self.browser.setUrl(QtCore.QUrl("file:///remote/tw_rnd1/ktc/prog/python/pyside2/WebEngine/data/aaa.ava.summary.html")) #self.browser.setUrl(QtCore.QUrl("file:///remote/tw_rnd1/ktc/prog/python/pyside2/WebEngine/data/aaa_ava_corners/C_1")) self.setCentralWidget(self.browser) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_()) 但是执行代码,我得到的结果如下: 但是点击Datadir,没有任何反应,甚至QWebEnginePage.acceptNavigationRequest也没有触发。有没有办法让 QWebEngine 的行为像 Firefox 和 Chrome 一样? 我尝试在 QWebEnginePage.acceptNavigationRequest 函数中添加打印消息来捕获点击 dataDir 信息,但似乎没有任何响应。 python版本:python-3.9.0, 操作系统版本:“CentOS Linux 7”, Qt 版本:“Qt_5.15” python 和 Qt 是自定义构建 我发现问题来自htmltarget =“_blank”在QWebEnginePage中不起作用,它可以通过在QtWebEngineWidgets中实现类函数createWindow来避免,例如: class CustomWebEnginePage(QtWebEngineWidgets.QWebEnginePage): # Store second window. external_window = None def acceptNavigationRequest(self, url, _type, isMainFrame): print(url, _type, isMainFrame) if _type == QtWebEngineWidgets.QWebEnginePage.NavigationTypeLinkClicked: if not self.external_window: self.external_window = QtWebEngineWidgets.QWebEngineView() self.external_window.setUrl(url) self.external_window.show() return False return super().acceptNavigationRequest(url, _type, isMainFrame) def createWindow(self, t): return self;enter code here


何时切换搜索栏和徽标下降?

.navbar { 背景颜色:#F91F46; } .src-bar { 边框:0; 边框半径:5px; 概要:无; 左内边距:15px; 宽度:30vw; } .navbar { background-color: #F91F46; } .src-bar { border: 0; border-radius: 5px; outline: none; padding-left: 15px; width: 30vw; } <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" integrity="sha512-b2QcS5SsA8tZodcDtGRELiGv5SaKSk1vDHDaQRda0htPYWZ6046lr3kJ5bAAQdpV2mmA/4v0wQF9MyU6/pDIAg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/js/bootstrap.min.js" integrity="sha512-WW8/jxkELe2CAiE4LvQfwm1rajOS8PHasCCx+knHG0gBHt8EXxS6T6tJRTGuDQVnluuAvMxWF4j8SNFDKceLFg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <nav class="navbar navbar-expand-md fixed-top"> <div class="container-fluid"> <a class="navbar-brand ms-3" href="#"> <img src="img/Logo.avif" width="40px" class="d-inline-block" /> </a> <form role="search" class="search-bar"> <div class="input-group"> <input class="src-bar" type="search" placeholder="Search For Products" /> <button class="btn bg-white" type="submit"> <i class="fa fa-search"></i> </button> </div> </form> <div class="justify-content-end"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav-colps" aria-controls="nav-colps" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="nav-colps"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </a> <ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li> <hr class="dropdown-divider" /> </li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </li> <li class="nav-item"> <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> </li> </ul> </div> </div> </div> </nav> 切换时,我希望折叠 div 居中。我知道原因 - 我将折叠和切换 btn 放在 justify-end div 内,因为我需要切换 btn 位置位于右侧。现在,当切换时,我的折叠位于右侧,但我希望在切换时,折叠div到中心。 当我删除 justify-end div 时,它位于左侧,但如果删除它,每个导航元素都会移动到 nav 和 md 视图中 lg 的左侧。 看起来像这样或中心 我们确实需要将 .nav-collapse 移到 justify-end 元素之外,才能在较窄的视口上获得所需的布局。 要将菜单显示在右侧,请通过 flex-grow: 1 类将 .nav-collapse 应用于 flex-grow: 0 元素,覆盖 flex-grow-0 上的默认 .nav-collapse。 为了使窄视口的链接元素居中,.navbar-nav中的元素采用垂直柔性布局,因此我们可以通过align-items: center类应用align-items-center: .navbar { background-color: #F91F46; } .src-bar { border: 0; border-radius: 5px; outline: none; padding-left: 15px; width: 30vw; } <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" integrity="sha512-b2QcS5SsA8tZodcDtGRELiGv5SaKSk1vDHDaQRda0htPYWZ6046lr3kJ5bAAQdpV2mmA/4v0wQF9MyU6/pDIAg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/js/bootstrap.min.js" integrity="sha512-WW8/jxkELe2CAiE4LvQfwm1rajOS8PHasCCx+knHG0gBHt8EXxS6T6tJRTGuDQVnluuAvMxWF4j8SNFDKceLFg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <nav class="navbar navbar-expand-md fixed-top"> <div class="container-fluid"> <a class="navbar-brand ms-3" href="#"> <img src="https://picsum.photos/40/40" width="40px" class="d-inline-block" /> </a> <form role="search" class="search-bar"> <div class="input-group"> <input class="src-bar" type="search" placeholder="Search For Products" /> <button class="btn bg-white" type="submit"> <i class="fa fa-search"></i> </button> </div> </form> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav-colps" aria-controls="nav-colps" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse flex-grow-0" id="nav-colps"> <ul class="navbar-nav me-auto mb-2 mb-lg-0 align-items-center"> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </a> <ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li> <hr class="dropdown-divider" /> </li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </li> <li class="nav-item"> <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> </li> </ul> </div> </div> </nav> 您还可以考虑通过 text-align: center 类应用 text-center,将链接元素 text 居中: .navbar { background-color: #F91F46; } .src-bar { border: 0; border-radius: 5px; outline: none; padding-left: 15px; width: 30vw; } <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" integrity="sha512-b2QcS5SsA8tZodcDtGRELiGv5SaKSk1vDHDaQRda0htPYWZ6046lr3kJ5bAAQdpV2mmA/4v0wQF9MyU6/pDIAg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/js/bootstrap.min.js" integrity="sha512-WW8/jxkELe2CAiE4LvQfwm1rajOS8PHasCCx+knHG0gBHt8EXxS6T6tJRTGuDQVnluuAvMxWF4j8SNFDKceLFg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <nav class="navbar navbar-expand-md fixed-top"> <div class="container-fluid"> <a class="navbar-brand ms-3" href="#"> <img src="https://picsum.photos/40/40" width="40px" class="d-inline-block" /> </a> <form role="search" class="search-bar"> <div class="input-group"> <input class="src-bar" type="search" placeholder="Search For Products" /> <button class="btn bg-white" type="submit"> <i class="fa fa-search"></i> </button> </div> </form> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav-colps" aria-controls="nav-colps" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse flex-grow-0" id="nav-colps"> <ul class="navbar-nav me-auto mb-2 mb-lg-0 text-center"> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </a> <ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li> <hr class="dropdown-divider" /> </li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </li> <li class="nav-item"> <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> </li> </ul> </div> </div> </nav>


带有边框半径和粘性标题的 HTML 表格

我有一个 HTML ,带有边框半径和使用位置的粘性标题:sticky,如下所示: https://codepen.io/muhammadrehansaeed/pen/OJpeeKP 但是,当使用 滚动时 我有一个带有 <table> 的 HTML border-radius 和使用 position: sticky 的粘性标题,如下所示: https://codepen.io/muhammadrehansaeed/pen/OJpeeKP 但是,当使用粘性标题滚动时,表格行会伸出粘性标题的圆角所在的位置。请参阅此图片的左上角: 有没有办法可以在使用粘性标题向下滚动时保持圆角,或者在标题变得粘性并从原始位置向下移动时删除粘性标题?理想情况下,我想要一个CSS解决方案。 您可以使用伪元素隐藏边框的某些部分: table thead th:first-child::before, table thead th:last-child::after { width: 1px; height: 5px; background: white; content: ""; display: block; position: absolute; top: 0px; } table thead th:first-child::before { left: -1px; } table thead th:last-child::after { right: -1px; } 正如Ivan建议的那样,似乎使用伪元素来覆盖标题下方不需要的边框是(令人惊讶的)唯一可行的选择。我建议使用伪不仅用于覆盖“外部”区域,而且还用于绘制弧线和填充“内部”区域。可以使用堆叠背景来做到这一点。应用于原始代码: /* § Additions / Changes */ table thead th { position: relative; } /* Pseudos exceeding header boundary by border width; with rectangle covering half circle and rest of height */ table thead th:last-child::after, table thead th:first-child::before { content: ""; position: absolute; top: 0; bottom: 0; left: calc(-1 * var(--global-border-width-1)); width: var(--global-border-radius); background-image: linear-gradient(to bottom, transparent var(--global-border-radius), var(--global-title-color) 0), radial-gradient(circle at var(--global-border-radius) var(--global-border-radius), var(--global-title-color) var(--global-border-radius), var(--global-content-background-color) 0); background-position: top left; background-size: var(--global-border-diameter) 100%, var(--global-border-diameter) var(--global-border-diameter); background-repeat: no-repeat; } table thead th:last-child::after { left: auto; right: calc(-1 * var(--global-border-width-1)); background-position: top right; } /* § Declarations and original style */ html { --global-content-background-color: white; --global-title-color: black; --global-background-color: lightblue; --global-border-color: black; --global-border-radius: 20px; --global-border-width-1: 10px; --global-space-fixed-2: 10px; --global-space-fixed-3: 15px; --global-border-diameter: calc(2 * var(--global-border-radius)); background-color: var(--global-content-background-color); } table { color: var(--global-title-color); background-color: var(--global-content-background-color); border-collapse: separate; border-color: var(--global-title-color); border-style: solid; border-radius: var(--global-border-radius); border-width: 0 var(--global-border-width-1) var(--global-border-width-1) var(--global-border-width-1); border-spacing: 0; width: 100%; } table thead { position: sticky; top: 0; z-index: 10; } table thead th { color: var(--global-background-color); background-color: var(--global-title-color); padding: var(--global-space-fixed-2) var(--global-space-fixed-3); vertical-align: bottom; } table tbody td { border-top: var(--global-border-width-1) solid var(--global-border-color); padding: var(--global-space-fixed-2) var(--global-space-fixed-3); vertical-align: top; } table tbody tr:last-child td:first-child { border-bottom-left-radius: var(--global-border-radius); } table tbody tr:last-child td:last-child { border-bottom-right-radius: var(--global-border-radius); } /* § Unrelated / demo */ * { scroll-margin-top: calc(var(--global-space-fixed-2) * 4 + 1rem); /* = height of sticky thead + top padding of cell, provided text in thead does not wrap */ scroll-margin-bottom: 1em; } td { height: 60vh; } td a { float: right } tr:last-child td { vertical-align: bottom; } a[name]:empty::before { content: attr(name); } th:not(#\0):hover::before { background-image: linear-gradient(to bottom, transparent var(--global-border-radius), #0F08 0), radial-gradient(circle at center, #00F8 var(--global-border-radius), #F2F4 0); background-position: top left; background-size: var(--global-border-diameter) 100%, var(--global-border-diameter) var(--global-border-diameter); } <table> <thead> <tr> <th>Fake non-transparent "border-radius"</th> </tr> </thead> <tbody> <tr> <td> <a href="#⬆️" name="⬇️"></a> For fixed header</td> </tr> <tr> <td> <a href="#⬇️" name="⬆️"></a> Using CSS stacked background images in pseudo elements</td> </tr> </tbody> </table> 只需从表格中删除边框,并为表格主体中的第一个和最后一个表格单元格添加左右边框: tbody td:first-child { border-left: 1px solid black; } tbody td:last-child { border-right: 1px solid black; } tbody tr:last-child td{ border-bottom: 1px solid black; } tbody tr:last-child td:first-child { border-bottom-left-radius: 2px; } tbody tr:last-child td:last-child { border-bottom-right-radius: 2px; } 当然是使用适当的缩进、嵌套和变量! 使用许多伪选择器看起来样式相当丑陋,但似乎可以解决您的问题。 有一个更紧凑的解决方案。只需将具有背景颜色的框阴影添加到第一个 < th > 和最后一个 < th > 即可隐藏元素。 在此示例中,在右侧,您可以看到表格行由于边框半径而可见。在左边,我应用了盒子阴影。 盒子阴影:0 -2.1rem 0 .6rem #E5E7EB; 在这里,它是灰色的,以便您可以看到它的工作原理,但您只需使用与背景相同的颜色即可使其完全不可见。 这是最终结果以及我正在使用的代码: th:第一个孩子 { 边界半径:0.75rem 0 0 0; 左边框:.1rem 实心 $color-gray-200; 框阴影:0 -2.1rem 0 .6rem $color-gray-200; } th:最后一个孩子{ 边界半径:0 0.75rem 0 0; 右边框:.1rem 实心 $color-gray-200; 盒子阴影:1rem -2.1rem 0 .6rem $颜色白色; } 可能需要调整框阴影以隐藏基于所选边框半径的行。 不确定你是否熟悉jquery,如果熟悉的话你可以在滚动内容时动态更改 border-top-left-radius: 等于粘性标题的半径,但这对于新手来说有点棘手jquery/JS。 其次,您可以将粘性标题封闭到父级(例如class="parent")),并将父级背景设置为白色,没有边框。并保持粘性标题的边框半径不变。因此,当您滚动内容时将位于该父级下方(例如 class="parent")。为了确保父级出现在该行上方,您可以给出 z-index: 10


如何防止我的CSS规则被reactjs/jsx中的规范化CSS覆盖?

我有一个非常简单的反应组件 类 UpgradeContainer 扩展组件 { 使成为() { 返回 ( 我有一个非常简单的反应组件 class UpgradeContainer extends Component { render() { return ( <div className={styles.msg}> <div className={styles['msg-container']}> <h3 className={`${styles.title} highlight-color`}> Big Header </h3> <div className={`${styles.description} alternate-color`}> Small text <br /> Some more small text </div> </div> </div> ); } 这是相关的css .title { font-size: 40px; line-height: 50px; color: white; } .description { text-align: center; font-size: 16px; padding: 20px 0 10px; color: white; } 这是上面组件的 DOM 输出 此处以文本形式转载: <div class="mRMOZryRtlFUx_NHlt1WD" data-reactid=".0.1.0.0.0.1"> <h3 class="_2s6iXRZlq-nQwIsDADWnwU highlight-color" data-reactid=".0.1.0.0.0.1.0"> Big Header</h3> <div class="_1pFak-xR0a8YH6UtvoeloF alternate-color" data-reactid=".0.1.0.0.0.1.1"> <span data-reactid=".0.1.0.0.0.1.1.0">Small text</span> <br data-reactid=".0.1.0.0.0.1.1.1"> <span data-reactid=".0.1.0.0.0.1.1.2">Some more small text</span></div></div> 如你所见,reactjs 添加了几个 <span/> 来包裹小文本 我希望标题文本 (Big Header) 比描述文本(small text 和 some more small text)大得多。 输出看起来像这样: 这是因为reactjs出于某种原因添加了一个span来包裹文本small text和some more small text(data-reactid“.0.1.0.0.0.1.1.0”和“.0.1.0.0.0.1.1.2”分别) 当我检查样式时,我发现这些 span 元素的样式被以下 css 规则覆盖 我真的很困惑,因为这些规则不是我自己定义的。 所以我点击 <style>...</style>,它会将我带到 我想知道如何有效地覆盖这些CSS规则? 我想要的最终结果是: 如果您使用“Normalize.css”! 此问题的解决方案是将主 css 文件“style.css”保留在底部。至少低于normalize.css。 如果您使用 Bootstrap, 直接来自 Bootstrap 官方网站,“为了改进跨浏览器渲染,我们使用 Normalize.css,这是 Nicolas Gallagher 和 Jonathan Neal 的一个项目。” 这个问题的解决方案是将主 css 文件“style.css”保留在底部。至少低于 bootstrap.css。 我遇到了与您类似的问题,我的解决方案是在 app.tsx 文件顶部导入 Bootstrap 样式。这样做的原因是它可以防止 Bootstrap CSS 被应用程序中的其他样式覆盖,它对我有用


如何在本机反应中强制 TextInput 增长而 multiline={false} ?

<TextInput ref={inputRef} value={text} style={styles.textInput} returnKeyType="next" placeholder={"placeholder"} scrollEnabled={false} blurOnSubmit={false} onFocus={onFocusInput} textAlignVertical="center" onContentSizeChange={onChangeContentSizeChange} onChangeText={onInputChangeValue} onBlur={onInputBlur} onKeyPress={onInputKeyPress} onSubmitEditing={() => NextScript(id)} multiline={false} numberOfLines={5} /> 逻辑是我想要 onSubmitEditing 带我到下一个 TextInput 字段,并且我需要文本来包装输入的多个文本。如果我启用 multiline,一旦按下回车键,它会在进入下一个输入之前进入下一行,这就是我试图避免的。 是否可以用onSubmitEditing完全取代回车键?每当我按下回车键时,它都会尝试在移动到下一个TextInput之前输入换行符,因此它会创建一个糟糕的用户界面,其中文本在重新定位然后进入下一行之前会稍微向上移动。 如果我将 blurOnSubmit 设置为 true,它会停止,但键盘会在提交时关闭。 如果我将 multiline 设置为 false,它会停止但不会换行。 我创建了一个示例,onKeyPress将允许您在按下回车键时聚焦下一个文本字段。 import { Text, SafeAreaView, StyleSheet, TextInput } from 'react-native'; export default function App() { return ( <SafeAreaView style={styles.container}> <TextInput multiline={true} placeholder={'PLACEHOLDER'} onKeyPress={(e) => { if (e.nativeEvent.key == 'Enter') { console.log('ENTER'); //focusNextTextField(); } }} style={{ borderColor: '#000000', borderWidth: 1 }} /> </SafeAreaView> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignContent: 'center', padding: 8, }, }); 我也面临同样的问题。后来我找到了解决办法。 自定义文本输入处理:您需要一个自定义逻辑来处理文本输入及其在按“Enter”键时的行为。您将以编程方式控制文本换行和导航到下一个输入字段,而不是依赖多行的默认行为。 用 onSubmitEditing 替换 Enter 键:要覆盖“Enter”键的默认行为,您可以使用 onKeyPress 事件。检测何时按下“Enter”键并以编程方式触发 onSubmitEditing 函数。 维护文本换行:由于 multiline={false} 禁用自动文本换行,因此您需要实现一种方法来根据输入的内容大小或字符数手动处理文本换行。 以下是如何实现这一点的概念示例: import React, { useState, useRef } from 'react'; import { TextInput, StyleSheet } from 'react-native'; const CustomTextInput = () => { const [text, setText] = useState(''); const nextInputRef = useRef(null); const onInputKeyPress = (e) => { if (e.nativeEvent.key === 'Enter') { // Replace the Enter key functionality // Call the function you would have in onSubmitEditing handleEnterKeyPress(); } }; const handleEnterKeyPress = () => { // Logic to navigate to next TextInput // Focus the next input field if (nextInputRef.current) { nextInputRef.current.focus(); } // Additional logic if needed to handle text wrapping }; return ( <TextInput value={text} style={styles.textInput} onChangeText={setText} onKeyPress={onInputKeyPress} blurOnSubmit={false} // prevent keyboard from closing // other props /> ); }; const styles = StyleSheet.create({ textInput: { // styling for your text input }, }); export default CustomTextInput;


如何在webview中加载html字符串?

我有一个包含以下内容的html字符串: 我有一个包含以下内容的html字符串: <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="spanish press" content="spain, spanish newspaper, news,economy,politics,sports"> <title></title> </head> <body id="body"> <!-- The following code will render a clickable image ad in the page --> <script src="http://www.myscript.com/a"></script> </body> </html> 我需要将该网站显示到 Android 中的网络视图中。 我尝试过这一切: webView.loadDataWithBaseURL(null, txt, "text/html", "UTF-8", null); webView.loadDataWithBaseURL("x-data://base", txt, "text/html", "UTF-8", null); webView.loadDataWithBaseURL("notreal/", txt, "text/htm", "utf-8",null); 我还尝试删除 DOCTYPE 标签: txt=txt.replace("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">", ""); 这些人都没有工作。我刚刚实现了将字符串显示到 webview(html 代码)中,但不是必须使用该 html 代码创建的网站。 出了什么问题? 在 WebView 中加载数据。调用WebView的loadData()方法 wv.loadData(yourData, "text/html", "UTF-8"); 你可以查看这个例子 http://developer.android.com/reference/android/webkit/WebView.html [编辑1] 您应该在 -- " 之前添加 -- \ -- 例如 --> name=\"spanish press\" 下面的字符串对我有用 String webData = "<!DOCTYPE html><head> <meta http-equiv=\"Content-Type\" " + "content=\"text/html; charset=utf-8\"> <html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1250\">"+ "<meta name=\"spanish press\" content=\"spain, spanish newspaper, news,economy,politics,sports\"><title></title></head><body id=\"body\">"+ "<script src=\"http://www.myscript.com/a\"></script>şlkasşldkasşdksaşdkaşskdşk</body></html>"; 你也可以试试这个 final WebView webView = new WebView(this); webView.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null); 从资产 html 文件中读取 ViewGroup webGroup; String content = readContent("content/ganji.html"); final WebView webView = new WebView(this); webView.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null); webGroup.addView(webView); 我有同样的要求,我是按照以下方式完成的。你也可以试试这个。 使用loadData方法 web.loadData(""" <p style='text-align:center'> <img class='aligncenter size-full wp-image-1607' title='' src="+movImage+" alt='' width='240px' height='180px' /> </p> <p> <center> <U> <H2>"+movName+"("+movYear+")</H2> </U> </center> </p> <p><strong>Director : </strong>"+movDirector+"</p> <p><strong>Producer : </strong>"+movProducer+"</p> <p><strong>Character : </strong>"+movActedAs+"</p> <p><strong>Summary : </strong>"+movAnecdotes+"</p> <p><strong>Synopsis : </strong>"+movSynopsis+"</p> """, "text/html", "UTF-8" ); movDirector movProducer 都是我的字符串变量。 简而言之,我保留了 URL 的自定义样式。 如果您正在 JetpackCompose 中寻找某些内容,这可以帮助您: @Composable fun HtmlTextVisualizerComponent(textFromData: String) { val mimeType = "text/html" val encoding = "UTF-8" LazyColumn( modifier = Modifier .padding( start = 24.dp, end = 24.dp, top = 16.dp, bottom = 24.dp, ), ) { items(1) { val state = rememberWebViewState( url = "data:$mimeType;$encoding,$textFromData", ) val navigator = rememberWebViewNavigator() WebView( state = state, modifier = Modifier.fillMaxSize(), navigator = navigator, onCreated = { it.settings.javaScriptEnabled = true }, ) } } } 一定不要忘记在你的 gradle 中添加依赖项: implementation "com.google.accompanist:accompanist-webview:0.30.1"


ng-bootstrap 滚动间谍在没有高度的情况下无法工作?

我在我的项目中使用 ng-bootstrap [ngbScrollSpy] 指令,如文档中所述,但它不起作用 - 滚动时活动项目不会改变。 我的代码如下: 我在我的项目中使用 ng-bootstrap [ngbScrollSpy] 指令,如文档中所述,但它不起作用 - 滚动时活动项目不会改变。 我的代码如下: <div> <div class="sticky-top"> <ul class="nav menu-sidebar"> <li > <a [ngbScrollSpyItem]="[spy, 'about']">About</a> </li> <li > <a [ngbScrollSpyItem]="spy" fragment="schedule">Schedule</a> </li> <li > <a [ngbScrollSpyItem]="spy" fragment="hotel">Information about the hotel</a> </li> </ul> </div> <div ngbScrollSpy #spy="ngbScrollSpy" > <section ngbScrollSpyFragment="about"> <h3>About</h3> <p>{{some long long text and content}}</p> </section> <section ngbScrollSpyFragment="schedule"> <h3>Schedule</h3> <p>{{some long long text and content}}</p> </section> <section ngbScrollSpyFragment="hotel"> <h3>Information about the hotel</h3> <p>{{some long long text and content}}</p> </section> </div> </div> 我在这个 stackoverflow 问题中看到,我的问题是我没有向我的 div 提供 height,这是事实。 但我的滚动间谍部分遍布整个页面,而不是一个小 div,(导航本身是 sticky-top)。所以我不能给它高度。 我知道有替代方法 - 刷新窗口滚动上的滚动间谍,但我没有找到可以帮助我的正确代码。 你能解决我的问题吗? 为我提供刷新滚动间谍的代码/给我有关高度的提示/帮助我找到另一个相应的元素。 非常感谢! 附上 stackblitz 演示的链接 注意:我使用来自 @ng-bootstrap/ng-bootstrap 的 NgbScrollSpy (我想它是非常相似的库) 我做什么: 我将所有内容(包括导航)包装在中 <div class="wrapper" ngbScrollSpy #spy="ngbScrollSpy" rootMargin="2px" [threshold]="1.0" > <div class="sticky-top pt-4 pb-4 bg-white"> ..here the navigation... </div> ..here the sections... <section ngbScrollSpyFragment="about"> </section> //the last I use margin-bottom:2rem; <section ngbScrollSpyFragment="hotel" style="margin-bottom:10rem" </section> </div> 见“门槛”。这表明“更改”活动片段应该可见的百分比(1 是 100%) 包装类 .wrapper{ height:100%; position: absolute; top:0; } 我使用强制链接的类别 //remove all the class for the link a{ color:black; text-decoration:none; padding:8px 16px; } a.custom-active{ color:white; background-color:royalblue } 以及我使用的每个链接 <a [class.custom-active]="spy.active=='about'">About</a> 嗯,问题是如何“滚动到”。 “链接”应该作为链接使用。 第一个是指示“路由器”应该考虑“碎片” 如果我们的组件是独立组件,我们需要使用提供者,provideRouter bootstrapApplication(App, { providers: [ provideRouter([], withInMemoryScrolling({anchorScrolling:'enabled'})), ] }) 然后,我们需要考虑到我们的页面确实没有滚动,div“包装器”是谁拥有滚动。因此,我们订阅 router.events,当事件有“锚点”时,我们滚动“包装器”div constructor(router: Router) { router.events.pipe(filter((e:any) => e.anchor)).subscribe((e: any) => { (document.getElementById('wrapper') as any).scrollTop+= (document.getElementById(e.anchor)?.getBoundingClientRect().top||0) -72; //<--this is the offset }); } 在这个stactblitz中你有一个有效的例子


“限制将街景标记添加到传单地图中的特定区域

我决定通过创建挪威夏季的公路旅行地图来开始学习 Leaflet 和 JavaScript,这是我的项目的可重复示例: 我决定通过创建挪威夏季的公路旅行地图来开始学习 Leaflet 和 JavaScript,这是我的项目的可重复示例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" /> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.css"/> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick-theme.css"/> <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script> <link rel="stylesheet" href="https://unpkg.com/leaflet-routing-machine/dist/leaflet-routing-machine.css" /> <script src="https://unpkg.com/leaflet-routing-machine/dist/leaflet-routing-machine.js"></script> <style> body { margin: 0; } #map { width: 100%; height: 100vh; } .carousel { max-width: 300px; margin: 10px auto; } .carousel img { width: 100%; height: auto; } /* Custom styling for Geiranger popup content */ .geiranger-popup-content { max-width: 500px; padding: 20px; } </style> </head> <body> <div id="map"></div> <script> var map = L.map('map').setView([61.9241, 6.7527], 6); var streetViewMarker = null; // Variable to keep track of the Street View marker L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }).addTo(map); var roadTripCoordinates = [ [59.9139, 10.7522], // Oslo [62.2622, 10.7654], // Tynset [62.5949, 9.6926], // Oppdal [63.0071, 7.2058], // Atlantic Road [62.1040, 7.2054] // Geiranger ]; // Function to initialize Slick Carousel for a specific marker function initSlickCarousel(markerId, images) { $(`#${markerId}_carousel`).slick({ infinite: true, slidesToShow: 1, slidesToScroll: 1, dots: true, arrows: true }); // Add images to the carousel images.forEach(img => { $(`#${markerId}_carousel`).slick('slickAdd', `<div><img src="${img}" alt="Image"></div>`); }); } // Add markers for each destination with additional information and multiple pictures var destinations = [ { coordinates: [59.9139, 10.7522], name: 'Oslo', info: "../07/2023 : Start of the road-trip", images: ['https://www.ecologie.gouv.fr/sites/default/files/styles/standard/public/Oslo%2C%20Norvege_AdobeStock_221885853.jpeg?itok=13d8oQbU', 'https://via.placeholder.com/300', 'https://via.placeholder.com/300'] }, { coordinates: [62.2622, 10.7654], name: 'Tynset', info: "../07/2023 : Fly-fishing spot 1", images: ['https://www.czechnymph.com/data/web/gallery/fisheries/norway/glommahein/Kvennan_Fly_Fishing_20.jpg', 'https://via.placeholder.com/300', 'https://via.placeholder.com/300'] }, { coordinates: [62.5949, 9.6926], name: 'Oppdal', info: "../07/2023 : Awesome van spot for the night", images: ['https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSFRtpLlHWr8j6S2jNStnq6_Z9qBe0jWuFH8Q&usqp=CAU', 'https://via.placeholder.com/300', 'https://via.placeholder.com/300'] }, { coordinates: [63.0071, 7.2058], name: 'Atlantic Road', info: "../07/2023 : Fjord fishing", images: ['https://images.locationscout.net/2021/04/atlantic-ocean-road-norway.jpg?h=1100&q=83', 'https://via.placeholder.com/300', 'https://via.placeholder.com/300'] }, { coordinates: [62.1040, 7.2054], name: 'Geiranger', info: "../07/2023 : Hiking 1", images: ['https://www.fjordtours.com/media/10968/nicola_montaldo-instagram-26th-may-2021-0717-utc.jpeg?anchor=center&mode=crop&width=1120&height=1120&rnd=133209254300000000&slimmage=True', 'https://via.placeholder.com/300', 'https://via.placeholder.com/300'] } ]; // Use Leaflet Routing Machine with Mapbox Routing plugin to get and display the route L.Routing.control({ waypoints: roadTripCoordinates.map(coord => L.latLng(coord[0], coord[1])), router: L.Routing.mapbox('MAP_BOX_KEY'), draggableWaypoints: false, addWaypoints: false, lineOptions: { styles: [{ color: 'brown', opacity: 0.7, weight: 2 }] } }).addTo(map); // Remove the leaflet-routing-container from the DOM var routingContainer = document.querySelector('.leaflet-routing-container'); if (routingContainer) { routingContainer.parentNode.removeChild(routingContainer); } destinations.forEach(function (destination) { var marker = L.marker(destination.coordinates).addTo(map); var markerId = destination.name.replace(' ', '_'); marker.bindPopup(` <b>${destination.name}</b><br> ${destination.info}<br> <div class="carousel" id="${markerId}_carousel"></div> `).on('popupopen', function () { // Initialize Slick Carousel when the marker popup is opened initSlickCarousel(markerId, destination.images); }).openPopup(); }); // Add Street View panorama on map click map.on('click', function (e) { if (streetViewMarker) { // Remove the existing Street View marker map.removeLayer(streetViewMarker); } let lat = e.latlng.lat.toPrecision(8); let lon = e.latlng.lng.toPrecision(8); streetViewMarker = L.marker([lat, lon]).addTo(map) .bindPopup(`<a href="http://maps.google.com/maps?q=&layer=c&cbll=${lat},${lon}&cbp=11,0,0,0,0" target="blank"><b> Cliquer ici pour avoir un aperçu de la zone ! </b></a>`).openPopup(); }); </script> </body> </html> 一切都按预期进行,我不得不说我对渲染非常满意。然而,通过查看 Stackoverflow 上的不同主题,我发现可以通过单击地图来显示 Google 街景视图。这个功能真的很酷,但我想限制仅在我的公路旅行行程中添加街景标记的选项。 有人可以帮我吗? 您通过创建挪威夏季公路旅行地图开始了学习 Leaflet 和 JavaScript 的旅程,真是太棒了。到目前为止,您的项目设置看起来不错,我很乐意在您的进展过程中提供指导或帮助。 既然您已经包含了 Leaflet、Slick Carousel 和 Leaflet Routing Machine 库,看来您正计划使用 Slick Carousel 创建一个带有路线的交互式地图,也许还有一些附加功能。 以下是一些增强您的项目的建议: 地图初始化: 使用初始视图和要显示的任何特定标记或图层设置您的传单地图。 路由功能: 利用 Leaflet Routing Machine 将动态路线添加到您的地图。您可以自定义路线、添加航点并提供逐向指示。 照片轮播: 既然您提到了公路旅行地图,请考虑集成 Slick Carousel 来展示旅途中关键地点的照片或描述。这可以为您的地图添加视觉上吸引人的元素。 地图控制: 探索 Leaflet 插件或内置控件以增强用户体验。例如,您可以添加缩放控件或比例尺。 响应式设计: 确保您的地图能够响应不同的设备。 Leaflet 通常适合移动设备,但如果需要的话进行测试和调整是一个很好的做法。 数据层: 如果您有与您的公路旅行相关的特定数据点或事件,您可以使用标记或其他视觉元素在地图上表示它们。 JavaScript 交互性: 使用 JavaScript 为地图添加交互性。对于 ㅤ 实例,当用户单击标记时,您可以创建包含附加信息的弹出窗口。 记得迭代测试你的项目,并参考每个库的文档以获取详细的使用说明。 如果您有具体问题或在此过程中遇到挑战,请随时提问。祝您的公路旅行地图项目好运!


错误:在此 BlocBuilder<InternetBloc> Widget<InternetBloc, InternetState> 上方找不到正确的提供程序

我在尝试将 flutter_bloc 集成到 flutter 项目中时遇到错误。 错误:在此 BlocBuilder 上方找不到正确的 Provider 我在尝试将 flutter_bloc 集成到 flutter 项目中时遇到错误。 错误:在此 BlocBuilder Widget 上方找不到正确的提供者 这是我正在使用的代码示例。 internet_state.dart abstract class InternetState{} class InitialInternetState extends InternetState{} class LostConnectionInternetState extends InternetState{} class GainConnectionInternetState extends InternetState{} internet_event.dart abstract class InternetEvent{} class LostConnectionEvent extends InternetEvent{} class GainConnectionEvent extends InternetEvent{} internet_bloc.dart class InternetBloc extends Bloc<InternetEvent, InternetState>{ final Connectivity _connectivity = Connectivity(); StreamSubscription? streamSubscription; InternetBloc() : super(InitialInternetState()){ on<GainConnectionEvent>((event, emit) => emit(GainConnectionInternetState())); on<LostConnectionEvent>((event, emit) => emit(LostConnectionInternetState())); _connectivity.onConnectivityChanged.listen((event) { if(event == ConnectivityResult.mobile || event == ConnectivityResult.wifi){ add(GainConnectionEvent()); } else { add(LostConnectionEvent()); } }); } @override Future<void> close() { streamSubscription?.cancel(); return super.close(); } } main.dart class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(title),), body: SafeArea( child: Center(child: BlocBuilder<InternetBloc, InternetState>( builder: (context, state) { return const Text("hello"); }, )), ),); } } 我明白了。 ======== 小部件库捕获异常====================================== =================== 构建 MediaQuery(MediaQueryData(size: Size(392.7, 783.3), devicePixelRatio: 2.8, textScaler: noscaling, platformBrightness: Brightness.light, padding: EdgeInsets.zero, viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets 时抛出以下 ProviderNotFoundException。零,systemGestureInsets:EdgeInsets(29.8,24.0,29.8,8.0),alwaysUse24HourFormat:假,accessibleNavigation:假,highContrast:假,onOffSwitchLabels:假,disableAnimations:假,invertColors:假,boldText:假,navigationMode:传统,gestureSettings:DeviceGestureSettings (touchSlop:8.0),显示功能:[])): 错误:无法在此 BlocBuilder Widget 之上找到正确的提供程序 发生这种情况是因为您使用了不包含提供程序的 BuildContext 你的选择。有以下几种常见场景: 您在main.dart中添加了一个新的提供程序并执行了热重载。 要修复此问题,请执行热重启。 您尝试阅读的提供商处于不同的路线。 提供商具有“范围”。因此,如果您在路线中插入提供者,那么 其他路线将无法访问该提供商。 您使用了 BuildContext,它是您尝试读取的提供程序的祖先。 确保 BlocBuilder 位于您的 MultiProvider/Provider 下。 当您创建提供程序并尝试立即读取它时,通常会发生这种情况。 例如,代替: Widget build(BuildContext context) { return Provider<Example>( create: (_) => Example(), // Will throw a ProviderNotFoundError, because `context` is associated // to the widget that is the parent of `Provider<Example>` child: Text(context.watch<Example>().toString()), ); } 考虑使用builder,如下所示: Widget build(BuildContext context) { return Provider<Example>( create: (_) => Example(), // we use `builder` to obtain a new `BuildContext` that has access to the provider builder: (context, child) { // No longer throws return Text(context.watch<Example>().toString()); } ); } 如果这些解决方案都不起作用,请考虑在 StackOverflow 上寻求帮助: https://stackoverflow.com/questions/tagged/flutter The relevant error-causing widget was: SafeArea SafeArea:file:///Users/../Projects/flutterTest/bloc_test/lib/main.dart:37:13 When the exception was thrown, this was the stack: #0 Provider._inheritedElementOf (package:provider/src/provider.dart:343:7) #1 Provider.of (package:provider/src/provider.dart:293:30) #2 ReadContext.read (package:provider/src/provider.dart:649:21) #3 _BlocBuilderBaseState.initState (package:flutter_bloc/src/bloc_builder.dart:130:36) #4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5602:55) #5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5) ... Normal element mounting (4 frames) #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16) #10 Element.updateChild (package:flutter/src/widgets/framework.dart:3831:20) #11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #12 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #13 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #14 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #15 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6743:14) #16 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #17 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #18 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #19 StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5) #20 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #21 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #22 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #23 StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5) #24 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #25 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #26 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #27 StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5) #28 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #30 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #31 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #32 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #34 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #35 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #36 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #37 Element.updateChildren (package:flutter/src/widgets/framework.dart:3964:32) #38 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6896:17) #39 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #40 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #41 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #42 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #43 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #44 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #45 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #46 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #47 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #48 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #49 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #50 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #51 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #52 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #53 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #54 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #55 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #56 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #57 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #58 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #59 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #60 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #61 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #62 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #63 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6743:14) #64 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #65 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #66 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #67 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #68 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #69 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6743:14) #70 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #71 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #72 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #73 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #74 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #75 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #76 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #77 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #78 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #79 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #80 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #81 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #82 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #83 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #84 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #85 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #86 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #87 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #88 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #89 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #90 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #91 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #92 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #93 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #94 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #95 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #96 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #97 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #98 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #99 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #100 ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5) #101 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #102 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #103 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11) #104 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #105 StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5) #106 Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15) #107 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16) #108 Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7) #109 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2895:19) #110 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:984:21) #111 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5) #112 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15) #113 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9) #114 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:978:7) #118 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12) (elided 3 frames from class _Timer and dart:async-patch) ==================================================================================================== 我不想使用像 MultiProvider 这样的全局提供程序。 您应该在某处创建 InternetBloc 并提供它。 MultiProvider 本身并不是全局的,它只是多个。 更多信息在这里:https://bloclibrary.dev/#/flutterbloccoreconcepts?id=blocprovider 所以,如果您不想使用全局提供程序,它将看起来像这样: class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(title), ), body: SafeArea( child: Center( child: BlocProvider<InternetBloc>( create: ( context) => InternetBloc(), child: BlocBuilder<InternetBloc, InternetState>( builder: (context, state) { return const Text("hello"); }, ), ), ), ), ); } } 要使用 BlocBuilder,您需要在 Widget 树中放置一个 BlocProvider。最佳实践是将其放置得尽可能深。在您的情况下,只需将 BlocProvider 放在 BlocBuilder 之上。 此外 MultiProvider / MultiBlocProvider 不是全局 Provider。它只是一个提供多个 Provider/BlocProvider 的便捷小部件。 class MyHomePage extends StatelessWidget { const MyHomePage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(title), ), body: SafeArea( child: Center( // Now everything below that can access the InternetBloc child: BlocProvider<InternetBloc>( create: (_) => InternetBloc(), child: BlocBuilder<InternetBloc, InternetState>( builder: (context, state) { return const Text("hello"); }, ), ), ), ), ); } }


© www.soinside.com 2019 - 2024. All rights reserved.