0

I have this CSS:

div#element1 {
    width: 100px;
    height: 100px;
    float: left;
}
div#element2 {
    width: 100px;
    height: 100px;
    float: left;
}

How do I do this without float? I've tried with display: inline-block; but it doesn't work. Any idea?

4

2 回答 2

1

display: inline-block;像你说的那样放,
还要加上white-space: nowrap;父级#element1 & #element2

于 2013-10-08T18:51:33.923 回答
1

这是一个选项:

<html>
<style>
div {
    display: inline-block;
}
div #element1 {
    width: 300px;
    height: 300px;
    background-color: red;
}
div #element2 {
    width: 300px;
    height: 300px;
    background-color: yellow;
}
</style>
<body>
<div>
    <div id="element1">element1</div>
    <div id="element2">element2</div>
</div>
</body>
</html>

要不就:

div #element1 {
    width: 300px;
    height: 300px;
    background-color: red;
    display: inline-block;
}
div #element2 {
    width: 300px;
    height: 300px;
    background-color: yellow;
    display: inline-block;
}
于 2013-10-08T18:57:30.413 回答