在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 如何實(shí)現(xiàn)中心點(diǎn)等距分布,第一項(xiàng)和最后一項(xiàng)貼邊

如何實(shí)現(xiàn)中心點(diǎn)等距分布,第一項(xiàng)和最后一項(xiàng)貼邊

圖片描述

想要實(shí)現(xiàn)如圖效果,每個(gè)項(xiàng)目中心點(diǎn)等距分布,但第一項(xiàng)的左邊無空隙,最后一項(xiàng)右邊無空隙,所有內(nèi)容異步獲取,數(shù)量不定,文字內(nèi)容長(zhǎng)短不等
中心點(diǎn)等距分布
中心點(diǎn)等距分布
中心點(diǎn)等距分布
文字內(nèi)容長(zhǎng)短不等
文字內(nèi)容長(zhǎng)短不等
文字內(nèi)容長(zhǎng)短不等

我覺得純CSS是實(shí)現(xiàn)不了,有沒有js能解決的辦法?

求解答

回答
編輯回答
傲嬌范

flex可以的,還有一個(gè)奇葩方法兼容性好一點(diǎn),放一排等寬的div,第一個(gè)text-align:left,最后一個(gè)right,中間的center,如果是文本可以考慮

2017年6月19日 07:35
編輯回答
浪婳

flex布局了解一哈
阮一峰-flex
可以給項(xiàng)目的父元素設(shè)置display:block,justify-content:space-between

2017年12月19日 14:31
編輯回答
陪我終

圖片描述圖片描述

圖片描述

是這樣要效果嗎?望采納

2018年2月18日 01:07
編輯回答
維她命

在每一個(gè)子元素設(shè)定寬(足夠?qū)挘缓笞寖?nèi)容居中),然后使用space-between或space-around實(shí)現(xiàn)

2017年12月30日 03:22
編輯回答
檸檬藍(lán)

自己寫了個(gè)一看就很不優(yōu)雅的方式實(shí)現(xiàn)吧,還是在vue里有dom操作真的是...emmm...惡心

<template>
    <div class="wrap">
        <div :style="[key == 0 && marginLeft, key == items.length - 1 && marginRight]" class="text" v-for="(item, key) in items" :key="key"><span>{{ item }}</span></div>
    </div>
</template>

<script>
export default {
    props: {
        items: {
            type: Array,
            default: () => {
                return [];
            }
        }
    },
    data() {
        return {
            marginLeft: {
                marginLeft: ''
            },
            marginRight: {
                marginRight: ''
            }
        }
    },
    mounted() {
        const texts = document.querySelectorAll('.text span');
        this.marginLeft.marginLeft = `-${texts[0].offsetLeft}px`;
        this.marginRight.marginRight = `-${texts[texts.length - 1].offsetLeft}px`;
    }
}
</script>

<style lang="less">
.wrap {
    display: flex;
    justify-content: space-between;
    .text {
        position: relative;
        flex: 1;
        text-align: center;
        &::after {
            content: '';
            position: absolute;
            left: 0;
            right: 0;
            display: block;
            margin: 5px auto;
            width: 1px;
            height: 10px;
            background: #ccc;
        }
    }
}
</style>

處理marginRight的時(shí)候還是取了offsetLeft,考慮到文字是居中的,左右的offset相同。

https://codepen.io/anon/pen/V...

2017年8月3日 09:35
編輯回答
純妹

首先考慮flex布局 justify-content:space-between,兼容IE10+,
其次可以用使用margin-right,然后使用css3選擇器nth-last-child將最后一個(gè)元素的margin置為0

2018年2月21日 19:22