html - 如何强制2个div并排保持

标签 html css

我的网站左侧有一张图片,它会根据浏览器大小进行缩放。右边是一些文本。

我遇到的问题是,当浏览器变小时,右侧的 div 会下降到左侧图像的下方,只有当图像现在是屏幕上的唯一元素时,它才会开始缩小

https://jsfiddle.net/0gyhrve2/

我想要实现的是,当您更改页面的宽度时,2 个 div 将并排保留,但左侧的图像会缩小,而不是文本落在下面。

我的努力

<div class="outer">
    <div class="img">Words</div>
    <div class="other">More words</div>
</div>

CSS

.img {
float: left;
        background-image: url("http://bootstrapbay.com/blog/wp-content/uploads/2014/05/yellow-taxi_vvvjao.png");
        background-repeat: no-repeat;
        background-size: 100%;
        width: 100%;
        height: 349px;
        font-weight: bold;
        text-shadow: 1px 1px 2px #000;
        max-width: 300px;
}

.other{}

最佳答案

这是你想要的吗:https://jsfiddle.net/0gyhrve2/3/

CSS:

.img {
        background-image: url("http://bootstrapbay.com/blog/wp-content/uploads/2014/05/yellow-taxi_vvvjao.png");
        background-repeat: no-repeat;
        background-size: 100%;
        width: 100%;
        height: 349px;
        font-weight: bold;
        text-shadow: 1px 1px 2px #000;
        max-width: 300px;
}

.imgContainer {
    float: left;
    width: 75%;
}

.other {
    float: left;
    width: 25%;
}

HTML:

<div class="outer">
    <div class="imgContainer"><div class="img">Words</div></div>
    <div class="other">More words</div>
</div>

关于html - 如何强制2个div并排保持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33451494/

相关文章:

jquery - 显示 div 时出现部分边框

css - 必应 map 加载不顺畅,我正在使用 Bootstrap 3

javascript - CodeMirror CSS 只允许在 class/id 内编辑

html - 悬停时,菜单链接会向左移动一点

javascript - 如何判断元素在导航前是否在屏幕上?

javascript - 如何在没有 jQuery 的情况下获取一组已检查的 radio 输入?

javascript - 更改 ajax 以请求用要嵌入到 html 页面本身的 html 内容填充 div

php - 在 HTML 表中显示 SQL 查询

html - 标语和背景图片响应式附加

html - 在 Bootstrap 行中将 div 对齐到底部