I have the following html where I want the left div to show an image about 20% and the second div to contain text and take up the rest of the width. The problem I have is the second div gets pushed to the button when the image is added:

我有以下html,我希望左侧div显示约20%的图像,第二个div包含文本并占据宽度的其余部分。我遇到的问题是在添加图像时第二个div被推到按钮:

<div style="display:table; width: 100%; border: solid 1px blue;">

    <div style="display: table-cell; width: 20%;  max-height: 100%; border: solid 1px green; ">
        <img src="http://lorempixel.com/400/200/" style=" width: 100%; height: 100%;  border: 0;" />            
    </div>
    <div style="dislay: table-cell; border: solid 1px red; vertical-align: top; top: 0; left: 0; ">
        This is the area of the description
    </div>
</div>

This example as you can see pushes the text to the bottom. But if I remove the image then all is well:

您可以看到此示例将文本推送到底部。但如果我删除图像,那么一切都很好:

<div style="display:table; width: 100%; border: solid 1px blue;">

    <div style="display: table-cell; width: 20%;  max-height: 100%; border: solid 1px green; ">
        No Image        
    </div>
    <div style="dislay: table-cell; border: solid 1px red; vertical-align: top; top: 0; left: 0; ">
        This is the area of the description
    </div>
</div>     

If I float the image to the left, it behaves properly but the table is not taking the whole width of the browser now

如果我将图像浮动到左侧,它的行为正常,但表格现在不占用浏览器的整个宽度

<div style="display:table; border: solid 1px blue;">

    <div style="display: table-cell; width: 20%;  max-height: 100%; border: solid 1px green; float: left; ">
        <img src="http://lorempixel.com/400/200/" style=" width: 100%; height: 100%;  border: 0;" />            
    </div>
    <div style="dislay: table-cell; border: solid 1px red; vertical-align: top; top: 0; left: 0; ">
        This is the area of the description
    </div>
</div>  

Here is my demo

这是我的演示

I've tried different things but nothing seems to work. So if anyone can give me any tips, it would be appreciated.

我尝试过不同的东西但似乎没什么用。所以如果有人能给我任何提示,我们将不胜感激。

1 个解决方案

#1


1

You forget to add width:100% on the bottom div.

你忘记在底部div添加宽度:100%。

See this JSFiddle.

看到这个JSFiddle。

It should be like this:

它应该是这样的:

<div style="display:table; width: 100%; border: solid 1px blue;">

    <div style="display: table-cell; width: 20%;  max-height: 100%; border: solid 1px green; float: left; ">
            <img src="http://lorempixel.com/400/200/" style=" width: 100%; height: 100%;  border: 0;" />            
    </div>
    <div style="dislay: table-cell; border: solid 1px red; vertical-align: top; top: 0; left: 0; ">
        This is the area of the description
    </div>
</div>  

更多相关文章

  1. 如何在离子框架中显示图像标题?
  2. 两个并列的div,一个确定宽度一个自动调整
  3. 如何让我的固定宽度移动网站始终显示“完全放大”?
  4. CSS3列 - 添加第二个元素后的额外宽度
  5. 如何使用“left:100%”CSS规则保留DIV宽度
  6. 将图像从本地上传到tinyMCE
  7. 使三个标签填充容器的宽度
  8. 嵌入的图像在签名中不显示。
  9. 我似乎无法正确对齐这些图像

随机推荐

  1. ubuntu添加android真机调试
  2. android简陋的开发工具
  3. Android中的MVC
  4. Android Activity从创建到显示流程
  5. Android 如何破解兼容性困局
  6. 学个明白--Android世界的坐标系
  7. Android(安卓)OKHttp系列2-RetryAndFollo
  8. 关于greenDao函数报错
  9. Android—自制Android闹钟3步即可!(2020-6
  10. android 获取实时麦克风声音大小