简体   繁体   English

显示:表格单元格绝对定位查询

[英]Display: table-cell absolute positioning query

I am building a drop-down menu for wordpress, and i've come across an interesting dilemna. 我正在为wordpress构建一个下拉菜单,但遇到了一个有趣的难题。 Initialy i had a drop down when you hovered "shop" that would display all categories, and from their highlighting categories would bring up 5 random products in a div underneath that would span the whole width of the menu bar. 最初,当我将鼠标悬停在显示所有类别的“商店”时,我会出现一个下拉菜单,从其突出显示的类别中,可以在div下方的div中调出5个随机产品,这些产品将覆盖菜单栏的整个宽度。 This worked fine 这很好

However, the client at the time decided he needed much more categories than what were there, and aptly i had to break them down into subcategories. 但是,当时的客户认为他需要类别比那里的要多得多 ,而我不得不将它们细分为子类别。

The menu currently works like this: 菜单当前的工作方式如下:

Hover shop -> show main categories Hover categories -> show sub-categories. 悬停商店->显示主要类别悬停类别->显示子类别。

This part works absolutely fine; 这部分工作正常; however the list to show the subcategories is laid out using css table settings in order to keep the sub-categories list spread evenly across the size of the menu. 但是,使用css表设置对显示子类别的列表进行布局,以使子类别列表在菜单大小上均匀分布。 You can see an example of what i mean here . 您可以在此处看到我的意思的示例。

Previously, i didn't use the css table settings, as the menu fit just fine. 以前,我没有使用css表设置,因为菜单非常合适。 The drop down div that contained the categories products worked just fine. 包含类别产品的下拉div效果很好。 Now that they are within the css table markup though, even though they are not defined as being so, seem to be "pretending" to be table-cells. 现在,尽管它们没有在CSS表标记中定义,但它们似乎已经“假装”为表单元格。 Every drop down of the products is being placed to the right of each subcategory as a blank space. 产品的每个下拉列表都在每个子类别的右侧放置空白。 But because they are set to spread evenly, it makes it look very odd. 但是,由于它们将均匀分布,因此看起来很奇怪。

So i have two questions: Firstly; 所以我有两个问题:第一。 despite displaying absolutely, the drop down products section is -not- going where i need it to go. 尽管绝对显示,但下拉产品部分却不在我需要的地方。 Is there a way to break these out of the table layout? 有没有办法打破这些表布局?

Secondly, if not, what other options do i have to make these categories display evenly across the parent div no matter how many subcategories i have? 其次,如果没有,无论我有多少个子类别,我还需要哪些其他选择才能使这些类别在父div上均匀显示? An option i considered was working out the width percentage needed using javascript and then applying that straight to the li's, however i'm not sure how viable that is. 我考虑的一个选项是使用javascript计算出所需的宽度百分比,然后将其直接应用于li,但是我不确定那是多么可行。

$args = array(

     'taxonomy'     => $taxonomy,
     'orderby'      => $orderby,
     'show_count'   => $show_count,
     'pad_counts'   => $pad_counts,
     'hierarchical' => $hierarchical,
     'title_li'     => $title,
     'hide_empty'   => $empty
);
$all_categories = get_categories( $args );
$categorycounter == 0;
foreach ($all_categories as $cat) {
if($cat->category_parent == 0) {
    $categorycounter = $categorycounter + 1;
    $categorypadding = "";
    $category_id = $cat->term_id;       
    echo $categorypadding . '<li class="category-' . $categorycounter.  '"><a class="main-nav-link" href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a><div class="drop-down-'. $cat->name .'"><section class="drop-down-section"><section class="sub-list">';
// set up subcategories to display below main categories

              $IDbyNAME = get_term_by('name', $cat->name, 'product_cat');

              $product_cat_ID = $IDbyNAME->term_id;
                    $args4 = array(
                   'hierarchical' => 1,
                   'show_option_none' => '',
                   'hide_empty' => 0,
                   'parent' => $product_cat_ID,
                   'taxonomy' => 'product_cat',     
                    'posts_per_page' => -1
              );            

            $subcategoryloop = get_categories( $args4 );        
            $subcount = 0;
            foreach ($subcategoryloop as $sc){
            if($subcategoryloop){
                $subcount = $subcount + 1;
            $link = get_term_link( $sc->slug, $sc->taxonomy);
            echo '<a class="subme" href="' . $link . '">'. $sc->name .'</a><section class="drop-down-products">';


                                //set up subcategories to display products   

                                        $args2 = array(
                                        'posts_per_page' => -1,
                                        'product_cat' => $sc->slug,
                                        'post_type'=>'product',
                                         'orderby' => 'rand'
                                  );    

                                $productcount = 0;
                                $loop = new WP_Query( $args2 );

                                while ( $loop->have_posts() ) : $loop->the_post();

                                            $productcount = $productcount + 1;
                                            if($productcount < 6){
                                            echo "<section class='thumbcontainer'><p><a href='";
                                            the_permalink();
                                            echo "'>" ;
                                            the_title();
                                            $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
                                                echo "</a></p><img src='" . $feat_image . "'/><br/><p class='dropdown-price'>";
                                                $price = get_post_meta( get_the_ID(), '_regular_price', true);
                                                echo "&pound;" .$price;
                                                echo "</p></section>";



                                            }
                                endwhile;

            echo "<section><a class='view-more' href='". get_term_link($cat->slug, 'product_cat') ."'>View More Products</a></section></section>";


            }
            }
echo "</section></section></div></li>";

 }
 }

As a side note, i know my code is messy. 附带一提,我知道我的代码很乱。 Sorry! 抱歉!

To justify the list, add: 要证明列表的合理性,请添加:

.sub-list {
  display: table;
  table-layout: fixed;
}

.subme {
  width: 100%;
}

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

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