php - 如何显示前 3 里 100% 和每行 2 里 33.33% 宽度?

标签 php jquery html css html-lists

我有一个设计。我在这里遇到一个问题。

enter image description here

我要做的是,我必须显示前 3 个 li 标签的 100% 宽度,并保留 li 标签的 33.33%。

这是我的预期输出

li-100% width
li-100% width
li-100% width
li-33.33% width | li-33.33% width | big image here(not a part of loop)
li-33.33% width | li-33.33% width |
li-33.33% width | li-33.33% width |

但是请注意,我正在使用 while 循环,所以我会得到类似的输出

li-100% width
li-100% width
li-100% width
li-33.33% width | li-33.33% width | li-33.33% width
li-33.33% width | li-33.33% width | li-33.33% width
li-33.33% width | li-33.33% width | li-33.33% width

我必须每行只显示 2 里。

我正在使用以下逻辑

<div class="wrapperClass">
  <ul>
    <?php
      $index = 0;
      $check=0;
       while ( condition ) {
         if ($index < 3) {?>
      <li>
        <!--width 100%-->
      </li>
      <?php }
                else{?>
      <li>
        <!--width with 33.33-->
      </li>
      <?php } $index++;}?>
  </ul>
  <img src="">
</div>

CSS

.wrapperClass ul li:nth-child(1),.wrapperClass ul li:nth-child(2),.wrapperClass ul li:nth-child(3){
    width:100%;
}
.wrapperClass ul li{width:33.33%;display: inline-block;}

你能帮我解决这个问题吗?

最佳答案

使用这个CSS

.wrapperClass ul li:nth-child(-n+3){
    width:100%;
}
.wrapperClass ul li{display: inline-block; width:33.33%;}
<div class="wrapperClass">
  <ul>
    <li>Some text</li>
    <li>Some text</li>
    <li>Some text</li>
    <li>Some text</li>
    <li>Some text</li>
  </ul>
</div>

关于php - 如何显示前 3 里 100% 和每行 2 里 33.33% 宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58988147/

相关文章:

javascript - 如何使用 jQuery .serialize() 为 GET 参数获得成功和不成功的控件?

jQuery:根据包含元素的背景颜色更改文本颜色?

html - 让 youtube.com 在 iF​​rame 中加载

html - Actionmailer css 添加到整个应用程序

php - 根据另一个表的选择结果选择一个表

php - 如何在 TCPDF 中设置标题背景颜色?

php - 如何使用 jquery 验证器检查用户名和电子邮件已经存在,除了数据库中的一个特定 id

php - 在 PHP 中使用 session ID 作为文件名是否安全?

jquery - 需要 HTML5 输入 - 如何禁用

html - 停止位置绝对 child 不占用 parent 的宽度