Tips on arranging elements so that they appear in the same row as other similar elements

Currently, my display looks like this.

The add to cart button is not showing up in a row because the product name of the third element is a bit lengthy.

This is the code used to display the products:

<div>
    <div class='box' ng-repeat="product in ProductService.Products | filter:{'SubCategoryID': SCId.toString()}:true | orderBy:'ProductName'">

        <br>        <b>{{product.BrandName}}</b>
        <br>        {{product.ProductName}}
        <br><br>    <img src="http://localhost/{{ product.ProductImagePath }}" alt="" border=3 height=75 width=75></img>
        <br><br>    <select class="form-control btn btn-default btn-xs" ng-init="SelectedVariant = product.Variants[0]" ng-model="SelectedVariant" ng-options="variant.VariantName for variant in product.Variants" ng-change="ChangeVariant(product.ProductID, SelectedVariant.VariantID)"></select>

        <br>        <strike> {{SelectedVariant.MRP}} </strike> &nbsp; {{SelectedVariant.SellPrice}} {{SelectedVariant.InCart}}
        <br><br>        

        <div ng-if="SelectedVariant.InCart==0">
            <a class="btn btn-success btn-md" ng-click="AddToCart(product.ProductID, SelectedVariant.VariantID)">Add to Cart &nbsp;
                <span class="glyphicon glyphicon-plus"></span> 
            </a>
        </div>



        <div ng-if="SelectedVariant.InCart>0">

            <a class="btn btn-default btn-xs" ng-click="PlusItem(product.ProductID, SelectedVariant.VariantID)">
                <span class="glyphicon glyphicon-plus"></span> 
            </a>

            <button type="button" class="btn btn-info disabled">{{SelectedVariant.InCart}} in cart</button>


            <a class="btn btn-default btn-xs" ng-click="MinusItem(product.ProductID, SelectedVariant.VariantID)">
                <span class="glyphicon glyphicon-minus"></span> 
            </a>
        </div>  

    </div>          
</div>

Here is the CSS style for the box:

.box {
    margin : 5px;
    display : inline-block;
    width: 150px;
    height: 300px;
    background-color: #F5FBEF;
    text-align:center;
    vertical-align: top;
}

I need assistance in aligning all the elements in the box so that the add to cart buttons start on the same row. Currently, some are causing layout issues due to varying lengths of product names.

Answer №1

It is highly advised to steer clear of using <br> tags for content layout purposes.

I suggest placing all the elements (title/image/dropdown/button) in their own div container, where you can specify a fixed height for each individual container. For example, the height of the .title could be set to accommodate at least two lines of text.

<div class="boxes">
   <div class="box">
      <div class="title">Wheel <strong>Strong detergent bar</strong></div>
      <div class="image"><img src=""></div>
      <div class="price">$35</div>
      <div class="orderbutton"><button>Order now</button></div>
   </div>
</div>

You can then define the sizes for each of these classes in your .css file.

Answer №2

If the title is too long, I suggest adding an ellipsis to keep everything on one line.

Make sure to wrap your ProductName in a designated class

<span class='product-name'>{{product.ProductName}}</span>

Afterwards, you can style it with the following code:

.product-name{
  width: 100%;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis; 
  white-space: nowrap;
}

For a live example, check out this fiddle

Answer №3

I am seeking assistance to align all add to cart buttons or elements within a box on the same row, such as elements 1, 2, 4, and 5 in the display.

To achieve this, utilizing CSS flexbox would be helpful. However, it's worth noting that Internet Explorer versions below 10 do not support this feature.

Desired outcome: http://jsbin.com/micedo

Additional resources: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty setting a value for a tooltip with replaceWith() function

When using jQuery's .replaceWith() method to insert new DOM contents, I noticed that all content gets replaced except for the value of the title. Even though I tried different approaches, the tooltip only displays {{descriptions.title}} instead of the ...

Creating a Navigation Bar in Outlook Style Using Javascript and CSS

Looking for a navigation sidebar design similar to Outlook for my web application. I have seen options available as Winform controls and through Visual WebGUI, but these are Microsoft-dependent solutions. We need a Javascript & CSS based solution that is s ...

Modifying css background in real-time based on the current weather conditions

Is there a way to dynamically change the background image in CSS based on the weather condition? I'm utilizing the wunderground API to retrieve the weather data, which is stored in the weather variable. I am struggling with how to update the backgrou ...

Email contact form using PHP

