Having multiple divs lined up horizontally on a single row

I am trying to create three divs in a single row similar to this:

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

Any assistance on how to achieve this setup would be greatly appreciated.

Answer №1

If you're looking for different ways to achieve a specific layout, here are some options I want to share with you. Feel free to explore and see if any of these techniques could be helpful for your project.

  1. Table Layout:

body{
  margin: 0;
}
* {
  box-sizing: border-box  
}
.wrapper {
  display: table;
  height: 100%;
  width: 100%;
  border-collapse: collapse;
 }
.wrapper .row {
  display: table-row;  
}
.wrapper .row div {
  display: table-cell;
  border: 1px solid white;
  background: #ddd;
  color: red;
  text-align: center;
  height: 100px;
  vertical-align: middle;
}
<div class="wrapper">
  <div class="row">
    <div>a</div>
    <div>b</div>
    <div>c</div>
  </div>
  <div class="row">
    <div>d</div>
    <div>e</div>
    <div>f</div>
  </div>
</div>

  1. Using Flexbox :

body{
  margin: 0;
}
* {
  box-sizing: border-box  
}
.wrapper {
  height: 100%;
  width: 100%;
 }
.wrapper .row {
  display: flex;
  flex-direction: row;
}
.wrapper .row div {
  flex: 1;
  border: 1px solid white;
  background: #ddd;
  color: red;
  text-align: center;
  height: 100px;
  display: inline-block;
  vertical-align: middle;
}
.wrapper .row div:before {
  content: '';  
  display: inline-block;
  vertical-align: middle;
  height: 100%;
}
<div class="wrapper">
  <div class="row">
    <div>a</div>
    <div>b</div>
    <div>c</div>
  </div>
  <div class="row">
    <div>d</div>
    <div>e</div>
    <div>f</div>
  </div>
</div>

  1. Using Float :

body{
  margin: 0;
}
* {
  box-sizing: border-box  
}
.wrapper {
  height: 100%;
  width: 100%;
 }
.wrapper .row {
  display: block;
}
.wrapper .row:after {
  content: '';
  display: block;
  clear: both;
}
.wrapper .row div {
  flex: 1;
  border: 1px solid white;
  background: #ddd;
  color: red;
  text-align: center;
  height: 100px;
  display: inline-block;
  vertical-align: middle;
  width: 33.33%;
  float:left;
}
.wrapper .row div:before {
  content: '';  
  display: inline-block;
  vertical-align: middle;
  height: 100%;
}
<div class="wrapper">
  <div class="row">
    <div>a</div>
    <div>b</div>
    <div>c</div>
  </div>
  <div class="row">
    <div>d</div>
    <div>e</div>
    <div>f</div>
  </div>
</div>

Thank you for reading!

Answer №2

<div><div style="height:40px; width:40px; float:left;">uniquecontent1</div><div style="height:40px; width:40px; float:left;">uniquecontent2</div><div style="height:40px; width:40px; float:left;">uniquecontent3</div><div style="height:40px; width:40px; float:left;">uniquecontent4</div><div style="height:40px; width:40px; float:left;">uniquecontent5</div><div style="height:40px; width:40px; float:left;">uniquecontent6</div></div>

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

Tips for incorporating Material.io outlined icons within css pseudoelements (::before) usage

I'm attempting to incorporate the Material.io icon into a button using ::before, but it is appearing filled rather than outlined. Unfortunately, there are no available instructions on how to display the icon in an outlined style. This is the code I ...

What is the best way to center text in a div with a distinct background color?

Could really use some assistance with this. Here are the images for reference: https://i.stack.imgur.com/JNZkT.jpg Currently getting this result: https://i.stack.imgur.com/nW17o.jpg <style> .Nav_bar_links div{ margin: 0% 1 ...

A method to apply a class to the third <li> element using javascript

Can someone help me figure out how to add a class to the third element using Javascript? Here is the structure I am working with: <ul class="products-grid row four-columns first"> <li class="item"></li> <li class="item"></li&g ...

Convert PHP function output to HTML element

