Align everyone vertically in the left, center, or right div

My goal is to create a three-column layout with the following specifications:

  1. div1 (green) with its content left-aligned
  2. div2 (blue) with its content center-aligned
  3. div3 (magenta) with content right-aligned

Within each column, there are multiple block elements (referred to as "sheeps" in my design). I need each element to be vertically aligned at the absolute middle, regardless of their size. As shown by the red-dotted line, all contained elements should have their centers on the same line.

I am starting from scratch and want to achieve this without using fixed dimensions.

Thank you for any assistance provided.

Edit: The code that I currently have can be found here http://jsfiddle.net/gV99f/6/

Answer №1

I'm uncertain, however I believe this may be the solution you are looking for. Tables or display: table, display: table-cell might be necessary.

Take a look at the JsFiddle DEMO here

Answer №2

I came across a solution that may work for you, here is a link to the JSFIDDLE.

Just follow these instructions to align everything properly:

<div class="container">
    <div class="left"><span>div 1</span><br/><img src="http://i49.tinypic.com/bgd4qr.jpg" border="0" alt="Image and video hosting by TinyPic"></a></div>
    <div class="center">div 2</div>
    <div class="right">div 3</div>
</div>

CSS

.container {
    width:600px;
    height:200px;
    border:1px solid;
}
.left {
    width:150px;
    height:200px;
    background:magenta;
    float:left;
}
.left span{
      width:100px;
    float:left;
    text-align:left;
    margin-bottom:20px;
}
.left img{
    width:100px;
    height:100px;
    float:left;

}
.center {
    height:200px;
    width:300px;
    background:blue;
    float:left;
    text-align:center;
}
.right {
    height:200px;
    width:150px;
    background:green;
    float:right;
    text-align:right;
}

Answer №3

If you want to utilize the latest css3 property called flex, here's how you can do it:

In your HTML :

<div id="wrap">
    <div class="green"></div>
    <div class="blue"></div>
    <div class="cyan"></div>
</div>

For styling in CSS :

#wrap{
    height:50px;
    display:flex;
    align-items:initial;
}
#wrap div{
    flex:1;
}

Take a look at the DEMO here: http://jsfiddle.net/6cae7/1/

If you need to adjust the sizes, you can use the flex-grow property like this:

CSS :

#wrap{
    height:50px;
    display:flex;
    align-items:initial;
}
#wrap div{
    flex-grow:1;
}
#wrap div:nth-child(2){
    flex-grow:3;
}

Check out the DEMO for more details: http://jsfiddle.net/6cae7/3/

Answer №4

Check out the Demo

Here is the HTML code:

<div class="wrapper">
    <div class="main">
        <img src="http://www.w3.org/Style/Woolly/woolly-mc.png" width="100" height="100" />
    </div>
    <div class="aside aside-1">
        <img src="http://www.w3.org/Style/Woolly/woolly-mc.png" width="200" height="200" />
    </div>
    <div class="aside aside-2">
        <img src="http://www.w3.org/Style/Woolly/woolly-mc.png" width="150" height="150" />
    </div>
</div>

CSS styles applied to the elements:

.wrapper {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  align-items: center;
  -webkit-flex-flow: row wrap;
  flex-flow: row wrap;
  font-weight: bold;
  text-align: center;
}

.wrapper > * {
  padding: 10px;
  flex: 1 100%;
}

.main {
  background-color: deepskyblue;
   padding: 100px 0;
}

.aside-1 {
  background: gold;
    text-align: left;
    padding: 50px 0;
}

.aside-2 {
  background: hotpink;
    text-align: right;
    padding: 75px 0;
}

@media all and (min-width: 600px) {
  .aside {
    flex: 1 auto;
  }
}
@media all and (min-width: 800px) {
  .main {
    flex: 2 0px;
  }

  .aside-1 {
    order: 1;
  }

  .main {
    order: 2;
  }

  .aside-2 {
    order: 3;
  }

}

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

Changing Background Colors of Grid Items in React.js Grid Layout

I'm currently learning React and have created a basic app that shows data from a database in a grid format. I'm looking to customize the background colors of each grid item based on its priority level, which is pulled from the database. The prior ...

What is the best way to align all menu items horizontally with the logo?

I'm facing a small issue that I can't seem to resolve on my own. I recently added a links menu to the header of my website, and it looks like the menu has fixed dimensions, causing the Login URL to get pushed down due to space constraints. I&apos ...

Bootstrap not functioning properly in selecting gallery items

Looking for some help with my website's gallery page development. I've included the HTML and JavaScript files below. However, I seem to be missing a selector ID as none of the pictures are changing and the categories aren't working. Any help ...

