我有一个CSS的挑战,没有HTML的变化允许。
创建了一个页脚项的小列表,这些项在DOM中是按行排列的,但在桌面上需要像列一样处理,但在移动设备上,每列应该一个接一个。
这里是我尝试到目前为止的代码和图像也是什么需要:
.cmp-footer-navigation__group {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin: 0 auto;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
list-style: none;
}
.cmp-footer-navigation__item {
width: 20%;
}
<ul class="cmp-footer-navigation__group">
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/" data-title="HOME" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 1</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/patients-and-families" data-title="Patients & Families" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 6</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/locator" data-title="Locations" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 11</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="https://www.pruittcares.org/" data-title="Donate" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_blank">Link 15</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-company/emergency-preparedness" data-title="COVID-19" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 19</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-company" data-title="Our Company" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 2</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-services/skilled-nursing" data-title="Skilled Nursing" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 7</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/resources-home" data-title="Resources" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 12</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-company/partner-services" data-title="Partner Services" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 16</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/contact-us/privacy-policy" data-title="Privacy policy" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 20</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-company/news-list" data-title="News" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 3</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-services/home-health" data-title="Home Health" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 8</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/employment" data-title="Careers" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 13</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-services/vendor-services" data-title="Vendor Services" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 17</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/contact-us/terms-of-use" data-title="Terms of Use" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 21</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/contact-us" data-title="Contact" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 4</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-services/hospice" data-title="Hospice & Palliative Care" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 9</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-services" data-title="Other Services" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 14</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-company/medical-supply" data-title="Medical & Nutritional Supply" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 18</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/content/dam/pruitthealth/documents/pdf/Section%201557%20Notice%20-%20Doc%20for%20Website.pdf" data-title="Notice of Nondiscrimination" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 22</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" href="#" target="_self">Link 5</a>
</li>
<li class="cmp-footer-navigation__item cmp-navigation__item--level-0" data-cmp-data-layer="">
<a href="/our-services/senior-living" data-title="Senior Living" data-cmp-clickable="" class="cmp-footer-navigation__item-link subtitle subtitle--5" target="_self">Link 10</a>
</li>
</ul>
正如您在给定的代码中所看到的,数据实际上是按行排列的,但挑战是将其视为行,然后在移动设备上,每列应该一个接一个地出现。
我试着用第n个孩子的逻辑来实现
就像这样,&:nth-child(5n+1){}
但无法得到所需的结果,是否可以使用NTH-child或Grid?或任何其他方法更好。
2条答案
按热度按时间huwehgph1#
你可以很容易地实现这一点,通过使用第N个孩子的方法,你需要做的就是,计算你的逻辑,
通过你的问题,我在这里假设你的项目宽度在桌面上将保持20%,即每行5个项目。然后这样做。
x一个一个一个一个x一个一个二个x
v1uwarro2#
如果你可以访问DOM,你可以这样做,你把每一列 Package 成一个
<li>
标签,并使用flex-direction:管柱