Show three blocks side by side using CSS inline styling

I'm trying to display three divs - #left_sidebar, #records_list, and #right_sidebar - inline on my webpage. Initially, I used display:inline-block, but the sidebars ended up at the bottom of the page. Then, I attempted using float, but it resulted in some unexpected behavior. Finally, I combined float and display properties as follows:

#left_sidebar {
    top: 0px;
    width: 142px;
    float: left;
}

#records_list {
    width: 530px;
    display: inline-block;
}

#right_sidebar {
    background-image: url('../images/enstein_banner.png');
    width: 174px;
    height: 231px;   
    float: right;
}

By mixing float and display settings, everything now displays correctly. Can someone confirm if this approach is correct or suggest an alternative method? Thank you!

P.S. Feel free to ask for more information if my question is unclear.

Answer №1

#left_sidebar {
  width: 10%;
  padding: 20px;
  background: red;
  float: left;
  margin-right: 1%;
  color: #fff;
}
#records_list {
  width: 50%;
  padding: 20px;
  background: red;
  float: left;
  margin-right: 1%;
  color: #fff;
}
#right_sidebar {
  background-image: url('../images/enstein_banner.png');
  width: 15%;
  padding: 20px;
  background: red;
  height: 231px;
  float: left;
  color: #fff;
}
<div class="wrapper">
  <div id="left_sidebar">left bar</div>
  <div id="records_list">center part</div>
  <div id="right_sidebar">right bar</div>
</div>

Feel free to verify this now

Answer №2

To ensure all three div elements have a fixed width, you should use a wrapping div with a fixed width as well.

Additionally, try using float:left instead of inline-block.

For more information and demonstration, refer to the following fiddle: https://jsfiddle.net/afelixj/racnob3f/

Answer №3

I understand that you may already be familiar with the concept of float, but I believe there is still room for further clarification. A detailed discussion on float, inline, and inline-block can be found here: float:left; vs display:inline; vs display:inline-block; vs display:table-cell;

Answer №4

apply the float left property to all elements, causing them to line up horizontally one after the other. To create space between them, use margin.

To implement these changes:

#left_sidebar {
width: 142px;
float: left;
}

#records_list {
width: 530px;
float: left;
}

#right_sidebar {
background-image: url('../images/enstein_banner.png');
width: 174px;
height: 231px;   
float: left;
}

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

Switch the navbar background color from see-through to black

On my website, I have set up a navbar navigation that transitions between a transparent background and a black background as the user scrolls down. However, I would like the black background to be present at all times for the navbar. I built the website us ...

Adding text in front of an input field can be achieved by using the placeholder attribute

I'm struggling to insert text on the left side of an input field and beneath a label. Working with Bootstrap 4.3.1, my HTML code appears as follows: <div class="col-lg-6 col-md-6 col-sm-6"> <!-- some markup in here --> </div& ...

Learn the effective way to customize the primary button text color in Bootstrap 4 using SCSS styling

Looking to customize the .btn-primary text color. I attempted to modify the background color in _variables.scss by adding the following line: $primary: #a1c1b6; However, I was unable to change the text color despite trying various options. // not working ...

JavaScript date formatting without using jQuery

Looking for help to apply a date mask (dd/mm/yyyy) on an ASP.net textbox. I have tried several JavaScript solutions found through Google search, but none seem to work seamlessly, especially with backspacing. Any suggestions for a reliable script would be ...

I'm having trouble getting my CSS opacity to smoothly transition back to its original state of .5 using setTimeout(). What could be

I recently started learning JS, Jquery, and CSS. My goal is to create a Simon Says style game. However, when I attempt to animate the computer to automatically light up the correct square, I faced some challenges. To address this issue, I decided to star ...

Arrangements of lines in website design for various screen resolutions

I am having an issue with the layout I'm working on - specifically, there is a visible outline of the div boxes at certain resolutions or when zooming in. This is what it should look like: However, this is how it appears at some resolutions or when ...

Attach an event listener to a particular textarea element

Currently, I am developing a project in Next.js13 and my focus is on creating a custom textarea component. The goal is to have this component add an event listener to itself for auto-adjusting its height as the user types. Below is the relevant section of ...

Email Markup: !mso conditional tactic

As a newcomer to HTML Email Development, I've been diving into dissecting HTML Emails on "reallygoodemails.com" in order to enhance my understanding of HTML Email structures. During my exploration, I stumbled upon four different methods for creating ...

Can we dynamically adjust font size based on the width of a div using CSS?

My div is set to 70% width and I have a specific goal in mind: To fill that div with text To adjust the font size so that it takes up the entire width of the div https://i.stack.imgur.com/goVuj.png Would it be possible to achieve this using only CSS? B ...

How can I prevent the background image from overlapping the footer?

Click here for image Live version can be found at this link The background image extends beyond the footer. body { background-image: url(../img/planet.jpg); background-repeat: no-repeat; background-size: cover; } Footer: .footer { padd ...

Attempting to resolve the Bootstrap issue, currently in search of a suitable solution

Today I made the decision to utilize bootstrap to create a menu, but unfortunately, I've encountered a strange bug or conflict involving jQuery, potentially the UI, and Bootstrap. If you'd like, you can take a look at the picture provided in the ...

Update the style class of an <img> element using AJAX

My success with AJAX enables PHP execution upon image click. However, I seek a real-time visual representation without page reload. Thus, I aim to alter <img> tag classes on click. Presently, my image tag resembles something like <img title="< ...

Error Encountered in Laravel 5.2 FormBuilder.php

Encountering Laravel 5.2 ErrorException in FormBuilder.php on line 1235 stating that the method 'style' does not exist. This error has me perplexed. I have already made updates to my composer.json file by adding "laravelcollective/html": "^5.2" ...

CSS pixel movement problem causing the page to shift a few pixels before returning to its original position

Encountering a CSS issue, I need assistance. Take a look at this page. When you click on the "Barcelona" link on that page, the entire page shifts 10 pixels to the right and then returns to its original position. Why is this happening? Any solutions or i ...

New to CSS: Applying a background image on top of a gradient without any transparency on the image

Appreciate you taking the time to read this I'm facing an issue where I want to have a background image overlaid on a gradient, but every solution I've tried ends up making the background image transparent, causing a discrepancy in colors. I att ...

What is the reason behind Chrome removing an SVG image pattern while utilizing jQuery Draggable?

Currently, I am trying to encapsulate an SVG within a draggable div. The SVG contains a shape or path with an image fill on the face. Surprisingly, it displays perfectly and functions flawlessly in Firefox. However, when it comes to Chrome, the dragging op ...

If the option is 'Gel', use an if statement to console log

I'm trying to console.log the option from the data() function that is equal to 'Gel'. I attempted to use an if statement, but it doesn't seem to be working. Anyone have any ideas on how to make this work? data(){ return { ...

Ensuring CSS styles are permanent and unchangeable

Can someone guide me on how to ensure CSS styles remain immutable and cannot be overridden by JavaScript? The issue at hand is that sometimes, due to the presence of an img tag in the JavaScript code, all styling (for all images) ends up being replaced. ...

Switch up the placement of the boxes by moving them in different directions, such as

I've been attempting to recreate the button movement demonstrated in this link , but I'm having trouble achieving it. Using CSS animation, I can make the buttons move in a straight line, here's what I have so far: <div id="box" style=&ap ...

Looking to dynamically increase the ID of a specific DIV element using Jquery at regular time intervals?

<div id='my_id1'></div> Is there a way to increment by 1+ in a loop at specific time intervals, such as on the same div after 3 seconds using jQuery? I am new to JavaScript and would appreciate any help. Thank you! ...