html - 如何让圆形菜单(包括悬停+链接功能)完全响应?
问题描述
我试图让一个圆形菜单(包括悬停+链接功能)表现得完全负责。
- 悬停和链接部分基本上工作正常。
- 如果没有悬停部分,圆形菜单的行为是响应式的。
- 但是包含悬停部分时,调整显示/屏幕宽度时菜单会被挤压。
我已经尝试过这种@media
方法,为不同的屏幕宽度设置不同的宽度和高度.ch-grid li
,但这并不是真正的解决方案,只是一种临时的解决方法。
ul,
li {
list-style: none;
margin: 0;
padding: 0;
}
#test1 {
display: -webkit-flex;
display: flex;
text-align: center;
justify-content: space-between;
margin-bottom: 30px;
margin-left: 35px;
margin-right: 35px;
}
#test2 {
width: 15%;
text-align: center;
position: relative;
border-radius: 50%;
overflow: hidden;
background-color: #ff0082;
}
ul li img {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
object-fit: cover;
}
.ch-grid:after,
.ch-item:before {
content: '';
display: table;
}
.ch-grid:after {
clear: both;
}
.ch-grid li {
width: 220px;
height: 90px;
display: inline-block;
}
.ch-item {
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
position: relative;
cursor: default;
box-shadow: inset 0 0 0 16px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.1);
transition: all 0.4s ease-in-out;
}
.ch-info {
position: absolute;
background: rgba(63, 147, 147, 0.8);
width: inherit;
height: inherit;
border-radius: 50%;
overflow: hidden;
opacity: 0;
transition: all 0.4s ease-in-out;
transform: scale(0);
}
.ch-info p {
color: #fff;
padding: 13px 0px;
font-style: normal;
font-size: 9px;
border-top: 1px solid rgba(255, 255, 255, 0.5);
opacity: 0;
transition: all 1s ease-in-out 0.4s;
}
.ch-info p a {
display: block;
color: rgba(255, 255, 255, 0.7);
font-style: normal;
font-weight: 700;
font-size: 140%;
letter-spacing: 1px;
padding-top: 4px;
font-family: 'Open Sans', Arial, sans-serif;
}
.ch-info p a:hover {
color: rgba(255, 242, 34, 0.8);
}
.ch-item:hover {
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 1px 2px rgba(0, 0, 0, 0.1);
}
.ch-item:hover .ch-info {
transform: scale(1);
opacity: 1;
}
.ch-item:hover .ch-info p {
opacity: 1;
}
<ul id="test1" class="ch-grid">
<li id="test2">
<div class="ch-item">
<img src="https://gespreksmakers.nl/images/1_hansie_hansumus.jpg" />
<div class="ch-info">
<p><a href="https://nkbv.nl">Hansie<BR>Hansumus</a></p>
</div>
</div>
</li>
<li id="test2">
<div class="ch-item">
<img src="https://gespreksmakers.nl/images/1_missie_marble.jpg" />
<div class="ch-info">
<p><a href="https://kakivi.de">Missie<BR>Marble</a></p>
</div>
</div>
</li>
<li id="test2">
<div class="ch-item">
<img src="https://gespreksmakers.nl/images/1_piotr_linski.jpg" />
<div class="ch-info">
<p><a href="https://telegraaf.nl">Piotr<BR>Linski</a></p>
</div>
</div>
</li>
<li id="test2">
<div class="ch-item">
<img src="https://gespreksmakers.nl/images/1_red.jpg" />
<div class="ch-info">
<p><a href="https://www.tukhut.nl">Mister<BR>Red</a></p>
</div>
</div>
</li>
<li id="test2">
<div class="ch-item">
<img src="https://gespreksmakers.nl/images/1_green.jpg" />
<div class="ch-info">
<p><a href="https://www.alumnei.nl">Miss<BR>Green</a></p>
</div>
</div>
</li>
<li id="test2">
<div class="ch-item">
<img src="https://gespreksmakers.nl/images/1_blue.jpg" />
<div class="ch-info">
<p><a href="https://www.astronieuws.nl">Mister<BR>Blue</a></p>
</div>
</div>
</li>
</ul>
可以在这里找到显示当前 CSS 和 HTML 代码的小提琴:https ://jsfiddle.net/piotrlinski/b3tL9v4h/8/
任何建议如何解决?
解决方案
尽管我做了很多更改,但您可以在下面查看我的代码。
一些技巧:
ID 在 HTML 文档中必须是唯一的,因此您不应多次使用 ID(例如 #test2)。
此外,最好使用您创建的类来设置文档的样式,而不是使用 ID(例如,#test1、#test2 可以分别替换为 .ch-grid 和 .ch-grid li)。
<style>
ul,
li {
list-style: none;
margin: 0;
padding: 0;
}
.ch-grid {
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
text-align: center;
}
.ch-grid:after,
.ch-item:before {
content: "";
display: table;
}
.ch-grid:after {
clear: both;
flex: auto;
}
.ch-grid li {
flex: 1;
display: inline-block;
min-width: calc(100% / 6);
max-width: calc(100% / 6);
position: relative;
background-color: #ff0082;
overflow: hidden;
border-radius: 50%;
text-align: center;
}
.ch-grid li img {
width: 100%;
height: 100%;
object-fit: cover;
position: relative;
z-index: 10;
}
.ch-item {
position: relative;
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
cursor: default;
box-shadow: inset 0 0 0 16px rgba(255, 255, 255, 0.6),
0 1px 2px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease-in-out;
}
.ch-info {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: -webkit-flex;
display: flex;
flex-direction: column;
justify-content: center;
background: rgba(63, 147, 147, 0.8);
border-radius: 50%;
overflow: hidden;
opacity: 0;
transition: all 0.4s ease-in-out;
transform: scale(0);
z-index: 20;
}
.ch-info p {
color: #fff;
padding: 13px 0px;
font-style: normal;
font-size: 9px;
border-top: 1px solid rgba(255, 255, 255, 0.5);
opacity: 0;
transition: all 1s ease-in-out 0.4s;
}
.ch-info p a {
display: block;
color: rgba(255, 255, 255, 0.7);
font-style: normal;
font-weight: 700;
font-size: 140%;
letter-spacing: 1px;
padding-top: 4px;
font-family: "Open Sans", Arial, sans-serif;
}
.ch-info p a:hover {
color: rgba(255, 242, 34, 0.8);
}
.ch-item:hover {
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1),
0 1px 2px rgba(0, 0, 0, 0.1);
}
.ch-item:hover .ch-info {
transform: scale(1);
opacity: 1;
}
.ch-item:hover .ch-info p {
opacity: 1;
}
@media (max-width: 767px) {
.ch-grid li {
min-width: calc(100% / 3);
max-width: calc(100% / 3);
}
}
</style>
推荐阅读
- apache-kafka - 附加卷时,Kafka connect 找不到可用的代理
- react-native - 获取存储在状态中的数组长度时出错
- python - Python:有没有办法提取和连接多个文本文件系列,同时删除每个文件的前 3 行?
- excel - 在其他工作表和向下填充日期的最后一行下方复制和粘贴动态范围
- markdown - doxygen 抱怨我的 image-in-link 标签
- html - 是否可以在中使用样式属性
tag?</h1> <div id="body"><p>How to use <code>style</code> attribute in <code><title></code> tag? Is it possible?</p> </div> </data> <hr><data id="62063004"> - elasticsearch - 如何理解 x-pack 上“搜索延迟”的弹性搜索性能
- c++ - C ++中具有未知数组大小的指针转换
- reactjs - 一个组件中页面刷新后上下文值为空
- javascript - 在反应中处理不确定的复选框