Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css flex is changing image size [duplicate]

Tags:

html

css

flexbox

I am using the css flex to layout a series of 3 lines of logos. They are all the same size apart from two in the last line which are a bit deeper.

All the logos in the last line are being stretched to be the same depth, ie that of the deeper pair.

images are stretched

Image shows that the logos 1,3 and 5 have been stretched vertically

How do I stop this please.

    .brandLogos div{
      display:flex;
      display:-webkit-flex;	
      flex-flow: wrap;
      -webkit-flex-flow: wrap;
      -webkit-justify-content: space-between;
      justify-content: space-between; 	
    }
    
    .brandLogos img {
      border:1px solid green;
      margin-right:10px;
      margin-bottom:30px;
    }
    
    <div class="brandLogos">
     <div>
     .. 10 previous images 
      <img src="/uploads/2017/03/santander.jpg" alt="santander logo" width="134" height="70" />
      <img src="/uploads/2017/03/Sony.jpg" alt="" width="134" height="119" />
      <img src="/uploads/2017/03/talktalk.jpg" alt="talktalk logo" width="134" height="70" /> 
      <img src="/uploads/2017/03/unilever.jpg" alt="unilever logo" width="134" height="119" />
      <img src="/uploads/2017/03/Warburtonslogo.jpg" alt="warburtons logo" width="134" height="70" />
     </div>
    </div>
like image 458
maxelcat Avatar asked Mar 20 '17 12:03

maxelcat


People also ask

Does Flex basis work on images?

By default, everything has flex-basis:auto , which in this case means that each flex item starts out its flexing at its image's intrinsic width. So your huge-image flex items have a huge flex basis, and your small-image flex items have a small flex basis.

How do I fix my Flexbox size?

A flexbox item can be set to a fixed width by setting 3 CSS properties — flex-basis, flex-grow & flex-shrink. flex-basis : This property specifies the initial length of the flex item. flex-grow : This property specifies how much the flex item will grow relative to the rest of the flex items.

Does Flex-Shrink work on images?

You can easily shrink an image by using the flex-wrap property in CSS and it specifies whether flex items are forced into a single line or wrapped onto multiple lines.


2 Answers

You need to set the align-items: center;, which by default is stretch

Example

.brandLogos div{
  display:flex;
  display:-webkit-flex; 
  flex-flow: wrap;
  -webkit-flex-flow: wrap;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  align-items: center;
  -webkit-align-items: center;
}

More info: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

like image 162
SKeurentjes Avatar answered Oct 06 '22 18:10

SKeurentjes


Use align-items on the container.

Possible values are:

  • flex-start
  • flex-end
  • center
  • baseline

stretch is the default.

FYI: http://devdocs.io/css/align-items

like image 27
Niek Nijland Avatar answered Oct 06 '22 19:10

Niek Nijland