首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在一行中放置3个框

在一行中放置3个框
EN

Stack Overflow用户
提问于 2015-05-14 16:18:02
回答 2查看 54关注 0票数 0

我正在从数据库中获取数据图像,并希望在单行中放置最多3个图像,这些图像也有悬停效果,这是工作良好

我面临的问题是,如果我使用这段代码来显示静态图像,那么它工作得很好,但是如果我从数据库中获取数据,那么它就不能正确显示。我想在此表单中显示图像

代码语言:javascript
复制
1st_image  2nd_image  3rd_image   
4th_image  5th_image  6th_image  
7th_image .. and so on

但是我得到了这种形式的图像

代码语言:javascript
复制
1st_image  
2nd_image  
3rd_image   
4th_image  
5th_image  
6th_image

我拥有的代码是

我的首页代码是

代码语言:javascript
复制
<?php
$sql = "SELECT * FROM category";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) 
    {
        while($row = mysqli_fetch_assoc($result)) 
            {
                $catname=$row["catname"];
                $catdesc=$row["catdesc"];
                $catpic=$row["catpic"];
                $id=$row["id"];

?>
                <div id="effect-2" class="effects clearfix">
                    <div class="img">
                        <img src="<? echo $catpic; ?>" alt="">
                            <div class="overlay">
                                <a href="#" class="">content</a>
                                <a class="close-overlay hidden">x</a>
                            </div>
                    </div>
                </div>
            <?}
    }?> 

css页面上的代码是

代码语言:javascript
复制
nav ul {
  list-style-type: none;
  margin: 0 0 30px 0;
  padding: 0;
  text-align: center;
}
nav ul li {
  display: inline-block;
  margin-bottom: 4px;
}
nav ul li a {
  display: block;
  padding: 5px 20px;
  color: #fff;
  background-color: #32c896;
}
nav ul li a:hover {
  color: #fff;
  background-color: #238b68;
}
nav ul li a.active {
  color: #fff;
  background-color: #238b68;
}


.effects {
  padding-left: 15px;
}
.effects .img {
  position: relative;
  float: left;
  margin-bottom: 5px;
  width: 25%;
  overflow: hidden;
}
.effects .img:nth-child(n) {
  margin-right: 5px;
}
.effects .img:first-child {
  margin-left: -15px;
}
.effects .img:last-child {
  margin-right: 0;
}
.effects .img img {
  display: block;
  margin: 0;
  padding: 0;
  max-width: 100%;
  height: auto;
}

.overlay {
  display: block;
  position: absolute;
  z-index: 20;
  background: rgba(0, 0, 0, 0.8);
  overflow: hidden;
  -webkit-transition: all 0.5s;
  -moz-transition: all 0.5s;
  -o-transition: all 0.5s;
  transition: all 0.5s;
}

a.close-overlay {
  display: block;
  position: absolute;
  top: 0;
  right: 0;
  z-index: 100;
  width: 45px;
  height: 45px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  line-height: 45px;
  text-align: center;
  background-color: #000;
  cursor: pointer;
}
a.close-overlay.hidden {
  display: none;
}

a.expand {
  display: block;
  position: absolute;
  z-index: 100;
  width: 60px;
  height: 60px;
  border: solid 5px #fff;
  text-align: center;
  color: #fff;
  line-height: 50px;
  font-weight: 700;
  font-size: 30px;
  -webkit-border-radius: 30px;
  -moz-border-radius: 30px;
  -ms-border-radius: 30px;
  -o-border-radius: 30px;
  border-radius: 30px;
}


#effect-2 .overlay {
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 0;
}
#effect-2 .overlay a.expand {
  left: 0;
  right: 0;
  top: 50%;
  margin: -30px auto 0 auto;
}
#effect-2 .img.hover .overlay {
  height: 100%;
}

有谁能告诉我怎么做吗?

EN

回答 2

Stack Overflow用户

发布于 2015-05-14 17:00:25

您应该在html中使用唯一的in。我建议总是使用类而不是id。你可以在你的CSS中做这样的事情

代码语言:javascript
复制
div[id^="tocolor-"] {
    /* some css rules */
}
div[id^="tocolor-"] .overlay {
    /* some css rules */
}

在html中,您可以使用数据库表id添加一个id,如下所示

代码语言:javascript
复制
<div id="effect-<?php echo $id; ?>" class="effects clearfix">
票数 0
EN

Stack Overflow用户

发布于 2015-05-14 16:22:26

为什么不使用bootstrap并使用col-xs-4 class...which将确保您始终有3列

代码语言:javascript
复制
<div id="effect-2" class="col-xs-4">
    <div class="img">
        <img src="<? echo $catpic; ?>" alt="">
        <div class="overlay"> <a href="#" class="">content</a>
 <a class="close-overlay hidden">x</a>

        </div>
    </div>
</div>  
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30232535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档