How do you make div elements display inline?

2019-01-01 06:09发布

Given this HTML:

<div>foo</div><div>bar</div><div>baz</div>

How do you make them display inline like this:

foo bar baz

not like this:

foo
bar
baz

标签: css line html
19条回答
人间绝色
2楼-- · 2019-01-01 07:03

As mentioned, display:inline is probably what you want. Some browsers also support inline-blocks.

http://www.quirksmode.org/css/display.html#inlineblock

查看更多
听够珍惜
3楼-- · 2019-01-01 07:03

ok, for me :

<style type="text/css">
    div{
        position: relative;
        display: inline-block;
        width:25px;
        height:25px;
    }
</style>
<div>toto</div>
<div>toto</div>
<div>toto</div>
查看更多
柔情千种
4楼-- · 2019-01-01 07:05

An inline div is a freak of the web & should be beaten until it becomes a span (at least 9 times out of 10)...

<span>foo</span>
<span>bar</span>
<span>baz</span>

...answers the original question...

查看更多
孤独寂梦人
5楼-- · 2019-01-01 07:09

I think you can use this way without using any css -

<table>
 <tr>
  <td>foo</td>
 </tr>
 <tr>
  <td>bar</td>
 </tr>
 <tr>
  <td>baz</td>
 </tr>
</table>
查看更多
初与友歌
6楼-- · 2019-01-01 07:10
<style type="text/css">
div.inline { display:inline; }
</style>
<div class="inline">a</div>
<div class="inline">b</div>
<div class="inline">c</div>
查看更多
孤独总比滥情好
7楼-- · 2019-01-01 07:11

Just use a wrapper div with "float: left" and put boxes inside also containing float: left:

CSS:

wrapperline{
width: 300px;
float: left;
height: 60px;
background-color:#CCCCCC;}

.boxinside{
width: 50px;
float: left;
height: 50px;
margin: 5px;
background-color:#9C0;
float:left;}

HTML:

<div class="wrapperline">
<div class="boxinside">Box 1</div>
<div class="boxinside">Box 1</div>
<div class="boxinside">Box 1</div>
<div class="boxinside">Box 1</div>
<div class="boxinside">Box 1</div>
</div>
查看更多
登录 后发表回答