十种让两个 DIV 在一行的方法

1,149 阅读5分钟
cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

HTML CSS JavaScript Behavior

HTML Preprocessor

None Haml Markdown Slim Pug

Add Class(es) to <html>

Stuff for <head>

↑ Insert the most common viewport meta tag

CSS Preprocessor

None LESS SCSS Sass Stylus PostCSS

CSS Base

Normalize   Reset   Neither  

Vendor Prefixing

Autoprefixer   Prefixfree   Neither  

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: --- Bootstrap 4 Bootstrap 3 Foundation Animate.css Materialize Bulma + add another resource

JavaScript Preprocessor

None CoffeeScript LiveScript TypeScript Babel

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: --- Angular Backbone Bootstrap 3 Bootstrap 4 D3 Ember Foundation GreenSock TweenMax Handlebars jQuery jQuery UI Lodash Modernizr Polyfill.io Polymer React React DOM Snap.svg Three.js Underscore Vue Zepto ZingChart + add another resource

Code Indentation

Spaces   Tabs     1 2 3 4 5 6 Width of Indent

Save Automatically?

Autosave

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

Enabled

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML

 
1
<div class="one mar">
2
  <div class="a">1</div>
3
  <div class="b"></div>
4
</div>
5
6
<div class="two mar">
7
  <div class="a">2</div>
8
  <div class="b"></div>
9
</div>
10
11
<div class="three mar">
12
  <div class="a">3</div>
13
  <div class="b"></div>
14
</div>
15
16
<div class="four mar">
17
  <div class="a">4</div>
18
  <div class="b"></div>
19
</div>
20
21
<div class="five mar">
22
  <table>
23
    <tr>
24
      <td><div class="a">5</div></td>
!

CSS

 
1
body {
2
  color: #fff;
3
}
4
.a {
5
  width: 50px;
6
  height: 50px;
7
  background: #000;
8
}
9
10
.b {
11
  width: 50px;
12
  height: 50px;
13
  background: #b00707;
14
}
15
16
.mar {
17
  margin-bottom: 10px;
18
}
19
20
.one {
21
  .a {
22
     float: left;
23
  }
24
  .b {
!

JS

999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console

Clear