首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将P元素保留在Div中

将P元素保留在Div中
EN

Stack Overflow用户
提问于 2017-08-25 01:46:26
回答 1查看 655关注 0票数 1

我想让这个div具有响应性,并始终将文本放在它的中心。到目前为止,它在移动设备上看起来很好,因为我在它上面添加了媒体查询,但在桌面上,我的.info-p-div中的p元素放在下面的div中,看起来很糟糕。这些div在页面上是并排的。我会张贴我的HTML和CSS代码与这一部分的页面,这样你就可以明白我的意思。

HTML

代码语言:javascript
复制
<div class="info">
<div class="info-img-div">
<img src="images/owner.jpg" />
<p><font color="#F5F5F5">Text here</font></p>
</div>
<div class="info-p-div">
<p><font color="#F5F5F5">Text here</font></p>
</div>
</div>
<div class="parallax-3"></div>

CSS

代码语言:javascript
复制
.info   {
    text-align: center;
    min-height: 250px;
    width: 100%;
    background-color: #000;
}

.info-img-div   {
    position: left;
    width: 35%;
    border-right-style: solid;
    border-color: #F5F5F5;
}

.info-img-div img {
    border-radius: 50%;
    height: 25%;
    width: 25%;
    min-height: 100px;
    min-width: 100px;
    margin-top: 20px;
}

.info-p-div {
    height: 25%;
    width: 50%;
    max-width: 65%;
    text-align: center;
    position: relative;
    float: right;
    font-size: 12px;
    word-wrap: break-word;
    vertical-align: middle;
}

.parallax-3 {
    background-image: url("images/background3.jpg");
    height: 400px;
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

@media only screen and (max-width: 600px)   {
    .info   {
        text-align: center;
        float: none;
        height: 50%;
    }
    .info-img-div   {
        float: none;
        border-right-style: none;
        position: relative;
        width: 100%;
    }
    .info-p-div {
        float: none;
        text-align: center;
        width: 100%;
        max-width: 100%;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-25 02:29:07

我认为你正在寻找下面的解决方案。

我发布了一个工作示例。

代码语言:javascript
复制
.box {
  display: flex;
  justify-content: center;
  flex-direction: row;
  align-items: center;
  width: 100%;
  height: 300px;
  background: tomato;
}

.box p {
  flex: 1 0 0;
  text-align: center;
}

@media screen and (max-width:600px) {
  .box {
    flex-direction: column;
  }
  .box p {
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
代码语言:javascript
复制
<div class="box">
  <p>One</p>
  <p>Two</p>
</div>

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

https://stackoverflow.com/questions/45867971

复制
相关文章

相似问题

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