简体   繁体   English

CSS-两个Divs并排自动宽度

[英]CSS - Two Divs side by side auto width

I want make two columns with text inside. 我想在两栏内写上文字。 Depending on where it will be more text box will increase the width, but height must be the same. 根据不同的位置,文本框的宽度会增加,但是高度必须相同。

This is my code, and i don't know how to solved the problem. 这是我的代码,我不知道如何解决该问题。

https://jsfiddle.net/x0qqtr2y/ https://jsfiddle.net/x0qqtr2y/

<div id="main>
  <div class="cell1">SomeTEXTSomeTEXTSomeTEXTSomeTEXT</div>
  <div class="cell2">SomeTEXTSomeTEXT</div>
</div>

#main {
    width:100%;
    background:gray;
    display:table;
    position:relative;
}
.cell1 {
    width:auto;
    height:auto;
    display:table-cell;
    background:red;
    float:left;
}

.cell2 {
    width:auto;
    height:auto;
    display:table-cell;
    float:left;
    background:blue;
}

use display:flex; 使用display:flex; on the parent element example below 在下面的父元素示例中

CSS 的CSS

#main {
width:100%;
display:flex;
}
.cell1 {
    background:red;
}

.cell2 {
    background:blue;
}

HTML on your main make sure you close the quote marks 主屏幕上的HTML确保已关闭引号

<div id="main">
  <div class="cell1">SomeTEXTSomeTEXTSomeTEXTSomeTEXT</div>
  <div class="cell2">SomeTEXTSomeTEXT</div>
</div>

To learn more about flex use the link: https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 要了解有关flex的更多信息,请使用以下链接: https : //css-tricks.com/snippets/css/a-guide-to-flexbox/

I would try this CSS, worked when I tried it in your Fiddle: 我会尝试这个CSS,在我的Fiddle中尝试时会起作用:

#main {
    width:100%;
    background:gray;
    position:relative;
}
#main div {
    display: inline;
}

.cell1 {
    background:red;
}

.cell2 {
    background:blue;
}

Hi Because u miss (") id="main" below code working fine check it 嗨,因为您错过了(“)id =” main“,下面的代码工作正常,请检查一下

CSS 的CSS

#main {
width:100%;
background:gray;
}
.cell1 {
background:blue;
float:left;
}
.cell2 {

float:left;
background:red;
}

Html HTML

<div id="main">
<div class="cell1">SomeTEXTSomeTEXTSome</div>
<div class="cell2">SomeTEXTSomeTEXT1</div>   
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM