html - 如何在一行div中排列2个div

标签 html css

我有一个设计,将在另一个更大的 div 内的一行中的描述文本(和链接)旁边排列一张食谱图片。 (名为 col2)现在图像在描述的下方而不是在它的右侧,如果我想要它的话。谢谢。

 .col2{width:60%;
         background-color: #FFD6AD; 
         border-radius:25px
         color:#993D00;
         padding: 10px;}    

            font-size: 18px;}   

.col2 a {text-decoration:none;
            color: #993D00;
            font-weight: bold;
            font-size:20px;}        

.col2 p { max-width:500px;}

.thumb {max-width: 400px;}          

.recipe {max-width: 60%;

            display: -moz-inline-stack;
            display: inline-block;}     

使用 HTML

<div class="col2">  
<div "info"> Leckeres essen für wehnig Geld. Es gibt viele Gerichte die
ziemlich günstig sind und trozdem schmecken. </div> 

<div class="recipe"> 
    <div>
        <a href="3bohnen.html"> Chillie aus getrockneten Bohnen </a> 
            <p>Chillie sin carne, oder vegitarisches Chillie .....) </p>
    </div>
    <div class="thumb"> <img src="img/sm-chilly.jpg" alt="chilli sin carne">
        </div>
</div>

最佳答案

一般的解决方案是将图像向右浮动,并使用 % 限制其宽度。 Online Demo .

<div class="col2">
    <div class="thumb">
        <img src="img/sm-chilly.jpg" alt="chilli sin carne">
    </div>
    <div "info">Leckeres essen für wehnig Geld. Es gibt viele Gerichte die ziemlich günstig sind und trozdem schmecken.</div>
    <div class="recipe">
        <div> <a href="3bohnen.html"> Chillie aus getrockneten Bohnen </a> 
            <p>Chillie sin carne, oder vegitarisches Chillie .....)</p>
        </div>
    </div>
    <div class="clear"></div>
</div>

使用 CSS:

 .col2 {
     width:60%;
     background-color: #FFD6AD;
     border-radius:25px color:#993D00;
     padding: 10px;
 }
 font-size: 18px;
}
.col2 a {
    text-decoration:none;
    color: #993D00;
    font-weight: bold;
    font-size:20px;
}
.col2 p {
    max-width:500px;
}
.thumb {
    float: right;
    max-width: 40%;
}
.thumb img {
    max-width: 100%;
}
.recipe {
    max-width: 60%;
}
.clear {
    clear: both;
}

关于html - 如何在一行div中排列2个div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33267090/

相关文章:

javascript - 如何向音乐视频网站添加下载按钮

html - 如果内容太长,用省略号水平滚动

jquery - 侧边栏 block 随机改变宽度

html - 如何在标题标签内定位跨度?

html - 如何隐藏属于div但显示在另一个div上的内容?

css - 如何使用CSS隐藏youtube iframe

javascript - 在 html (jquery) 中动画化文本的一部分

html - 如何用绝对定位和相对定位正确定位

php - 如何将表单中复选框的值保存到单个 MySQL 字段中?

javascript - jQuery/JavaScript - 根据浏览器的窗口高度和宽度自动剪切和格式化段落