After following a tutorial on creating a basic 'contact us' form using PHP, I want the form to display a thank you message or error message directly on the same page instead of redirecting to a separate thank you page. How can I modify the code ...

Utilizing CSS to create a text box with angled left and right edges

.soccer-field{ width: 50%; box-shadow: 0 4px 12px 4px rgba(0,0,0,0.2); } .text-sf p{ float:left; } .right-curve{ float:right; width: 0; height: 0; border-style: solid; ...

Stop using the bootstrap dl-horizontal class for responsive design

I utilized Bootstrap to design a list and used the dl-horizontal class in the following way: <dl class="dl-horizontal"> <dt>1</dt> <dd>deta1</dd> <dt>1</dt> <dd>deta1</dd> <dt>1</dt> ...

Creating a choppy movement when switching between content with jQuery

I am experiencing a choppy effect when trying to toggle the content visibility with a button click. Can someone advise if there are any issues in how I have structured the markup? Also, is there a way to achieve a smoother toggle effect? View Code $(do ...

Wordpress Debacle: Bootstrap Columns Clash

Currently, I am in the process of designing a unique theme. In my code, I have implemented a condition that generates an additional div with the class "row" after every three posts or columns are created. Everything seems to be working smoothly, except f ...

Guide on how to save the selected user option in a PHP form

I'm having trouble getting the form to automatically set itself based on the state selected by the user from a drop-down menu of 50 states. The user's info, including their chosen state, is stored in an info array with $state. Everything else dis ...

The CSS property 'clear:both;' is not functioning properly on IE7 browsers whereas works fine on IE8/IE9, Firefox, Chrome, and other browsers

I have been receiving feedback from visitors about some issues on one of my websites. Those who reached out to us are using IE7 on Windows XP. I was able to recreate the problem by using IE7 or by mimicking it in compatibility mode with IE7 document mode o ...

What is the best way to define a styleClass for applying this CSS?

Is there a way to create a unique styleClass for the tabbed menu section of the form without affecting anything else? Currently, the CSS I have is applying to everything on the form. a.tab-menu-link:link, a.tab-menu-link:visited { display:block; width:1 ...

Angular 7: Finding the variance between array elements

How can I subtract the values from the first 3 rows of the table? The formula is TVA Collectée - TVA Déductible - TVA Déductible/immo If the result is positive, it should be displayed in the box labeled TVA à Payer. If it's negative, it should g ...

Selecting Specific File in Directory Using HTML File Input

Can you customize an HTML file input to choose a particular file from a directory or drive? By clicking on the file input button, the user opens the file selector and selects a folder or external drive. With jQuery, it is then possible to specify a specif ...

Creating a custom HTML table layout with both variable and fixed column widths, along with grouping headers

Is there a way to format an HTML table so that it appears like this: <- full page width -> <-20px->< dynamic ><-20px->< dynamic > +------------------+-------------------+ ¦ A ¦ B ...

What are some strategies I can use to prevent issues with my web design while updating bootstrap?

I recently updated Bootstrap CDN from version 4.0.0 alpha to beta this morning. Here is a snapshot of how the web page looked before (still under construction): Website with Bootstrap 4.0.0 alpha And here is how it appears now: With Bootstrap 4.0.0 bet ...

Step-by-step guide: Crafting an UP Arrow solely with HTML and CSS

What is the method to utilize solely HTML and CSS for creating a triangle? I am in need of constructing a thick triangle, but want to achieve this using only CSS So far, I have experimented with the following code: .arrow-up { width: 0; height: 0 ...

Interacting with HTML elements via Java programming

I am looking for a way to interact with HTML elements in my Java program by using the id or className of the elements (similar to getElementByID or getElementsByClassName). Additionally, I need the ability to click buttons on the page. Key Points: I am d ...

What is the best method for retrieving text from elements designated by class?

I am currently using BeautifulSoup to scrape data from a website, but I am facing an issue with extracting only the text I need. The specific part of the website data that I want to grab is: <div content-43 class="item-name">This is the te ...

Activate resizing only a single time

I am currently working on a script to reverse the order of two divs when the client's window is resized; however, I seem to be stuck in a loop. Although flexbox could easily solve this issue, I am determined to figure it out using JavaScript as part o ...

Customizable Button component featuring background image options

Need help with creating a versatile Button component in React that can easily accommodate different sizes and shapes of background images? This is how my current implementation looks like - Button.js const Button = ({ url }) => { const inl ...