简体   繁体   English

如何在不更改 position 的情况下将 div 和 dl 包装在 js 中

[英]How to wrap div and dl in js without changing their position

I have been messing with creating a site (with shopify) and want to create a box-shadow under two elemtens which occur more than one time on the site.我一直在搞乱创建一个站点(使用 shopify),并希望在站点上不止一次出现的两个元素下创建一个盒子阴影。 Creating a wrapper div is not working.创建包装器 div 不起作用。

I tried working with wrap and wrapAll but my results are, that wrap is wrapping the 2 divs but displaying a dropshadow underneath each element, while WrapAll wraps all elemtns and positions them in one giant div.我尝试使用 wrap 和 wrapAll 但我的结果是,该 wrap 包装了 2 个 div,但在每个元素下方显示了一个阴影,而 WrapAll 包装了所有 elemtns 并将它们放置在一个巨大的 div 中。

I am new to css and js but my guess is to我是 css 和 js 的新手,但我的猜测是

  1. loop over the parent divs循环遍历父 div
  2. get the 2 child divs获取 2 个子 div
  3. wrap them via wrapall but i dont know how.通过 wrapall 包装它们,但我不知道如何。
<div class="grid-view-item product-card">
    <div class="h4 grid-view-item__title product-card__title" aria-hidden="true">Testproduct</div>
    <dl class="price price--listing">...</dl>
</div>
        
$('.product-card__title,.price--listing').wrap('<div class="child"></div>');

(js code wraps all into a single big div) (js 代码全部封装到一个大 div 中)

Thank you for any answers.谢谢你的任何答案。

You can replace the code您可以替换代码

like this:像这样:

<div class="grid-view-item product-card">
        <div class="inner">
            <div class="h4 grid-view-item__title product-card__title" aria-hidden="true">Testproduct</div>
            <dl class="price price--listing">...</dl>
        </div>
    </div>
    $('.inner').wrap('<div class="product-card-inner"></div>');

and for box shadow you can give shadow to .product-card对于盒子阴影,您可以为.product-card提供阴影

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

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