【问题标题】:How can I horizontally align these divs in the centre?如何在中心水平对齐这些 div?
【发布时间】:2022-01-20 06:14:42
【问题描述】:

我尝试使用 Twitter Bootstrap 在我的网站页面中心水平和垂直对齐一些项目,以便它具有移动响应性,但不会水平对齐。

我确定它与图像、ul 列表和 p 标签的组合有关。接下来我可以尝试什么?

HTML:

<div class="row-fluid" id="trial">
    <div class="span4">

        <div style="display:inline-block;">
            <div align="center">
            <img src="http://mysite/wp-content/uploads/2016/05/socialmediatoo.png" width="150" height="auto"/>
            </div>
        </div>
        <div style="display:inline-block;">
            <div align="center">
            <ul class="testli">
                <li><a target="_blank" href="http://mysite/information">About Us</a></li>
                <li><a target="_blank" href="http://mysite/information">FAQ's</a></li>
                <li><a target="_blank" href="http://mysite/information">Contact Us</a></li>
                <li><a target="_blank" href="http://mysite/information">Work With Us</a></li>
                <li><a target="_blank" href="http://mysite/information">Terms and Conditions</a></li>
                <li><a target="_blank" href="http://mysite/information">Privacy Policy<br></a></li>
                <li><a target="_blank" href="https://www.drinkaware.co.uk/"><div id="drinkaware"></div></a></li>
            </ul>
        </div>
        </div>
        <div style="display:inline-block;">
            <div align="center">
            <div id="test-div">
                <p>become a driver</p>
                <p>As an ever evolving new start up we'll constantly be looking for friendly drivers to join the team, so If you'd be interested in  join our team click the button below to see the available opportunities we have available.</p>
                <input type="submit" id="test-btn" value="FIND OUT MORE" onclick="location='http://mysite/join-the-team/'"/>
            </div>
            </div>
        </div>
        <div style="display:inline-block;">
            <div align="center">
            <img src="http://mysite/wp-content/uploads/2016/04/open247.png" width="150" height="auto"/>
            </div>
        </div>


    </div>
</div>

CSS:

#social-logo {
    width: 180px;
    height: auto;
    background-image: url('http://mysite/wp-content/uploads/2016/05/DEVO_socialmediatoo.png');
    background-size: 140px auto;
    background-repeat: no-repeat;
    background-position: center;
    background-color: transparent;
  display: inline-block;
}
#trial {
    height: auto;
    width: 100%;
    background-color: pink;
}
#drinkaware {
    width: 156px;
    height: 50px;
  display:list-item;
    background-image: url('http://mysite/wp-content/uploads/2016/04/DrinkawareRed.png');
    background-size: 150px auto;
    background-repeat: no-repeat;
    background-position: center;
    background-color: transparent;
    vertical-align: top;
    list-style-type: none !important;
}
#open24 {
    display: inline-block;
    width: 200px;
    height: auto;
    background-image: url('http://mysite/wp-content/uploads/2016/04/open247.png');
    background-size: 250px auto;
    background-repeat: no-repeat;
    background-position: center;
    background-color: transparent;
}

【问题讨论】:

  • display:flexbox 可能在这里有用。
  • 在第一个最外面的 div 上?
  • @Maharkus display: flex
  • 有机会演示一下吗?
  • 一般将display:flex; align-items: center; justify-content: center;放在父元素上,子元素水平和垂直居中。我不知道是否有一些 CSS 干扰它,但值得一试。

标签: javascript html css twitter-bootstrap


【解决方案1】:

您可以使用 flexbox 并添加 justify-content 属性规则。我给你写了一个binhere

.block {
  display: inline-flex;
  justify-content: center;
  flex-direction: column;
}

.flex {
  display: flex;
}

【讨论】:

  • 如果您在答案中包含一些代码而不仅仅是链接,这将更有帮助。
猜你喜欢
  • 1970-01-01
  • 2013-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
  • 2012-03-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多