I have an issue with flexbox, where the 2 flex boxes side by side, do not share an equal height when scaling the page. I'll include a picture below, but one box contains a react-bootstrap carousel, while the other contains text. How do I keep them at the same height so that they will scale on all screen sizes?
Here is the JSX
<div className={styles.floatchild1}>
<Carousel fade className={styles.viewMap}>
<Carousel.Item>
<img
className="d-block w-100"
src="/open.jpeg"
alt="Front View of HICO Storage Unit, Grand Junction Colorado"
/>
</Carousel.Item>
<Carousel.Item>
<img
className="d-block w-100"
src="/inside.jpeg"
alt="Inside of HICO Storage Unit, Grand Junction Colorado"
/>
</Carousel.Item>
<Carousel.Item>
<img
className="d-block w-100"
src="/side-view-container.jpeg"
alt="Side View of HICO Storage Unit, Grand Junction Colorado"
/>
</Carousel.Item>
</Carousel>
<Button
className={styles.viewMapButton}
href="https://www.google.com/maps/place/2487+Commerce+Blvd,+Grand+Junction,+CO+81505/#39.0906152,-108.5944703,17z/data=!3m1!4b1!4m5!3m4!1s0x87471d18f2c3486b:0xe36fb2de2017f121!8m2!3d39.0906111!4d-108.5922816"
target="_blank"
>
+ View Map
</Button>
<div className={styles.buttonIdRow}>
<p></p>
<a>Jump to:</a>
Units
</div>
</div>
<div className={styles.floatchild2}>
<p>
Self Storage in <u>Grand Junction</u>, Co
</p>
<h2 className={styles.hicoLogo}>
<b>
<u>HICO Storage Company</u>
</b>
</h2>
<div className={styles.addressPhone}>
<h3 className={styles.address}>
<div className={styles.pinPicture}>
<Image
src="/pin.png"
alt="location pin"
width={20}
height={28}
/>{" "}
</div>
<div className={styles.location}>
2487 Commerce Blvd, Grand Junction, CO 81505
</div>
</h3>
<h3 className={styles.phoneWrapper}>
<div className={styles.phonePicture}>
<Image
src="/phone.png"
alt="location pin"
width={25}
height={25}
/>{" "}
</div>
<div className={styles.phone}>
<a className={styles.phoneColor} href="tel:8088962272">
<b>808-896-2272</b>
</a>
</div>
</h3>
</div>
<hr />
<div className={styles.hours}>
<div className={styles.officeHours}>
<p className={styles.TimeTitle}>Office Hours</p>
<p className={styles.TimeP}>
8:30am - 5:30pm Monday - Saturday
</p>
<p className={styles.TimeP}>10:30am - 3:30pm Sunday</p>
</div>
<div className={styles.officeHours}>
<p className={styles.TimeTitle}>Gate Hours</p>
<p className={styles.TimeP}>24/7 access</p>
</div>
</div>
<hr />
<Button href='/contact' className={styles.interestedButton}>Interested? Contact Us</Button>
</div>
</div>
And here is the CSS I'm using to style it
.wrapper {
overflow: hidden;
min-width: 300px;
display: flex;
flex-direction: row;
width: 90%;
font-family: 'southern';
align-items: center;
}
.floatchild1{
background: white;
flex:1;
min-width: 380px;
align-items: center;
}
.floatchild2 {
background: white;
flex:1;
min-width: 380px;
align-items: center;
padding: 4%;
}
Just change
align-items: center;
at .wrapper to
align-items: stretch;
Working codepen: https://codepen.io/maty1000/pen/oNEqvGY
Related
I know there are several threads on the "overlapping images" topic, but I can't find one that addresses my specific problem.
I have five circular images and I need to display them with slight overlap, kind of like how a deck of cards looks when it's laid out in a fan.
Here is what it should look like:
Here is what I currently have:
All the code examples I've found are aimed at overlapping two square images and I can't figure out how to translate to this scenario. Any help would be greatly appreciated.
I've tried messing around with grid layout and negative margins, but it was just a huge mess.
I can't share the source code but I've recreated the exact same HTML/CSS with dummy data in this codepen.
Code:
.main-container {
height: fit-content;
padding-top: 3rem;
}
#icons-container {
display: flex;
position: relative;
justify-content: center;
}
.icon {
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid white;
}
<div class="main-container">
<div id="icons-container">
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon1" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon2" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon3" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon4" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon5" />
</div>
</div>
</div>
You can use margin-right/margin-left on the icon . To overlap, let margin-right have negative values
.main-container {
height: fit-content;
padding-top: 3rem;
}
#icons-container {
display: flex;
position: relative;
justify-content: center;
}
.icon {
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid white;
margin-right: -15px;
}
<div class="main-container">
<div id="icons-container">
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon1">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon2">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon3">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon4">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon5">
</div>
</div>
</div>
I have a three column box in css, I need it to center on the page for the desktop and then stack the columns on top of each other in 600px or less. I have everything working except having it centered on the desktop view.
I have tried adding justify-content: relative, adding a wrapper align: center and a couple other lines of code that did not work. Any help is greatly appreciated.
Here is the code I currently have:
* {
box-sizing: border-box;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 178px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
<p align="center">
<font size="5" color="336699"><strong>Great American Song Contest</strong></font>
</p>
<p align="center">
<font size="3" color="a91e21"><strong>3 Easy Ways To Enter Your Songs</strong></font>
</p>
<div class="wrapper">
<div class="row">
<div class="column">
<p>
<a href="https://www.greatamericansong.com/newsite-backup/Form-Prepage.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-online.gif" alt="" width="178" height="158"></p>
</div>
<div class="column">
<p>
<a href="https://www.greatamericansong.com/newsite-backup/Entry-Direct.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-email.gif" alt="" width="178" height="158"></p>
</div>
<div class="column">
<p>
<img src="https://www.greatamericansong.com/newsite-backup/images/submit-mail.gif" alt="" width="178" height="158">
</p>
</div>
</div>
</div>
<div align="center"> <img src="//shield.sitelock.com/shield/greatamericansong.com" id="sl_shield_image" style="cursor: pointer;" alt="SiteLock" align="middle" />
<script id="sl_shield" type="text/javascript" src="//shield.sitelock.com/sitelock.js" language="javascript"></script>
</div>
<p align="center">
<p></p>
<p align="center"><strong>* WRITERS RETAIN ALL RIGHTS TO THEIR SONGS, LYRICS & COMPOSITIONS *</strong></p>
<p>
<font size="3" color="a91e21"><strong>2021 Rules & Entry:</strong></font>
</p>
<p>The Great American Song Contest is open to songwriters, lyricists & music composers worldwide.</p>
<p align="center"><strong>* WRITERS RETAIN ALL RIGHTS TO THEIR SONGS, LYRICS & COMPOSITIONS *</strong></p>
Apply a dedicated class to the parent of those columns (in my example: class="x"), use display: flex; and justify-content: center on that, and in the media query change it to flex-direction: column (t place them below each other) and align-items: center; (to center them). And forget the floats...
* {
box-sizing: border-box;
}
.column {
width: 178px;
}
.x {
display: flex;
justify-content: center;
}
#media screen and (max-width: 600px) {
.x {
flex-direction: column;
align-items: center;
}
}
<p align="center">
<font size="5" color="336699"><strong>Great American Song Contest</strong></font>
</p>
<p align="center">
<font size="3" color="a91e21"><strong>3 Easy Ways To Enter Your Songs</strong></font>
</p>
<div class="wrapper">
<div class="x">
<div class="column">
<p>
<a href="https://www.greatamericansong.com/newsite-backup/Form-Prepage.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-online.gif" alt="" width="178" height="158"></p>
</div>
<div class="column">
<p>
<a href="https://www.greatamericansong.com/newsite-backup/Entry-Direct.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-email.gif" alt="" width="178" height="158"></p>
</div>
<div class="column">
<p>
<img src="https://www.greatamericansong.com/newsite-backup/images/submit-mail.gif" alt="" width="178" height="158">
</p>
</div>
</div>
</div>
<div align="center"> <img src="//shield.sitelock.com/shield/greatamericansong.com" id="sl_shield_image" style="cursor: pointer;" alt="SiteLock" align="middle" />
<script id="sl_shield" type="text/javascript" src="//shield.sitelock.com/sitelock.js" language="javascript"></script>
</div>
<p align="center">
<p></p>
<p align="center"><strong>* WRITERS RETAIN ALL RIGHTS TO THEIR SONGS, LYRICS & COMPOSITIONS *</strong></p>
<p>
<font size="3" color="a91e21"><strong>2021 Rules & Entry:</strong></font>
</p>
<p>The Great American Song Contest is open to songwriters, lyricists & music composers worldwide.</p>
<p align="center"><strong>* WRITERS RETAIN ALL RIGHTS TO THEIR SONGS, LYRICS & COMPOSITIONS *</strong></p>
I have the following markup which uses bootstrap 4:-
<div class="container">
<div class="row ">
<div class="col-xl-12">
<img src="~/img/img1.png" style="height:60.3px;width:750px" class="mx-auto d-none d-sm-block" />
<p style="color: #2EBDBE;font-weight:bold;font-size:13px;margin-bottom: 0px;">...</p>
<p style="color: #2EBDBE;font-weight:bold;font-size:13px;margin-bottom: 0px;">...</p>
<img src="~/img/img2.png" class="mx-auto d-block" />
<p style="color: #2EBDBE;font-weight:bold;font-size:13px;margin-bottom: 0px;">...</p>
<p style="color: #2EBDBE;font-weight:bold;font-size:13px;margin-bottom: 0px;">...</p>
</div>
</div>
</div>
Currently i got this layout:-
where the images are centered while the text is left aligned, so how i can force the text to have the same vertical alignment as the images?
Try this, but edit classes or whatever to make it work on your site:
<div class="container" style="position:relative; display:inline-block;">
<img class="mx-auto d-none d-sm-block" style="display:block; height:60.3px;width:750px" src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/close-up-of-tulips-blooming-in-field-royalty-free-image-1584131603.jpg">
<div class="text-box" style="position:relative; height:100%; text-align: center; display:flex; justify-content: center; align-items: flex-start; width: 100%;">
<p class="centeredTxt" style="display: block; color: #333;">Text is centered under image</p>
</div>
<div class="text-box" style="position:relative; height:100%; text-align: center; display:flex; justify-content: center; align-items: flex-start; width: 100%;">
<p class="centeredTxt" style="display: block; color: #333;">Text is centered under image 2</p>
</div>
</div>
Difficult to understand how this would work in your code as I don't have the complete code, but I edited my answer to better suit your request.
I'm uploading images from a rails app I have developed and inside the edit form the currently uploaded images appear in one line only:
This is the setup I have:
<div class="container-image">
<% #attachments.each do |attachment| %>
<div class="item-image">
<div class="pinImage">
<%= image_tag(attachment.image.url(:mini))%>
<p style="font-size: 13px;">
<%= link_to "Remove", remove_item_attachment_path(attachment),
data: { confirm: "Are you sure?"},
:method => :delete %></p>
</div>
</div>
<% end %>
</div>
and this is the css:
.pinImage img
width: 100%
height: auto
border: 1px solid #d9d9d9
border-radius: 6px
background-color: white
.container-image
max-width: 1200px
display: flex
align-items: center
-webkit-justify-content: center
/* Safari */
justify-content: center
.item-image
padding: 5px
display: block
But I want the images to appear aligned as an image gallery like the following. Any idea how a can fix this?
Try this updated CSS. Added flex-wrap: wrap; and removed justify-content: center from container-image div. Also remove default margins from body.
body {
margin: 0;
}
.pinImage img {
width: 100%;
height: auto;
border: 1px solid #d9d9d9;
border-radius: 6px;
background-color: white;
}
.container-image{
max-width: 1200px;
display: flex;
flex-wrap: wrap;
align-items: center;
}
.item-image{
display: block;
width: 25%;
}
<div class="container-image">
<div class="item-image">
<div class="pinImage">
<img src=""/>
<p style="font-size: 13px;">
delete
</p>
</div>
</div>
<div class="item-image">
<div class="pinImage">
<img src=""/>
<p style="font-size: 13px;">
delete
</p>
</div>
</div>
<div class="item-image">
<div class="pinImage">
<img src=""/>
<p style="font-size: 13px;">
delete
</p>
</div>
</div>
<div class="item-image">
<div class="pinImage">
<img src=""/>
<p style="font-size: 13px;">
delete
</p>
</div>
</div>
<div class="item-image">
<div class="pinImage">
<img src=""/>
<p style="font-size: 13px;">
delete
</p>
</div>
</div>
<div class="item-image">
<div class="pinImage">
<img src=""/>
<p style="font-size: 13px;">
delete
</p>
</div>
</div>
<div class="item-image">
<div class="pinImage">
<img src=""/>
<p style="font-size: 13px;">
delete
</p>
</div>
</div>
<div class="item-image">
<div class="pinImage">
<img src=""/>
<p style="font-size: 13px;">
delete
</p>
</div>
</div>
<div class="item-image">
<div class="pinImage">
<img src=""/>
<p style="font-size: 13px;">
delete
</p>
</div>
</div>
</div>
I have a flexbox grid on my website which is not displaying correctly in IE11 and Firefox.
.section-home {
float: left;
}
/*** Flex Grid ***/
.flex-grid {
display: flex;
display: -webkit-flex;
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
flex-direction: row;
-webkit-flex-direction: row;
justify-content: space-between;
-webkit-justify-content: space-between;
}
.flex-grid .flex-item {
display: flex;
display: -webkit-flex;
margin-top: 2rem;
}
<div class="section-home">
<!-- PRODUCTS -->
<div class="products-home flex-grid">
<div class="flex-item">
<div class="collection-item animated shown">
<div class="collection-wrap">
<div class="collection-image">
<a href="{{ route('cuadrospersonalizados') }}">
<img class="img-responsive" src="{{ FotImg::asset('img/fotolienzos.jpg') }}?dts={DPL_TS}" alt="Cuadros personalizados" title="Cuadros personalizados">
<span class="description">
<p>Lienzo con tus fotos colocado sobre madera de pino</p>
</span>
<div class="caption">
<h2>Fotolienzos</h2>
</div>
</a>
</div>
</div>
</div>
</div>
<div class="flex-item">
<div class="collection-item animated shown">
<div class="collection-wrap">
<div class="collection-image">
<a href="{{ route('fotolienzosconreloj') }}">
<img class="img-responsive" alt="Fotolienzos con Reloj" title="Fotolienzos con Reloj" src="{{ FotImg::asset('img/fotolienzos-con-reloj.jpg') }}?dts={DPL_TS}">
<div class="label-new">
<span class="new">novedad</span>
</div>
<span class="description">
<p>Lienzo personalizado con reloj colocado sobre bastidor de madera</p>
</span>
<div class="caption">
<h2>Fotolienzos con Reloj</h2>
</div>
</a>
</div>
</div>
</div>
</div>
<div class="flex-item">
<div class="collection-item animated shown">
<div class="collection-wrap">
<div class="collection-image">
<a href="{{ route('posterspersonalizados') }}">
<img class="img-responsive" alt="Pósters personalizados" title="Pósters personalizados" src="{{ FotImg::asset('img/posters-personalizados.jpg') }}?dts={DPL_TS}">
<span class="description">
<p>Pósters especialmente pensados para habitaciones juveniles e infantiles</p>
</span>
<div class="caption">
<h2>Pósters personalizados</h2>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
<!-- PRODUCTS -->
</div>
The flex grid displays correctly in Chrome but in IE and Firefox the items stay on one line and do not wrap. Why is this?
Your problem is that the container around .flex-grid (.section-home) is set to float: left; and has no width set. This means it will be set to width: auto; which, as it is a floated element, will mean that its content will govern how wide it is. In this case there appears to be a difference in how the browsers choose to calculate the width:
Chrome limits .section-home to the width of its parent
IE lets .section-home grow as much as it needs to accommodate all children of .flex-grid
There are a couple of ways you could tackle this, however, the simplest will be to remove float: left; from .section-home as it appears it is not needed anyway.
.section-home {
/*float: left; Remove this*/
}
/*** Flex Grid ***/
.flex-grid {
display: flex;
display: -webkit-flex;
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
flex-direction: row;
-webkit-flex-direction: row;
justify-content: space-between;
-webkit-justify-content: space-between;
}
.flex-grid .flex-item {
display: flex;
display: -webkit-flex;
margin-top: 2rem;
}
<div class="section-home">
<!-- PRODUCTS -->
<div class="products-home flex-grid">
<div class="flex-item">
<div class="collection-item animated shown">
<div class="collection-wrap">
<div class="collection-image">
<a href="{{ route('cuadrospersonalizados') }}">
<img class="img-responsive" src="{{ FotImg::asset('img/fotolienzos.jpg') }}?dts={DPL_TS}" alt="Cuadros personalizados" title="Cuadros personalizados">
<span class="description">
<p>Lienzo con tus fotos colocado sobre madera de pino</p>
</span>
<div class="caption">
<h2>Fotolienzos</h2>
</div>
</a>
</div>
</div>
</div>
</div>
<div class="flex-item">
<div class="collection-item animated shown">
<div class="collection-wrap">
<div class="collection-image">
<a href="{{ route('fotolienzosconreloj') }}">
<img class="img-responsive" alt="Fotolienzos con Reloj" title="Fotolienzos con Reloj" src="{{ FotImg::asset('img/fotolienzos-con-reloj.jpg') }}?dts={DPL_TS}">
<div class="label-new">
<span class="new">novedad</span>
</div>
<span class="description">
<p>Lienzo personalizado con reloj colocado sobre bastidor de madera</p>
</span>
<div class="caption">
<h2>Fotolienzos con Reloj</h2>
</div>
</a>
</div>
</div>
</div>
</div>
<div class="flex-item">
<div class="collection-item animated shown">
<div class="collection-wrap">
<div class="collection-image">
<a href="{{ route('posterspersonalizados') }}">
<img class="img-responsive" alt="Pósters personalizados" title="Pósters personalizados" src="{{ FotImg::asset('img/posters-personalizados.jpg') }}?dts={DPL_TS}">
<span class="description">
<p>Pósters especialmente pensados para habitaciones juveniles e infantiles</p>
</span>
<div class="caption">
<h2>Pósters personalizados</h2>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
<!-- PRODUCTS -->
</div>