logo
Tags down

shadow

css vertical center two divs


By : keimura
Date : May 03 2020, 07:30 AM

I need to vertically center the content of two div's (image-container & text-container) that I am align side-by-side one another using flex. The frist div on the left contains a fixed image, the contents of div on the right is variable - it may contain a single div or many divs.

Here is my html code:

.alert-container {
  display: flex;
  justify-content: start;
  min-width: 100%;
  min-height: 3rem;
  margin: 0;
  padding: 0 0 0 5px;
  border: 1px solid rgb(243, 165, 70);
  border-radius: 5px;
  background-color: #FEE1BD;
}

.image-container {
  /* this seems to work */
  display: flex;
  align-items: center;
}

.text-container {
  /* I cannot figure out what to do here to vertically center the contents.
   Also, the child divs inside this container need to each be on their own 
   row. */
}

img {
  max-height: 70px;
}

The content inside the
parent div is variable
there may be 1, 2, 3, or more divs
The content inside the
parent div is variable
there may be 1, 2, 3, or more divs
...
...
...
...
...

Answer :

alignment is to be made from parent , else you can use margin or align-self.

try this code :

.alert-container {
  display: flex;
  justify-content: start;
  min-width: 100%;
  min-height: 3rem;
  margin: 0;
  padding: 0 0 0 5px;
  border: 1px solid rgb(243, 165, 70);
  border-radius: 5px;
  background-color: #FEE1BD;
  align-items: center;
}


/* flex children 


.image-container {
}

.text-container {

}
*/

img {
  max-height: 70px;
}

i.fa {
  font-size: 70px;
  color: tomato;
  padding: 0.2em
}

The content inside the
parent div is variable
there may be 1, 2, 3, or more divs
The content inside the
parent div is variable
there may be 1, 2, 3, or more divs
...
...
...s
...
...



Share : facebook icon twitter icon
Related Posts Related Posts :
  • clear array after form submit
  • pass url variable to javascript
  • access data using api
  • div position fixed css
  • add horizontal line between two div
  • disable toggle button css
  • css fixed line height
  • background image not working
  • table cell border
  • text line break css
  • overlay div on div
  • text direction rtl css
  • javascript convert string to an object
  • bind inner div click to outer div
  • jquery ajax oncomplete
  • how to use promise in for loop
  • jquery get element using variable
  • javascript send textbox value
  • pass div class content to another class or id
  • css new line after element
  • css calc not working properly
  • link disabled jquery
  • sql join table to subquery
  • MS Access SQL Issue with OR AND Operators
  • set textarea value using php
  • php merge two arrays into one
  • php form with google captcha
  • update current row in php
  • php date format mysql
  • mysql pdo select query
  • php function return an array
  • PHP mysqldump database to sql file
  • display image query
  • php create array using foreach loop
  • associative array php
  • group_concat in mysql laravel
  • php array_push empty
  • mysql on update cascade not working
  • pdo insert prepared statement
  • mysql insert ignore vs on duplicate key
  • mysql insert into existing row
  • mysql multi insert query
  • mysql group by show all rows
  • php change profile image
  • combine multiple arrays into one array php
  • how to sum values in an array
  • how to get sum of the total time
  • How to Create Facebook live stream without notification using API ?
  • on button click make div visible
  • css affect another element on hover
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org