Get rid of the underlined anchors in your email signature

I'm currently in the process of creating personalized email signatures for one of my clients. At this point, I am testing them on various platforms such as GMail, Hotmail, Brinkster, and more. One issue I am facing is trying to remove the underline t ...

CSS transforms fluidly transition between absolute and relative positioning

Can CSS transitions be used to combine "position: relative" and "position: absolute" in a smooth manner? I have developed a compact widget called the Deck, which has both a collapsed and expanded state. Currently, it is working well by using absolute posi ...

Customize your Bootstrap navbar dropdown to showcase menu items in a horizontal layout

I have been developing a new project that requires a navbar to be positioned at the center of the page, at the top. The current HTML code I am using is as follows... <div class="navbar navbar-inverse navbar-fixed-top center"> <div class="con ...

Conceal the calendar icon from the date-type HTML input field specifically on the Firefox

The situation at hand is quite straightforward. <input type="date /> When viewed on Firefox (both desktop and mobile), it appears as follows: https://i.stack.imgur.com/S2i0s.png While the internet provides a solution specifically for Chrome: ...

Chrome autocomplete behaves as if the input fields are disabled and cannot be clicked on

I am experiencing an unusual issue with autofill in Chrome. After logging in and then logging out of the app, the input fields (email, password) are auto-filled but appear to be frozen and unclickable. This problem does not occur every time; it only happe ...

Show divs in identical position when clicking

There are 4 section divs that need to be displayed in the center of the page when clicked, but the last one appears further down. This is likely due to the flex box nature. What is the best way to ensure all sections appear at the exact same location? Ano ...

creating an identical copy of a dynamic element's size

I am currently working on a project using react js where I need to incorporate multiple images. My goal is to have standard background divs / rectangles that match the exact size of each image, allowing for animations to be performed on top of them. The sn ...

How can I position an input element with the class "button" exactly where I need it on the webpage?

I am struggling to position my input (class="button") where I want it to be html: <div id="popup" class="overlay"> <div class="popup"> <a class="close" href="#">×</a> <div id="content"> <select required name="list" ...

Having trouble interacting with buttons while an overlay is open

When I try to use the overlay to move the text upwards and reveal buttons, I encounter an issue where I am unable to hover or click on those buttons. As soon as I try to interact with the buttons, the overlay and text come down, blocking my access. I have ...

Changing the visibility of a div with an onClick event in React

Can anyone help me figure out how to toggle the display of this div on click? I've been struggling with it for a while now. Any suggestions are welcome. https://i.sstatic.net/lPZtN.png https://i.sstatic.net/8Pybg.png ...

Can HTML/CSS be used to specifically target handheld mobile devices?

I am looking to optimize my video display in HTML by only showing it on desktop browsers. The difference in bandwidth between desktop and mobile devices is affecting the performance of mobile browsers, so I want to target only desktop users. Is there a way ...

What is the best way to customize arrow designs in a React Slick Slider?

I am struggling to customize the arrows in react-slick with my own PNG images. Despite my efforts, the images appear distorted on the screen as they are automatically set to a width and height of 20px instead of their actual size of 17x27px. I have experim ...

Having trouble adjusting the outer margin of a PDF generated with html/css in a Flutter iOS app

I am currently facing an issue with the PDF generated from Html/css in my flutter iOS app. While the layout appears fine on Android, there seems to be a problem with left margins when it comes to iOS, as illustrated in the attachment provided. For referen ...

CSS Only Sidebar Dropdown (without using Bootstrap)

I want to create a sidebar with collapsible dropdown options and smooth animations using only pure css/js/html/jquery, without relying on bootstrap like I did in the past. Here is an example of what I created previously with bootstrap: Now, as a challenge ...

Whenever I press the view button, all the cards open instead of just the one I chose from the index. Can anyone tell me where I am going wrong?

I've encountered an issue with the View buttons I added to display more detailed information about the characters in the card bodies. When I click on the view button, it opens all the boxes instead of the one I selected. I've tried using a for lo ...

Utilize the object's ID to filter and display data based on specified criteria

I retrieved an array of objects from a database and am seeking to narrow down the results based on specific criteria. For instance, I want to display results only if a user's id matches the page's correct id. TS - async getResultsForId() { ...

Modifying the overflow behavior within a Vuetify dialog

Is there a way to have a floating action button positioned on the top right of a dialog, slightly overflowing so it's offset from the dialog itself? I'm struggling to override the 'overflow-y: hidden' property set by v-dialog. <v-dia ...