如何把两个元素并排 [英] How to put two elements side by side

查看:157
本文介绍了如何把两个元素并排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把两个元素并列,但我不能让它工作。我尝试float:left和display:inline-block,没有工作。

Im trying to put two elements side-by-side, but i can't get it to work. I tryed float: left and display: inline-block and none of it worked. I tryed putting inline styling, file styling, head styling and none of it worked.

HTML:
`

HTML: `

{% extends "layout.html" %}
{% block title %} Home {% endblock %}
{% block head %}
  <script src="{{ url_for('static', filename='isp_home/main.js')}}"></script>
  <script src="{{ url_for('static', filename='libs/poseidon.min.js')}}"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
  <link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="{{ url_for('static', filename='isp_home/main.css')}}">
{% endblock %}
{% block body %}
  <div class="container" id="welcome" style="margin-top: 3%;">
    <h1 style="text-align: center;">Welcome back to Dataflow</h1>
    <h2 style="text-align: center;">Click to change view</h2>
  </div>
  <div class="container main" style="margin-top: 3%;">
    <div class="container main-info">
      <i class="fa fa-btc" style="font-size: 6em"></i>
      <h2> DataCoin wallet: </h2>
      <h3> DataCoins: 50 </h3>
      <h3> DataCoin Trust: 50 </h3>
    </div>
    <div class="container main-info">
      <i class="fa fa-server" style="font-size: 6em;"></i>
      <h2> Computating Power Usage: </h2>
      <h3> Decryption: 40% </h3>
      <h3> DataCoin Mining: 40% </h3>
      <h3> Spamming and Pishing: 20% </h3>
    </div>
    <div class="container main-info">
      <i class="fa fa-server" style="font-size: 6em"></i>
      <h2> Computating Power Usage: </h2>
      <h3> Decryption: 40% </h3>
      <h3> DataCoin Mining: 40% </h3>
      <h3> Spamming and Pishing: 20% </h3>
    </div>
  </div>
{% endblock %}

CSS:

body {
  background-color: #0d0d0d;
  font-family: 'Raleway';
  color: white;
}
* {
  font-family: 'Raleway';
  color: white;
}
.main-info {
  margin-top: 3%;
  margin-left: 0%;
  display: inline-block;
  float: left;
}
.main {
  width: 100%;
}


推荐答案

为元素.main-info。该值不一定是百分比。

You need set a width's value for the element ".main-info". The value doesn't have to be percent.

.main-info {
    margin-top: 3%;
    margin-left: 0%;
    display: inline-block;
    float: left;
    width: 30%;// could be 100px for example
 }

请参见 https://jsfiddle.net/bgdvxce4/

这篇关于如何把两个元素并排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