gpt4 book ai didi

css - 将文本旋转 90°,生成的 div 在父级中有位置

转载 作者:太空宇宙 更新时间:2023-11-03 20:25:00 25 4
gpt4 key购买 nike

当我旋转文本(或者更确切地说是包含文本的 div)时,这会导致 div escaping 它是父级。不仅如此,div 的高度就是它的原始宽度。我宁愿坚持使用 CSS 来获得所需的结果,而不是依赖 javascript/jquery,即使这些工具可用,因为我使用的是 Bootstrap-4我怎样才能确保旋转的 div 保留在它的父级内部,并使用它的父级宽度/高度作为高度/宽度的基础,因为旋转了 90°?

谢谢!

.emptydropzone{
height: 10vh;
border: 1vh dashed #000;
border-radius: 1vh;
background-color: #CCC;
}

.taflag{
width: 98%;
min-height: 50px;
margin: 10px 125px 10px 5px;
padding: 10px 10px 10px 10px;
border: 5px solid #90C;
border-radius: 5px;
background-color: #90C;
color: #FFF;
font-size:xx-large;
font-weight: bolder;
}

.rotateparent {
position:absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: yellow; /* this is just to see the parent div in testing */
}

.agentflag{
transform: rotate(-90deg);
border: 5px solid #F00;
border-radius: 5px;
background-color: #F00;
color: #FFF;
font-size:xx-large;
font-weight: bolder;



}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<body>

<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="row">
<div class="col-2">
<div class="taflag"> TA </div>
</div>
<div class="col-10">
<div class="emptydropzone" id="ta" > </div>
</div>
</div>
<div class="row">
<div class="col-2">
<div class="rotateparent">
<div class="agentflag"> AGENTS </div>
</div>
</div>
<div class="col-10">

<div class="emptydropzone" id="agent1"> </div>
<div class="emptydropzone" id="agent2"> </div>
<div class="emptydropzone" id="agent3"> </div>
<div class="emptydropzone" id="agent4"> </div>

</div>
</div>
</div>
</div>
</div>



<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

enter image description here

最佳答案

writing-mode 在这里可能更有效率。

可能用更少的 html 和更多的 boostrap 类进行更新

.emptydropzone {
min-height: 10vh;
border: 1vh dashed #000;
border-radius: 1vh;
background-color: #CCC;
}

.taflag {
width: 98%;
min-height: 50px;
margin: 10px 125px 10px 5px;
padding: 10px 10px 10px 10px;
border: 5px solid #90C;
border-radius: 5px;
background-color: #90C;
color: #FFF;
font-size: xx-large;
font-weight: bolder;
}

.rotateparent {
background: yellow;
padding: 10px 0;
}

.agentflag {
writing-mode: vertical-lr;
transform: scale(-1, -1);
/* untill
writing-mode:sideways-lr; works everywhere */
margin: auto;
border: 5px solid #F00;
border-radius: 5px;
background-color: #F00;
color: #FFF;
font-size: xx-large;
font-weight: bolder;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<body>

<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="row">
<div class="col-2">
<div class="taflag"> TA </div>
</div>
<div class="col-10">
<div class="emptydropzone" id="ta"> </div>
</div>
</div>
<div class="row">

<div class="col-2 d-flex rotateparent m-0">
<div class="agentflag m-auto"> AGENTS </div>
</div>

<div class="col-10 d-flex flex-column justify-content-around">

<div class="emptydropzone" id="agent1"> </div>
<div class="emptydropzone" id="agent2"> </div>
<div class="emptydropzone" id="agent3"> </div>
<div class="emptydropzone" id="agent4"> </div>

</div>
</div>
</div>
</div>
</div>



<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

关于css - 将文本旋转 90°,生成的 div 在父级中有位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58456309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com