【问题标题】:how to horizontally align nested divs? possibly responsively?如何水平对齐嵌套的div?可能有反应?
【发布时间】:2013-08-02 22:54:05
【问题描述】:

我有一个名为“content1”的容器 div,理想情况下我希望包含三个 div,每个 div 包含一个图像和一些文本。

我希望这三个嵌套的 div 彼此相邻,除非浏览器窗口变得太小,在这种情况下,我希望它们垂直堆叠在一起。现在 div 只是彼此叠放....

谁能指点我正确的方向?

我目前(显然不正确)的设置是:

HTML

> <div id="content1">
    <div id="item1"><img src="EXAMPLE URL"><br>example text example text example text</div>
    <div id="item2"><img src="EXAMPLE URL"><br>example text example text example text</div>
    <div id="item3"><img src="EXAMPLE URL"><br>example text example text example text</div>
</div>

CSS

#content1 {
    padding: 20px;
    margin-top: 17px;
    margin-bottom: 17px;
    margin-left:auto;
    margin-right:auto;
    width:70%;
    height: auto;
    background-color: rgba(255, 255, 255, 0.25);
    border-bottom-right-radius: 50px 50px;
    border-bottom-left-radius: 50px 50px;
    border-top-left-radius: 50px 50px;
    border-top-right-radius: 50px 50px; }

#item1 {
    position: relative;
    margin-left:auto;
    margin-right:auto;
    color: white;
    font-family:'Oswald';
    text-align: center;
    font-size: 18px;
    width: 80&;
    max-width: 60%;
    padding: 2px;
  }
  #item1 img {
    position: relative;
    margin-left:auto;
    margin-right:auto;
    max-width: 100%;
    height: auto;
  }

如果有人知道如何让这三个 div 并排放置并可能在嵌套的“content1”div 中做出响应,我将非常感激。

【问题讨论】:

标签: css html css-position


【解决方案1】:

试试这个:

#content1 > div{
float:left;
}

【讨论】:

    【解决方案2】:

    http://learnlayout.com/

    看看这个。这是我遇到过的最全面的基本 CSS 布局指南。你必须在那里得到你的答案。

    【讨论】:

    • 问题没有答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 2017-11-05
    • 1970-01-01
    • 2021-05-24
    • 2020-10-17
    • 2010-09-18
    相关资源
    最近更新 更多