javascript - 如何将图像 div 放在文本 div 旁边?

标签 javascript jquery html css

我正在尝试用 HTML 制作 GTA 在线提示加载屏幕。

这就是我想要做的 - http://prntscr.com/6n7txe 这就是我的 - http://prntscr.com/6n7w92

我现在关注的问题是让 2 个 dive 彼此相邻并具有正确的宽度和高度。

HTML:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>GTA ONLINE</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div>

<div class="column">
    <div class="text">
        <p class="top">GTA Online</p>
        <p class="middle">First Person Mode</p>
        <p class="bottom">Lorem ipsum dolor sit amet, consectetu adipiscing elit. Maecenas sodales, velit sed dictum fermentum, ligula nunc  sodales magna, at convallis. </p>
    </div>
    <div class="picture">
        <img src="pics/Trevor.jpg"
    </div>
</div>

<script src="script.js"></script>
</body>
</html>

CSS:

body{
    background-image: url("../pics/background_1.jpg");
    background-size: cover;
}

.column {
    white-space: nowrap;
}

.column .picture img {
    width: 25%;
    height: 25%;
    vertical-align: middle;
    float: right;
}

.column .text {
    background:rgba(0,0,0,1);
    display: inline-block;
    vertical-align: top;
    float: left;
    width:50%;
}

.column .text p{
    color:rgba(255,255,255,1);
    width:50%;
}

最佳答案

省略 float:rightfloat:left 但将 display:inline-block 添加到两个 div。

    body{
        background-image: url("../pics/background_1.jpg");
        background-size: cover;
    }

    .column {
        white-space: nowrap;
    }

    .column .picture img {
        width: 25%;
        height: 25%;
        vertical-align: middle;
        vertical-align: middle;
        float: right;

    }

   /* new style start*/
    .column .picture {
    display:inline-block;
    }
   /* also set width to this div 
      otherwise it takes 100% and won't 
      stay inline with other elements.
      new style end */ 

    .column .text {
        background:rgba(0,0,0,1);
        display: inline-block;
        vertical-align: top;
        width:50%;
    }

    .column .text p{
        color:rgba(255,255,255,1);
        width:50%;
    }

关于javascript - 如何将图像 div 放在文本 div 旁边?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29345635/

相关文章:

javascript - 根据类别添加空格以保存文本文件

javascript - 单选按钮/复选框未使用 AJAX 输入 MySQL DB

javascript - 如何在div中找到具有相同类的最后两个元素并为它们分配一个类?

html - 页眉和页脚之间的 100% 高度 div

javascript - 在行按钮单击上生成事件并添加图标?如何

javascript - 在单引号字符串中转义 onClick 参数周围的双引号

javascript - 如何将两个搜索代码合并为一个

javascript - 如何在自定义所见即所得编辑器中添加 'TAB' 功能?

javascript - d3 : Make a static directed graph

javascript - 更改显示中居中按钮的动画方向(持续时间)