html - 一行中可以并排放置 2 张背景图片吗?

标签 html css image twitter-bootstrap-3 background

我试图在 Bootstrap 3 的同一行上并排放置 2 个背景图像(每个都在它自己的容器中)。2 footer div backgrounds

无论我做什么,绿色的 div 都会出现在下一行。我正在尝试将这两 block 并排用作页脚,每 block 都包含文本和社交媒体 Logo ,随着屏幕变小,它们将保留在自己的 div 中。

如果我不能使用彼此相邻的 2 个背景图片,有人可以提供代码来对 .我认为我不能使用 clip-path,因为并非所有浏览器都支持它们。

最佳答案

  • 为 div(图像容器)和图像提供 display: inline-block;display:left;。最终将 paddingmargin 设置为 0
  • 对于图像容器,您也可以使用 span 而不是 div

祝你好运。

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes" />
        <meta charset="UTF-8" />
        <!-- The above 3 meta tags must come first in the head -->

        <title>Demo</title>

        <!-- CSS resources -->

        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css" rel="stylesheet" />

        <!-- JS resources -->

        <!-- jQuery -->
        <script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

        <!-- Bootstrap -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>

        <style type="text/css">
            .page-content {
                padding: 30px;
                text-align: center;
                background-color: yellow;
            }

            footer {
                text-align: center;
                position: relative;
                background-color: blue;
            }

            .outer-container {
                margin-left: auto;
                margin-right: auto;
                display: inline-block;
                border: 10px solid blue;
            }

            .img-container,
            .img-container img {
                margin: 0;
                padding: 0;
                display: inline-block;
                float: left;
            }
        </style>
    </head>
    <body>

        <section class="page-content">
            This is the page content
        </section>

        <footer>
            <div class="outer-container">
                <div class="img-container">
                    <img src="left.png" alt="Left image" />
                </div>
                <div class="img-container">
                    <img src="right.png" alt="Right image" />
                </div>
            </div>
        </footer>

    </body>
</html>

关于html - 一行中可以并排放置 2 张背景图片吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48236331/

相关文章:

javascript - 动态创建html时如何实现分层标题组织?

html - 确定用户的时区

当鼠标悬停在一个图像上时,jquery 或 CSS 会使其余图像变暗

html - 在 html 文档中,使用高度和宽度标签调整图像大小是一种不好的做法吗?

java - 我应该为 Graphics.drawImage() 函数的 ImageObserver 参数使用 null 吗?

html - 图像未从 CSS 继承

android - android如何使用蓝牙打印机打印WebView内容

css - svg加css动画

javascript - 为什么我的 JS 代码只运行一次?

html - 如何根据包含的div的大小设置背景图片的大小?