Having trouble achieving the desired effect with inline block

I'm having some trouble creating a simple store page. One of the products is supposed to look like this:

https://i.sstatic.net/JLlua.png

However, it's currently showing up like this:

https://i.sstatic.net/hHYUm.png

I've been attempting to use inline block so that I can have the negotiate button and product price on the same line, with the button aligned to the left and the price to the right. But for some reason, inline block isn't behaving as expected. Can anyone help me figure out why?

#popularSection {
  background-color: blue;
}

#product {
  outline: 1px solid grey;
  margin: 15px;
  background-color: lightblue;
  padding-top: 10px;
}

#negButton {
  margin-bottom: 10px;
}

#inline {
  margin: 0;
  padding: 0;
  display: inline-block;
}

img {
  width: 190px;
  height: 140px;
}
<div class="container">
  <div class="row" id="popularSection">
    <div class="col-lg-3 text-center">
      <div id="product">
        <img class="img-responsive" src={{path}}/>
        <p>{{productName}}</p>
        <div id="inline">
          <button class="btn btn-success btn-sm" type="button" id="negButton" (click)="negotiate()">Negotiate</button>
          <p>{{price}}</p>
        </div>
        <button class="btn btn-success btn-sm" type="button" id="addCart" (click)="addCart()">Add To Cart</button>
      </div>
    </div>
  </div>
</div>

Answer №1

To style the container, you can utilize the properties display: flex; and flex-direction: row;.

#popularSection {
  background-color: blue;
}

#product {
  outline: 1px solid grey;
  margin: 15px;
  background-color: lightblue;
  padding-top: 10px;
}

#negButton {
  margin-bottom: 10px;
}

#inline {
  display: flex;
  flex-direction: row;
}

img {
  width: 190px;
  height: 140px;
}
<div class="container">
  <div class="row" id="popularSection">
    <div class="col-lg-3 text-center">
      <div id="product">
        <img class="img-responsive" src={{path}}/>
        <p>{{productName}}</p>
        <div id="inline">
          <button class="btn btn-success btn-sm" type="button" id="negButton" (click)="negotiate()">Negotiate</button>
          <span>{{price}}</span>
        </div>
        <button class="btn btn-success btn-sm" type="button" id="addCart" (click)="addCart()">Add To Cart</button>
      </div>
    </div>
  </div>
</div>

Answer №2

Consider using a span instead of a p tag for displaying your price, as it is an inline element.

You can then remove the unnecessary style from the #inline div.

(Please note that in the following snippet, I have replaced the {{interpolation}} to eliminate any Angular references)

#popularSection {
  background-color: blue;
}

#product {
  outline: 1px solid grey;
  margin: 15px;
  background-color: lightblue;
  padding-top: 10px;
}

#negButton {
  margin-bottom: 10px;
}

#inline {
  margin: 0;
  padding: 0;
  display: inline-block;
}

img {
  width: 190px;
  height: 140px;
}
<div class="container">
  <div class="row" id="popularSection">
    <div class="col-lg-3 text-center">
      <div id="product">
        <img class="img-responsive" src="https://craft.com.au/images/products/FPA13.jpg" />
        <p>Product 1</p>
        <div>
          <button class="btn btn-success btn-sm" type="button" id="negButton" (click)="negotiate()">Negotiate</button>
          <span >100</span>
        </div>
        <button class="btn btn-success btn-sm" type="button" id="addCart" (click)="addCart()">Add To Cart</button>
      </div>
    </div>
  </div>
</div>

Answer №3

It seems like you've applied display: inline-block to the parent element, but I believe it should be given to the child element instead.

To rectify this, remove display: inline-block from the #inline element and apply it to both the #negButton and the p element.

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

Encounter a problem while running `ng build` due to a module not

I was looking to automate the building of my Angular project on a separate CentOS 7 machine. Here are the versions being used: Angular CLI: 8.3.23 Node: 13.14.0 OS: linux x64 Angular: 8.2.14 ... animations, common, compiler, compiler-cli, core, forms ... ...

Angular 2 feature that allows for a single list value to be toggled with the

Currently, my form is connected to a C# API that displays a list of entries. I am trying to implement a feature where two out of three fields can be edited for each line by clicking a button that toggles between Yes and No. When the button is clicked, it s ...

Challenges with the height of the calendar component in Vuetify

I need assistance with preventing the appearance of two scroll bars while working with Vuetify's sheet and calendar components. https://i.stack.imgur.com/yBfhj.png Below is my code snippet: <template> <v-app> <v-main> & ...