Check out the content of my Class.php file: <?php class Class { public function validate() { if(empty($_POST['first_name'])) { return 'first name should not be empty!'; } elseif(em ...

When it comes to the CSS `:visited` pseudo-class, I have

I'm having trouble changing the color of the anchor tag and blurring the image after visiting the link. Despite my CSS code, only the color is changing and the image remains unchanged. Here's my CSS code: <style> .image123{ paddin ...

Tips for executing a function on a specific class selector using the document.getElementsByClassName method

When I click on a specific class, I want to implement a fade-out function in JavaScript. However, I am struggling to make a particular class fade out successfully. I attempted to use the this keyword, but it seems like I might be using it incorrectly bec ...

Display iframe as the initial content upon loading

Seeking solutions for loading an iframe using jQuery or Ajax and outputting the content to the page once it has been loaded. The challenge lies in loading an external page that may be slow or fail to load altogether, leading to undesired blank spaces on th ...

Develop a responsive component on the right side

I am encountering an issue with creating a responsive div that matches the height of the image on the left side. I want to include text in this div, however, when I do so, the paragraph expands in height along with the div element when I attempt to change ...

Guide on excluding a specific element using an Xpath expression

I am seeking a solution to craft an XPath expression that can target all <p> elements except for p[6] and p[7]. Currently, I have formulated this expression: //div[@class="Job-Description app-responsive-jd"]/p[1], which is functioning corre ...

What steps should I follow to ensure that the content for the back page is printed on the back page of a booklet when using paged.js?

In the case of a booklet printed from folded sheets, it is interesting to note that the number on the back page will always be divisible by 4. If the content does not have a multiple of 4 pages, then the back page will end up inside the booklet. For my cu ...

Problem involving non-breaking spaces

After changing the font-family of my website from Gotham Pro to Gotham, I encountered an issue with the styling of numbers that were formatted using my currency formatter function. Strangely, when the &nbsp character is removed, everything appears to b ...

Emphasize entries in an index that match the currently visible content as you scroll

I have a table of contents in my HTML page with the CSS attribute position: fixed;. I want to emphasize the current reading position by highlighting it (bold or italics) as I scroll down the page. | yada yada yada ... 1. Secti ...

Avoiding line wrapping can be achieved by hiding elements using the d-none class from Bootstrap

During the development of a responsive website, I encountered an issue with the topbar menu. The menu contains numerous options, which is ideal for larger screens. However, on smaller viewports like cellphones, the buttons start wrapping rather than fittin ...

Applying FAB (Material UI) to span across 2 columns in a CSS Grid: A step-by-step guide

Is there a way to make the zero button larger than the other buttons in its row by spanning 2 columns? I would like it to be an oversized oval shape. Appreciate any assistance you can provide. import "./styles.css"; import Button from '@mui/materia ...

Perfectly Aligning Image at the Center of the Screen

I'm having trouble centering a loading image on my screen. It seems to be centered closer to the bottom rather than in the middle. Any suggestions on how I can adjust it to be more centered vertically? Edit: I also want it to look good on mobile devi ...

What is the best way to ensure the second navbar stays at the top when scrolling, after the first one?

Looking for a solution to create a navbar with two distinct sections for contact info and the menu. The goal is to have the contact info disappear when scrolling down, while the menu remains fixed at the top of the page. When scrolling back up, the menu sh ...

Reducing Bootstrap Navigation Bar with a scrolling logo

Is there a way to make the fixed navbar shrink 50% when it starts scrolling? I've only come across text navbars, but I'm looking for one with a logo. Any suggestions would be greatly helpful. You can access the css and html from that link. ...

React-bootstrap's Modal is glitching and only partially appearing on the screen

I am a beginner in frontend development and I've been struggling to position the modal at the center of the screen; it keeps appearing on the right side. I am currently using "bootstrap/dist/css/bootstrap.min.css" for my CSS. Should I create a new CSS ...

Using JavaScript to pass a value from an input field to a href attribute

I am currently working on a scenario where, upon clicking on an input field, the value is passed to a URL and the corresponding radio button is checked. This way, I can share the URL with someone else. Unfortunately, I have hit a roadblock in my progress: ...

Embedding a PDF file into an HTML form

For days, I have been on a relentless search for a solution to my problem to no avail. My ideal scenario involves embedding a fillable pdf form into an intranet html form for submission to the server, with the ability to parse field/values being a bonus b ...