我需要最好的方法来处理五个圆圈,每个圆圈都可以点击页面,这部分很容易,但圆圈也处理响应。这里列出的是我想要的桌面外观的代码,但是当它下移到移动设备时我希望它是左右,所以顶部图像,左边,下一个图像是正确的,然后是从左到右,依此类推。
http://codepen.io/anon/pen/GJBOwP
.hero-intro1 {
margin-top: 120px;
text-align: center;
}
.hero-intro1 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
.hero-intro2 {
margin-top: -120px;
text-align: center;
}
.hero-intro2 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
@media (max-width: 1200px) {
.hero-intro1 {
margin-top: 120px;
text-align: center;
}
.hero-intro1 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
.hero-intro2 {
margin-top: 0;
text-align: center;
}
.hero-intro2 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
}
@media (max-width: 991px) {
.hero-intro1 {
margin-top: 120px;
text-align: center;
}
.hero-intro1 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
.hero-intro2 {
margin-top: 0;
text-align: center;
}
.hero-intro2 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
img.imgright {
/*margin-top: 50px;*/
margin-left: 0px;
margin-right: 0px;
position: absolute;
right: 10px;
}
img.imgleft {
/*margin-top: 50px;*/
margin-left: 0px;
margin-right: 0px;
position: absolute;
left: 10px;
}
img.imgmiddle {
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
top: 150px;
}
.hero-intro2 ul li {
margin-top: 250px;
margin-bottom: 50px;
}
}
@media (max-width: 768px) {
.hero-intro1 {
margin-top: 120px;
text-align: center;
}
.hero-intro1 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
.hero-intro2 {
margin-top: 0;
text-align: center;
}
.hero-intro2 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
img.imgright {
/*margin-top: 50px;*/
margin-left: 0px;
margin-right: 0px;
position: relative;
right: 10px;
}
img.imgleft {
/*margin-top: 50px;*/
margin-left: 0px;
margin-right: 0px;
position: relative;
left: 10px;
}
/* img.imgmiddle {
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
top: 150px;
}*/
.hero-intro2 ul li {
/*margin-top: 250px;*/
/*margin-bottom: 50px;*/
}
}
.list-inline>li {
display: inline-block;
padding-right: 5px;
padding-left: 5px;
}

<div class="hero-intro1">
<ul class="list-inline intro-social-buttons">
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
</ul>
</div>
<div class="hero-intro2">
<ul class="list-inline intro-social-buttons">
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
</ul>
</div>
&#13;
答案 0 :(得分:0)
我使用css flex属性以更加简单灵活的方式重写了所有代码。
首先,删除两个hero-容器,不需要伪类:nth-child():
<ul class="list-inline intro-social-buttons">
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
</ul>
然后是css:
.list-inline {
display: flex;
flex-direction: row;
}
.list-inline > li {
display: inline-block;
padding-right: 5px;
padding-left: 5px;
}
.list-inline > li:nth-child(even) {
/* we use :nth-child in order to avoid ugly use of 2 different containers */
margin-top: 120px;
}
/* Following is for smartphones only */
@media (max-width: 991px) {
.list-inline {
/* here we revert the behaviour of our elements: from line to column */
flex-direction: column;
}
.list-inline > li:nth-child(even) {
margin-top: 0;
margin-left: 120px;
}
}
使用此模式,您将能够轻松更改和调整元素的模板。
答案 1 :(得分:0)
我在nth-child
中使用了max-width = 768px
个选择器来左右浮动它们。摆脱各种屏幕尺寸的超额利润。
.hero-intro1 {
margin-top: 120px;
text-align: center;
}
.hero-intro1 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
.hero-intro2 {
margin-top: -120px;
text-align: center;
}
.hero-intro2 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
@media (max-width: 768px) {
.hero-intro1 {
text-align: center;
}
.hero-intro1 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
.hero-intro2 {
margin-top: 0;
text-align: center;
}
.hero-intro2 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
img.imgright {
margin-top: 0;
margin-left: 0px;
margin-right: 0px;
position: relative;
right: 10px;
}
img.imgleft {
margin-top: 0;
margin-left: 0px;
margin-right: 0px;
position: relative;
left: 10px;
}
.hero-intro2 ul li {
margin-top: 0;
margin-bottom: 0;
}
.hero-intro1 ul li:nth-child(1) {
float: left;
}
.hero-intro1 ul li:nth-child(2) {
float: right;
}
.hero-intro1 ul li:nth-child(3) {
float: left;
}
.hero-intro2 ul li:nth-child(1) {
float: right;
}
.hero-intro2 ul li:nth-child(2) {
float: left;
}
}
@media (max-width: 991px) {
.hero-intro1 {
margin-top: 120px;
text-align: center;
}
.hero-intro1 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
.hero-intro2 {
margin-top: 0;
text-align: center;
}
.hero-intro2 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
img.imgright {
margin-left: 0px;
margin-right: 0px;
position: absolute;
right: 10px;
}
img.imgleft {
margin-left: 0px;
margin-right: 0px;
position: absolute;
left: 10px;
}
img.imgmiddle {
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
top: 150px;
}
.hero-intro2 ul li {
margin-top: 250px;
margin-bottom: 50px;
}
}
@media (max-width: 1200px) {
.hero-intro1 {
margin-top: 120px;
text-align: center;
}
.hero-intro2 ul li {
margin: 0;
}
.hero-intro1 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
.hero-intro2 {
margin-top: 0;
text-align: center;
}
.hero-intro2 img {
max-width: 200px;
margin-left: 80px;
margin-right: 80px;
}
}
.list-inline>li {
display: inline-block;
padding-right: 5px;
padding-left: 5px;
}
&#13;
<div class="hero-intro1">
<ul class="list-inline intro-social-buttons">
<li>
<img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png">
</li>
<li>
<img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png">
</li>
<li>
<img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png">
</li>
</ul>
</div>
<div class="hero-intro2">
<ul class="list-inline intro-social-buttons">
<li>
<img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png">
</li>
<li>
<img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png">
</li>
</ul>
</div>
&#13;
答案 2 :(得分:0)
在不同li
列表中包含ul
个元素时,您无法实现这一目标。你应该将它们放在一个并使用li
伪选择器引用:nth-child
元素 - 这样你就可以定位偶数元素(每秒,你想要的)。
HTML:
<ul class="list-inline intro-social-buttons">
<li class="item"><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li class="item"><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li class="item"><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li class="item"><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
<li class="item"><img src="http://staging.eminetwork.com/relazenships/wp-content/themes/RELAZENSHIPS/img/corporate-cooperation.png"></li>
</ul>
CSS:
.item {
display: inline-block;
}
.item:nth-child(even) img {
margin: 0 -25px;
position: relative;
top: 120px;
}
/* Following is for smartphones only */
@media (max-width: 1100px) {
.list-inline {
display: flex;
flex-direction: column;
}
.list-inline > li:nth-child(even) {
margin: -25px 0;
}
.item:nth-child(even) img {
position: relative;
margin: 0;
left: 120px;
top: 0;
}
}