The secrets of z-index: Ensuring nested elements stay behind their parent element

Check out this demo to see the problem: http://jsfiddle.net/5sqxQ/2/ I am trying to make the sub menu appear below the main menu. I also want to use JavaScript to slide the menu from underneath when hovering over the parent li element. I don't real ...

What is the best way to store and retrieve data from the current webpage using HTML, CSS, and JavaScript?

Is there a way to persistently save the button created by the user even when the browser is refreshed? Here is an example code snippet: function create(){ const a = document.createElement("button") document.body.appendChild(a) const b = documen ...

How to ensure an absolutely positioned div spans the entire width of the screen

I am facing an issue with an absolutely positioned div that I want to stretch the full width of the screen using 100vw. However, the problem is that it aligns with its parent's starting point rather than the left side of the viewport. How can I make s ...

Refreshing HTML tables with AJAX in Django

After going through all the posts here, I found that some are outdated and others don't quite match my issue. Apologies for bringing it up again. I have a basic HTML table with data in it. My goal is to update this data without refreshing the entire ...

What is the best way to retrieve the value of a select tag in Vue JS?

Delving into Vue JS has presented me with a challenge. I'm aiming to retrieve the value of the selected option. But unfortunately, I'm stuck. Despite my efforts to scour Google for answers, I have come up empty-handed. Below is a snippet of m ...

What is the best method for sending form data requests using HttpClient?

Currently, I am faced with the task of uploading a file to our server. In the past, I have successfully accomplished this using the Http module from the @angular/http library. However, in order to better integrate with our current project, we have decided ...

Creating an uncomplicated selector bar for a basic javascript slideshow

I've spent the last couple of hours teaching myself some basic JavaScript, so please bear with me. Currently, I have a simple code in place for a straightforward slideshow on a website. Here is the JavaScript I'm using (where the 'slide&apo ...

Silencing the warning message from ngrx/router-store about the non-existent feature name 'router'

After adding "@ngrx/router-store" to my project, I noticed that it fills the app console in development mode and unit test results with a repeated message: The warning states that the "router" feature name does not exist in the state. To fix this, make ...

Encountering a 'Cannot Get /' Error while attempting to reach the /about pathway

I attempted to create a new route for my educational website, and it works when the route is set as '/', but when I try to link to the 'about' page, it displays an error saying 'Cannot Get /about' Here is the code from app.js ...

Personalizing CSS for a large user base

My website allows users to choose themes, customize background, text, and more. I am seeking the best method to save all of these changes. Is it preferable to use a database read or a file read for this purpose? Any recommendations are greatly appreciate ...

Getting to grips with accessing HTML elements within a form

<form name="vesselForm" novalidate> <input type="text" id="owner" name="ownerEdit" required ng-blur="vesselForm.btnCC.attr('value', 'Change Customer')"/> <input type="button" name="btnCC" value="Customer" /> </fo ...

In Angular 15, CSS override configurations do not function as intended

Exploring the world of Angular is exciting, and I am a newcomer to it. Currently, I am tackling an innovative Angular 15 project that makes use of the Material library. My current predicament lies in the fact that none of the CSS overrides appear to be tak ...

Looking to display a single Angular component with varying data? I have a component in Angular that dynamically renders content based on the specific URL path

I have a component that dynamically renders data based on the URL '/lp/:pageId'. The :pageId parameter is used to fetch data from the server in the ngOnInit() lifecycle hook. ngOnInit(){ this.apiHelper.getData(this.route.snapshot.params.pageId) ...

The server is unable to process the request for /path

After browsing various posts, I am still unable to identify the root cause of my issue. I am developing a donation page for an organization and need to verify if PayPal integration is functioning correctly. The error I am encountering lies between my form ...

What is the best way to reset an Observable while maintaining a filter in place?

I have a timer-based observable that periodically updates a REST resource. The user can disable these updates as needed. Here is a simple example code snippet: export class MyThingComponent { data$: Observable<string>; userControlledEnabledFlag: ...

Guide to ensuring a jQuery modal box appears above other page elements

As I work on a jQuery popup modal box, I am faced with the issue of it pushing all other content aside when called. The toggleSlide() function is being used and works fine, but the layout problem remains. Attempts to rectify this by using position: relati ...

Having trouble with spawning child processes asynchronously in JavaScript

I'm trying to figure out how to format this code so that when a user clicks a button, new input fields and redirect buttons are asynchronously inserted into the unordered list. Everything was working fine until I added the redirect button insertion fu ...