简体   繁体   English

如何使Vue for循环生成的按钮覆盖div的整个区域?

[英]How can I make my Vue for-loop generated buttons cover the entire area of my div?

I'm trying to generate buttons with a Vue for-loop that will stretch the entire width of a div. 我正在尝试生成带有Vue for循环的按钮,该按钮将拉伸div的整个宽度。

My template looks like this: 我的模板如下所示:

<div id="nonav" style="width: 100%; margin-right: 0px; margin-top: 100px">
                <button v-for="(val, key) in convertedCategories" :key="key"  @click="selectCategory(val, key)" v-if="Object.keys(selectedCategory).length===0  && searchText=='' && Object.keys(selectedSubcategory).length===0"
                    :style="{ width: $el.clientWidth/4 + 'px',
                        height: $el.clientHeight/4 + 'px',  
                        'padding-top': '30px',

                        display: 'inline-block'}"
                    class="tiles"           
                >
                <div v-if="val['icon']"><icon :name="val['icon']" scale="4" color="rgb(234, 34, 45)"></icon></div>
                <span><p style="font-size: 18px">{{ val['.key'].toUpperCase() }}</p></span>
                </button>
                <button v-for="(subval, subkey) in subcats(selectedCategory)" v-if="Object.keys(selectedCategory).length>0 && Object.keys(selectedSubcategory).length===0  && searchText=='' && subval['.key'] !== 'icon'" :key="subkey" @click="selectSubcategory(subval, subkey)"
                    :style="{ 
                        width: $el.clientWidth/4 + 'px',
                        height: $el.clientHeight/4 + 'px',

                        'padding-top': '30px',


                        display: 'inline-block'}"
                    class="tiles"       
                >
                <span v-if="subval['icon']"><icon :name="selectedCategory['icon']" scale="4" color="rgb(234, 34, 45)"></icon></span>
                <p style="font-size: 18px">{{ subkey.toUpperCase() }}</p>
                </button>
            </div>

As you can see, I'm trying to define the width by the parent div's width divided by 4, so there will be 4 buttons per row. 如您所见,我正在尝试通过父div的宽度除以4来定义宽度,因此每行将有4个按钮。 The problem is, although the buttons seem responsive, they do not fill the entire width --- there is some gap that is left while I resize the window. 问题是,尽管按钮似乎响应很快,但是它们并不能填满整个宽度---在调整窗口大小时还剩下一些间隙。 How can this be the case if the buttons are always a quarter of the window width? 如果按钮始终是窗口宽度的四分之一,怎么办?

(To clarify: while I'm resizing, I can close the window enough so that the buttons fill the div as they should, but any more and the buttons will stack on top of each other and leave padding on the left and right) (要澄清一下:在调整大小时,我可以关闭窗口足够多的时间,以使按钮按其应有的方式填充div,但更多的话,按钮将堆叠在彼此的顶部,并在左右两侧留出填充物)

First Remove the button inline style. 首先,删除按钮的内联样式。 Second always provide JSfiddle when you need CSS help 其次,在需要CSS帮助时始终提供JSfiddle

#nonav {
    display: flex;
    align-items: stretch;
    justify-content: center
}
#nonav button.tules {
   flex: 1;
   width: auto;
}

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

相关问题 如何使对话框覆盖整个屏幕? - How can I make my dialog box cover the whole screen? 如何使我的脚本循环并检查所有处于活动状态的按钮? 香草js - How can I make my script loop and check all buttons that are active? vanilla js Javascript:如何覆盖整个区域? - Javascript: how to cover entire area? JavaScript for循环:如何使我的数字转换器工作? - JavaScript for-loop: how to make my number translator work? 如何使我的 canvas 区域适合 iphone 浏览器? - How can i make my canvas area fit to the iphone browser? 无论窗口大小如何,如何获取徽标,幻灯片和图像以覆盖整个屏幕 - How do I get my logo, slideshow and image to cover my entire screen no matter the window size 如何使Sublime Text的“改进的本机for循环”增量像普通的for循环一样? - How can I make Sublime Text's “Improved Native for-loop” increment like a normal for-loop? 如何使按钮导航到不同页面? - How can i make my buttons navigate to diffrent pages? 如何使用变量内的变量进行for循环工作 - how can I make an for-loop work with a variable inside a variable 如何让我的 vue 2 组件在我重写到 vue 3 时使用? - how i can make my vue 2 components to use in my rewrite to vue 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM