gpt4 book ai didi

html - CSS 箭头在 div 的右侧垂直居中

转载 作者:太空宇宙 更新时间:2023-11-04 14:53:54 26 4
gpt4 key购买 nike

正如标题所说,我试图将 CSS 三 Angular 形/箭头垂直居中放置在 div 的右侧,当然,我希望使用纯 CSS 解决方案来实现这一点。

我会包含图片,但由于我的低代表,我不能。

注意:我当前的代码无法正常工作并且不跨浏览器兼容(即 Chrome 将箭头放在右上角~但在 Firefox 上,它会被压到边界之外)

我的代码

HTML:

<div class="main-panel">
<nav class="left-panel">
<ul class="page-nav">
<li class="page-tab active"><a class="page-nav-link">Dashboard</a></li>
<li class="page-tab"><a class="page-nav-link">Page 1</a></li>
<li class="page-tab"><a class="page-nav-link">Page 2</a></li>
<li class="page-tab"><a class="page-nav-link">Page 3</a></li>
<li class="page-tab"><a class="page-nav-link">Somewhat long</a></li>
<li class="page-tab"><a class="page-nav-link">Somewhat long abc</a></li>
<li class="page-tab"><a class="page-nav-link">Somewhat long abcdef</a></li>
<li class="page-tab"><a class="page-nav-link">Somewhat long abcdefghi</a></li>
<li class="page-tab"><a class="page-nav-link">Somewhat long abcdefghijkl</a></li>
<li class="page-tab"><a class="page-nav-link">Very long element abcdefghijklmno</a></li>
</ul>
</nav>
<div class="right-panel">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam pellentesque nisl vitae nulla dignissim, at rutrum nunc interdum. Mauris et facilisis orci. Phasellus ac libero id nisl malesuada ultricies. Aenean vitae cursus velit. Nulla sit amet leo eu enim scelerisque volutpat. Vivamus gravida felis et pulvinar mollis. Sed bibendum consectetur nisi, sit amet tincidunt enim interdum a. Duis sed gravida felis. Fusce mauris est, bibendum a neque et, fringilla placerat magna. Vestibulum pellentesque massa quis bibendum dapibus. Praesent pharetra ipsum id libero dapibus rutrum. Quisque accumsan dictum lacinia.
Mauris ut mi nec orci accumsan consequat. Donec blandit augue eget nulla fermentum, quis porttitor lacus feugiat. Proin vehicula dolor id lorem egestas elementum. Nullam vitae rutrum tortor. Proin varius adipiscing nibh. Vivamus ultrices nibh nec varius bibendum. Integer quis nisi sed metus adipiscing sagittis. Curabitur congue, nisi nec pretium suscipit, mi leo posuere dui, pellentesque dapibus ligula urna a ligula. Quisque mauris nisl, interdum eu est in, elementum cursus arcu. Sed suscipit vel erat vitae viverra. Mauris neque ipsum, bibendum eget hendrerit ac, vulputate in eros. Ut tincidunt, urna ac auctor porttitor, mauris purus varius erat, ut pellentesque urna turpis non nibh. Aenean sed neque a velit tristique tristique.
Praesent id cursus libero. Vestibulum pulvinar feugiat neque pretium suscipit. Nam vitae magna eget elit aliquam accumsan. Duis et eleifend enim. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec nunc est, commodo quis pretium vitae, lacinia ac lectus. Cras mi tellus, suscipit non leo eget, auctor feugiat mauris. Praesent vitae vehicula ipsum, nec ultrices arcu. Proin mollis leo sit amet erat scelerisque feugiat. Nullam eget varius ante. Praesent a laoreet libero.
Suspendisse ut eros et odio rhoncus malesuada. Integer laoreet, leo at fringilla volutpat, augue lorem tincidunt augue, sit amet feugiat erat neque in est. Phasellus imperdiet, nisi vel faucibus auctor, sapien orci mollis est, tincidunt vehicula nisi nunc sit amet purus. Sed cursus ipsum nisi, id elementum leo feugiat in. Phasellus vitae arcu ac ligula pellentesque malesuada. Maecenas vulputate nunc et consequat pellentesque. Nulla semper quam a orci eleifend, vel gravida est euismod. Nam fermentum, nisi ullamcorper congue convallis, turpis purus lacinia ligula, ac posuere urna est non felis. Cras lobortis ligula neque, vel fermentum magna facilisis sit amet. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Quisque a quam nec sem vestibulum dapibus quis non lacus. Integer eget ligula eu turpis pretium iaculis. Cras gravida ligula in mauris bibendum placerat. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Proin ac tristique risus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque diam nisi, sodales vel nisi a, sollicitudin commodo ipsum. Fusce elementum nisi ac semper dignissim. Etiam nec felis dapibus lacus faucibus vehicula eget eu odio. Sed id risus tellus. Curabitur in luctus orci.
</p>
</div>
</div>

CSS:

* {
margin: 0;
padding: 0;
font-family: "Helvetica Neue",Helvetica,sans-serif;
line-height: 20px;
}

.main-panel {
min-width: 700px;
width: 100%;
min-height: 500px;
max-height: 700px;
display: -webkit-flex;
display: flex;
background: rgba(64, 64, 64, 0.4);
}

.left-panel {
border-width: 2px 0 0 0 0;
background: rgba(245, 245, 245, 0.4); /* fallback color if gradients are not supported */
background: -webkit-linear-gradient(top, rgba(245, 245, 245, 0.4), rgba(221, 221, 221, 0.4)); /* For Chrome and Safari */
background: -moz-linear-gradient(top, rgba(245, 245, 245, 0.4), rgba(221, 221, 221, 0.4)); /* For old Fx (3.6 to 15) */
background: -ms-linear-gradient(top, rgba(245, 245, 245, 0.4), rgba(221, 221, 221, 0.4)); /* For pre-releases of IE 10*/
background: -o-linear-gradient(top, rgba(245, 245, 245, 0.4), rgba(221, 221, 221, 0.4)); /* For old Opera (11.1 to 12.0) */
background: linear-gradient(to center bottom, rgba(245, 245, 245, 0.4), rgba(221, 221, 221, 0.4)); /* Standard syntax; must be last */
box-shadow: 0px 0px 7px white inset;
-moz-box-shadow: 0px 0px 7px white inset;
-webkit-box-shadow: 0px 0px 7px white inset;

overflow: hidden;
min-width: 180px;
max-width: 280px;
padding: 5px 0 5px 7px;
}

.right-panel {
background-color: white;
overflow: hidden;
padding: 5px 5px 5px 5px;
-webkit-flex: 1;
flex: 1;
flex-basis: auto;
}

.left-panel > .page-nav > .page-tab {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
border: solid 1px rgba(245, 245, 245, 0.4);
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.3) inset;
border-top-width: 1px;
border-right-width: 0;
padding: 0 5px;
margin-bottom: 0px;
cursor: pointer;
height: 25px;
text-transform: uppercase;
font-weight: bold;
font-size: 11px;
list-style: none;
text-align: center;
}

.left-panel > .page-nav > .page-tab.active {
box-shadow: 2px 2px 2px rgba(245, 245, 245, 0.6) inset;
background: rgba(245, 245, 245, 0.4); /* fallback color if gradients are not supported */
background: -webkit-linear-gradient(top, rgba(68, 68, 68, 0.4), rgba(59, 59, 59, 0.4)); /* For Chrome and Safari */
background: -moz-linear-gradient(top, rgba(68, 68, 68, 0.4), rgba(59, 59, 59, 0.4)); /* For old Fx (3.6 to 15) */
background: -ms-linear-gradient(top, rgba(68, 68, 68, 0.4), rgba(59, 59, 59, 0.4)); /* For pre-releases of IE 10*/
background: -o-linear-gradient(top, rgba(68, 68, 68, 0.4), rgba(59, 59, 59, 0.4)); /* For old Opera (11.1 to 12.0) */
background: linear-gradient(to center bottom, rgba(68, 68, 68, 0.4), rgba(59, 59, 59, 0.4)); /* Standard syntax; must be last */
}

.left-panel > .page-nav > .page-tab.active:after {
content: " ";
height: 0;
width: 0;

border-top: 7px solid transparent;
border-bottom: 7px solid transparent;
border-right: 7px solid white;
margin-right: -5px;
display: inline-block;
float: right;
}

.left-panel > .page-nav > .page-tab:hover {
box-shadow: 2px 2px 2px rgba(245, 245, 245, 0.6) inset;
}

JSFiddle 链接:http://jsfiddle.net/LvG2C/

最佳答案

像这样尝试:

.left-panel > .page-nav > .page-tab {
position: relative;
}

.left-panel > .page-nav > .page-tab.active:after {
width: 0px;
height: 0px;
border-style: solid;
border-width: 7px 7px 7px 0;
border-color: transparent #ffffff transparent transparent;
position: absolute;
top: 50%;
right: 0;
margin-top: -7px;
content: "";
}

高度三 Angular 形 14px,对于垂直对齐:14/2 = 7,对于这个 margin-top:-7px;

Example

顺便说一句,generator triangles

关于html - CSS 箭头在 div 的右侧垂直居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17138785/

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