怎么设置border-width为父元素高度的30%

不用js只用css能实现吗

阅读 4.5k
2 个回答

我看到过的实现是,设置像素绝对高度...[Orz...大概没啥用...
例如:

<div class="father">
    <div class="son"></div>
</div>
.father {
    position: relative;
    height: 100px;
    width: 100%;
}
.father .son {
    position: absolute;
    height: 30px;
    width: 100%;
}
    <style type="text/css">
        #father {
            height: 100px;
            width: 200px;
            background: green;
        }
        #child {
            height: 30%;
            width: 20px;
            background: yellow;
            margin: auto;
        }
        .rotate90 {
            transform: rotate(90deg);
        }
    </style>



<div id="father">
    <div id="child" class="rotate90">
    </div>
</div>


強行rotate, 假裝是width.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题