新人求助,div 模块问题,麻烦大家帮我看一下问题出在哪?

问题可以说又简单又复杂

我在用template里创建了多个div,

想着分上中下布局,在”head”里定义了上布局,

然后在”head”在下面想做一个搜索框,另外再写一个div “search”

但是”search”的样式定义好了,放在与”head”同级并列

却不可以显示出定义好的样式,

然而放在”head”里面,又能正常显示。

下面二图是运行情况,以及开发者模式检查。

第二张图显示,”search”并没有样式应用到。

请问这是什么原因?:dash:

<template>

    <div class="container_global">
        <div class="head">
            <div class="return"><span style="color:#1989fa">&lt;&ensp;返回</span></div>
            <div class="title">选课</div>
        <div class="search">
                1234
        </div>
        </div>
        <div class="search">
                1234
        </div>
    </div>
</template>

<style lang="less" scoped>
.container_global{
    height: 180vw;
    width: 100%;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background-color: #ebedf0;
}
.head{
    height: 11vw;
    width: 100%;
    background-color: white;
    .return{
        float: left;
        width: 12vw;
        height: 6vw;
        position: absolute;
        left: 6vw;
        top: 3vw;
        font-size: 3.5vw;
        font-family: 'Mircosoft Yahei';
        font-weight: bold;
    }
    .title{
        float: left;
        width: 8vw;
        height: 6vw;
        position: absolute;
        font-size: 4vw;
        left: 50%;
        top: 2.5vw;
        transform: translateX(-50%);
        font-family: 'Mircosoft Yahei';
        font-weight: bold;
    }
.search{
    height: 12vw;
    width: 100%;
    background-color: white;
    position: absolute;
    top: 50%;
}
}
</style>
vue
讨论数量: 3

你这用的太奇怪了 又用定位 又用浮动的,分析起来很麻烦的,建议你还是好好学一下布局,把浮动、flex、定位 好好学习下

3年前 评论
morethanthis (楼主) 3年前
自由与温暖是遥不可及的梦想

布局 最后不要依赖于 浮动 定位之类的

3年前 评论

额...怎么说呢,你写css样式时,.search 是在 .head 内部的,所以你把 search 和 head 平级方的话肯定是没有样式的! 你把样式改成第二章图那样就可以了。

file

file

3年前 评论
morethanthis (楼主) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!