【问题标题】:How to put two html elements on the same line on opposite sides如何将两个html元素放在同一行的相对侧
【发布时间】:2020-09-05 02:53:15
【问题描述】:

我正在尝试设置这个样式(我正在使用引导程序):

代码如下:

<div class="container-fluid" id="products">
    <h2 class='wishlist-title text-center'>My Wishlist ({{ productList|length }} items)</h2>
    {% for product in productList %}
    <div class='userProduct text-left'>
        <a class='product-title' href="{{ product.productURL }}" target="_blank">{{ product.title|truncate(30) }}</a>
        <h4 class="current-price text-right">Current Price: ${{ product.currentPrice }}</h4>
        <h4 class="budget">Budget: ${{ product.userBudget }}</h4>
        <form class='adjust-budget' method="POST" action="{{ url_for('budget', id=product.id) }}">
            <input class='budget-update input-lg' type="number" id="new_budget" name="new_budget" min="0" max="{{ product.currentPrice }}" step=".01"><br>            
            <input class='budget-update-btn btn btn-primary' type="submit" value="Adjust Budget">
        </form>
        <form class='remove-wishlist' action="{{ url_for('delete', id=product.id) }}">
            <button class="btn btn-danger" type="submit">Remove from Wishlist</button>
        </form>
        
        {% if loop.index < productList|length %}
        <hr>
        {% endif %}
    </div>
    {% endfor %}
</div>

和当前的css

body {
    padding-top: 50px;
    font-family: Cabin;
    font-size: 20px;
  }
  
  footer {
    color: #111111;    
    position: absolute;
    bottom: 0;
    width: 100%;  
    
}

.form-track {
  max-width: 330px;
  padding: 15px;
  margin: 0 auto;
}

.product-title {
  display: inline-block;
  
}

.current-price {
  display: inline-block;
  
}

.adjust-budget {
  display: inline-block;
  
}

.remove-wishlist {
  display: inline-block;
  
}

  .logo {
    font-size: 30px;
  }  
  
  /*
   * Global add-ons
   */
  
  .sub-header {
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
  }
  
  /*
   * Top navigation
   * Hide default border to remove 1px line.
   */
  .navbar-fixed-top {
    border: 0;
  }
  
  
  /*
   * Main content
   */
  
  .main {
    padding: 20px;
  }
  @media (min-width: 768px) {
    .main {
      padding-right: 40px;
      padding-left: 40px;
    }
  }
  .main .page-header {
    margin-top: 0;
  } 

我本质上希望当前价格与产品标题在同一行,但要保持在右侧并具有响应性。 另外,我怎样才能使调整预算按钮和输入区域并排并使其大小相同? 最后,我希望从愿望清单中移除按钮与调整预算按钮位于同一行(类似于当前价格和产品标题)

我尝试用 display: inline-block 和宽度和填充做一些事情,但它没有响应

TLDR 我怎样才能把它设计成这样:

【问题讨论】:

    标签: html css flask bootstrap-4 flask-bootstrap


    【解决方案1】:

    修改你的 html 到下面我添加了一些 div 来使用 css flex 属性

     <div class="container-fluid" id="products">
        <h2 class='wishlist-title text-center'>My Wishlist ({{ productList|length }} items)</h2>
        {% for product in productList %}
        <div class='userProduct text-left'>
           <div class="productprice">
            <a class='product-title' href="{{ product.productURL }}" target="_blank">{{ product.title|truncate(30) }}</a>
            <h4 class="current-price text-right">Current Price: ${{ product.currentPrice }}</h4>
           </div>
           
            <h4 class="budget">Budget: ${{ product.userBudget }}</h4>
            <div class="formdiv">
                <form class='adjust-budget' method="POST" action="{{ url_for('budget', id=product.id) }}">
                    <input class='budget-update input-lg' type="number" id="new_budget" name="new_budget" min="0" max="{{ product.currentPrice }}" step=".01"><br>            
                    <input class='budget-update-btn btn btn-primary' type="submit" value="Adjust Budget">
                </form>
                <form class='remove-wishlist' action="{{ url_for('delete', id=product.id) }}">
                    <button class="btn btn-danger" type="submit">Remove from Wishlist</button>
                </form>
            </div>
           
            {% if loop.index < productList|length %}
            <hr>
            {% endif %}
        </div>
        {% endfor %}
    </div>
    

    并添加这些 css

        .adjust-budget {
          display: flex;
        }
        
        .productprice,.formdiv{
            display: flex;
            justify-content: space-between;
        }
    
      
    

    这将与您在图像中的预期相似,因为您的服务器端代码已编译,因此不会打印动态值

    【讨论】:

    • 我没有 bootstrap 4 并且将其更改为 bootstrap 4 使我的页面的其余部分现在看起来很奇怪。有没有办法使用 bootstrap 3 css 类或一些 css 配置来做到这一点?
    • 是的,当然我已经编辑了我的答案,现在我已经通过 css 属性完成了,这将使用引导程序或使用纯 html
    猜你喜欢
    • 1970-01-01
    • 2013-09-22
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多