I am trying to set three images in horizontal but the images always comes out vertically
I have took reference from internet but still I cant solve this problem can someone please help me how to set it horizontally
.categories{
margin: 70px 0;
}
.col-3{
flex-basis: 30%;
min-width: 250px;
margin-bottom: 30px;
}
.col-3 img{
width: 100%;
}
.small-container{
max-width: 1080px;
margin: auto;
padding-left: 25px;
padding-right: 25px;
}
<div class="categories">
<div class="small-container">
<div class="row">
<div class="col-3">
<img src="assets/offer.jpg">
<div class="col-3">
<img src="assets/offer2.jpg">
<div class="col-3">
<img src="assets/offer3.jpg">
</div>
</div>
if you are not using Bootstrap try this code
.categories{
margin: 70px 0;
}
.col-3{
flex-basis: 30%;
min-width: 250px;
margin-bottom: 30px;
}
.col-3 img{
width: 100%;
}
.small-container{
max-width: 1080px;
margin: auto;
padding-left: 25px;
padding-right: 25px;
}
.row{
flex-direction: row!important;
display:flex;
}
<div class="categories">
<div class="small-container">
<div class="row">
<div class="col-3">
<img src="assets/offer.jpg">
</div>
<div class="col-3">
<img src="assets/offer2.jpg">
</div>
<div class="col-3">
<img src="assets/offer3.jpg">
</div>
</div>
</div>
</div>
I list out some changes in your code
Close Every Divisions <div></div>
add row class like this
.row{
flex-direction: row!important;
display:flex;
}
if you are using bootstrap
Close Every Divisions <div></div>
add class in your HTML d-flex flex-row
like this
<div class="categories">
<div class="small-container">
<div class="d-flex flex-row">
<div class="col-3">
<img src="assets/offer.jpg">
</div>
<div class="col-3">
<img src="assets/offer2.jpg">
</div>
<div class="col-3">
<img src="assets/offer3.jpg">
</div>
</div>
</div>
</div>
The problem: I see you have used the flex-basis property. This property belongs to Flexbox and only works with Flex elements.
The solution:
You need to make .row a flex container like so:
.row {
display: flex;
}
By the way, your 2nd and 3rd col-3 don't have an ending tag. Please close them using an ending tag.
Some resources to learn Flexbox:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://flexboxfroggy.com
Related
This question already has answers here:
Centering in CSS Grid
(9 answers)
Closed 1 year ago.
I am making my first html/css website and I have the start of a skeleton with placeholder images and icons. I want the icons with text, to each be centered within their respective column. I'm using a CSS grid to set up the columns.
.content-items-wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.content-item-wrapper {
position: relative;
}
.content-img-background {
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.img-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100px;
padding-right: 100px;
}
<div class="master-content-wrapper">
<div class="content-items-wrapper">
<div class="content-item-wrapper">
<div class="content-img-background" style="background-image: URL(images/blue-placeholder.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/wrench-placeholder.png">
</div>
<div class="subtitle">
Services
</div>
</div>
</div>
<div class="content-item-wrapper">
<div class="content-img-background" style="background-image:URL(images/white-placeholder.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/computer-placeholder.png">
</div>
<div class="subtitle">
Technicians
</div>
</div>
</div>
<div class="content-item-wrapper">
<div class="content-img-background" style="background-image:URL(images/red-placeholder.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/paper-placeholder.png">
</div>
<div class="subtitle">
Reviews
</div>
</div>
</div>
</div>
I tried different paddings and tweaking some other things but it never gets exactly in the center of the three vertical columns. The icon with text I'm referring to is the ".img-text-wrapper" div.
If we put some background color and border to some of the elements we can more clearly see what is going on:
The absolutely positioned elements' contents are centered within themselves but not within their parent elements. To achieve that we need to display the parents as flex with justification and alignment centered. Also, the div giving the background to each of these elements does not seem to have any particular meaning other than providing a background image so that is removed and the background is put on the parent in this snippet which gives this result (on wide screens see note):
.content-items-wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.content-item-wrapper {
position: relative;
border-style: solid;
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-color: pink;
display: flex;
justify-content: center;
align-items: center;
}
.content-img-background {
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-color: pink;
}
.img-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100px;
padding-right: 100px;
background-color: lime;
}
<div class="master-content-wrapper">
<div class="content-items-wrapper">
<div class="content-item-wrapper" style="background-image: URL(images/blue-placeholder.jpg)">
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="https://i.stack.imgur.com/Iynpe.jpg">
</div>
<div class="subtitle">
Services
</div>
</div>
</div>
<div class="content-item-wrapper" style="background-image:URL(images/white-placeholder.jpg)">
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="https://i.stack.imgur.com/Iynpe.jpg">
</div>
<div class="subtitle">
Technicians
</div>
</div>
</div>
<div class="content-item-wrapper" style="background-image:URL(images/red-placeholder.jpg)">
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="https://i.stack.imgur.com/Iynpe.jpg">
</div>
<div class="subtitle">
Reviews
</div>
</div>
</div>
</div>
(Note that on smaller displays the cells shrink to fit - this needs correction for full responsiveness - the square can't be given a fixed px dimension)
Sorry i removed a lot of the css as this is not necessary for the answer.
.content-img-background {
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.column {
float: left;
width: 30%;
}
div {
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="column">
<div style= "background-image: URL(images/blue-placeholder.jpg)">
<img src="images/wrench-placeholder.png">
</div>
<div class="subtitle">
Services
</div>
</div>
<div class="column">
<div style= "background-image:URL(images/white-placeholder.jpg)">
<img src="images/computer-placeholder.png">
</div>
<div class="subtitle">
Technicians
</div>
</div>
<div class="column">
<div style= "background-image:URL(images/red-placeholder.jpg)">
<img src="images/paper-placeholder.png">
</div>
<div class="subtitle">
Reviews
</div>
</div>
</div>
</div>
</body>
</html>
I'm working on a project, and I'm trying to get a fixed div container so that I can have all pictures in the div container and they will have the same size. I tried many suggested ways, but somehow it does not do anything to my div container. Nothing at all. I'm not 100% sure but I assume it's because I use bootstrap? Why am I not able to change the size?
[image1][image2]
[ image3 ]
This is how I try to have a fixed size div, but what my css does is still:
[image1][image2]
[image3]
.imagesContainer {
max-width: 200px;
max-height: 100px;
overflow: hidden;
}
.imagesContainer img {
width: 100%;
min-height: 100%;
}
<div class="album">
<div class="imagesContainer">
<div class="row justify-content-center mt-3">
<div class="col-4 px-2">
<img src="https://via.placeholder.com/150" class="img-fluid" alt="1">
</div>
<div class="col-4 px-2">
<img src="https://via.placeholder.com/150" class="img-fluid" alt="1">
</div>
</div>
</div>
<div class="imagesContainer">
<div class="row">
<div class="col mt-3"></div>
<div class="col mt-3"><img src="https://via.placeholder.com/300" alt="3"></div>
<div class="col mt-3"></div>
</div>
</div>
</div>
If you are trying to stick to Bootstrap, this solution might help
.album {
display: flex;
align-items: center;
justify-content: center;
}
.imagesContainer {
max-width: 400px;
max-height: 700px;
overflow: hidden;
}
.imagesContainer img {
width: 100%;
min-height: 100%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="album">
<div class="imagesContainer">
<div class="row mt-3">
<div class="col px-2">
<img src="https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images02.jpg" class="img-fluid" alt="1">
</div>
<div class="col px-2">
<img src="https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images02.jpg" class="img-fluid" alt="1">
</div>
</div>
<div class="row mt-3">
<div class="col"><img src="https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images02.jpg" alt="3"></div>
</div>
</div>
</div>
You can use your own styles rather than bootstraps. So you can have 3 separate divs inside the main div and set the images as the background images. With the three separate divs, you can use display- flex on the overall image container and have them be responsive and meet your designs. Here is what I mean and I hope it helps.
.imagesContainer {
width: 800px;
height: 700px;
display: flex;
flex-wrap: wrap;
}
//overall image container
.imagesContainer {
width: 800px;
height: 700px;
display: flex;
flex-wrap: wrap;
}
//individual image div
.imageDiv {
background-image: url(${Image});
background-position: center;
background-repeat: no-repeat;
background-size: cover;
flex: 1 1 400px;
}
You can add an additional class name to the last image container and have it specifically change the background size to contain as so if you want it to stretch and fill out the empty space
.lastImageContainer{
background-size: contain;
}
Trying to create a 2 column, 3 row flexbox container for a food menu. The product elements (which should be 2 per row) do not wrap when shrunk. I'm looking for a way to create a wrapping layout using flexbox. Also, what would be the best way to use Media Queries for the product title to be displayed when the layout is shrunk for mobile-size?
I'm attaching my jsfiddle code:
https://jsfiddle.net/5ksd34nf/#&togetherjs=Ix1LEBTca6
(keep in mind without the images, the design changes so I'm attaching photos)
The HTML is:
`
<section class="menu-page" id="Menu">
<div class="TitleWrapper">
<h1 class="title">Menu</h1>
</div>
<div class="menu-list">
<div class="product">
<div class="imgwrapper">
<img src="images/burger.jpg" alt="Burger" class="food-image">
</div>
<div class="text">
<div class="product-content">
<h3 class="name">Burgers</h3>
<h3 class="price">10 €</h3>
</div>
<div class="ptags">
<p class="allergens">Allergens:</p>
<p class="info">Milk, Gluten</p>
</div>
</div>
</div>
How can I space out the Price from the Name using flexbox?
Basically, you can do something like this:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.flex-container {
display: flex;
flex-wrap: wrap;
}
.flex-item {
border: 1px solid gray;
width: 100%;
margin-bottom: 20px;
}
.flex-sub-item {
display: flex;
justify-content: space-between;
}
#media screen and (min-width: 400px) {
.flex-item {
width: calc((100% - 20px) / 2);
margin-right: 20px;
}
.flex-item:nth-child(2n) {
margin-right: 0;
}
}
<div class="flex-container">
<div class="flex-item">
<div class="flex-sub-item">
<div>Title</div>
<div>Price</div>
</div>
</div>
<div class="flex-item">
<div class="flex-sub-item">
<div>Title</div>
<div>Price</div>
</div>
</div>
</div>
I have a wrapper with two boxes in it. The boxes are each to other. In the boxes there is a title (optional) and a content. I have two cases. First case: One of the boxes has a title the other hasn't. Second case: Both boxes have a title. If you take a look on the example for the second case (both titles), the boxes and titles are aligned on the bottom of the wrapper, and the titles are also aligned. There is also an example for the first case (one box without title). Because of the missing title, the alignment isn't correct yet. Here is a screenshot of the problem:
So what I tried is, to figure out the missing space for the first case, which was 21px. After this I select in CSS the second box and add the missing space. For the second case with both title, I tried to add a modifier class on the box and remove the margin-top. So default there would be a space on the second box if no title (this title is optional) and if both titles are avalable, a class should remove it again. Thats the part of the code:
.box + .box {
margin-top: 21px;
}
.box--with-title {
margin-top: 0;
}
Now with my idea it doesn't work. The first case is solved, but my class is not removing the margin. So now the alignment for the second case is wrong. Any ideas how to solve that the class is removing the margin or is there a bether way to do this with pure CSS? Hope this is clear enough.
.wrapper {
display: flex;
justify-content: space-betweet;
width: 500px;
background-color: lightgray;
;
margin-top: 36px;
}
.box {
display: flex;
flex-direction: column;
width: 50%;
}
.box__content {
width: 120px;
height: 100px;
background-color: lightcoral;
}
.box+.box {
margin-top: 21px;
}
.box--with-title {
margin-top: 0;
}
<div class="wrapper">
<div class="box">
<h3>I have a title!</h3>
<div class="box__content"></div>
</div>
<div class="box">
<h3></h3>
<div class="box__content"></div>
</div>
</div>
<div class="wrapper">
<div class="box">
<h3>I have a title!</h3>
<div class="box__content"></div>
</div>
<div class="box box--with-title">
<h3>I have also a title!</h3>
<div class="box__content"></div>
</div>
</div>
Simply use align-items:flex-end on the container and no need to consider margin:
flex-end
The cross-end margin edge of the flex item is flushed with
the cross-end edge of the line. ref
.wrapper {
display: flex;
justify-content: space-between;
align-items:flex-end;
width: 500px;
background-color: lightgray;
;
margin-top: 36px;
}
.box {
display: flex;
flex-direction: column;
width: 50%;
}
.box__content {
width: 120px;
height: 100px;
background-color: lightcoral;
}
<div class="wrapper">
<div class="box">
<h3>I have a title!</h3>
<div class="box__content"></div>
</div>
<div class="box">
<div class="box__content"></div>
</div>
</div>
<div class="wrapper">
<div class="box">
<h3>I have a title!</h3>
<div class="box__content"></div>
</div>
<div class="box box--with-title">
<h3>I have also a title!</h3>
<div class="box__content"></div>
</div>
</div>
By the way your intial code was almost good, you are simply facing a specificity issue which make the rule of .box--with-title not being considered. You may do something like this instead:
.wrapper {
display: flex;
justify-content: space-betweet;
width: 500px;
background-color: lightgray;
;
margin-top: 36px;
}
.box {
display: flex;
flex-direction: column;
width: 50%;
}
.box__content {
width: 120px;
height: 100px;
background-color: lightcoral;
}
.box+.box {
margin-top: 21px;
}
.box.box--with-title {
margin-top: 0;
}
<div class="wrapper">
<div class="box">
<h3>I have a title!</h3>
<div class="box__content"></div>
</div>
<div class="box">
<h3></h3>
<div class="box__content"></div>
</div>
</div>
<div class="wrapper">
<div class="box">
<h3>I have a title!</h3>
<div class="box__content"></div>
</div>
<div class="box box--with-title">
<h3>I have also a title!</h3>
<div class="box__content"></div>
</div>
</div>
I have made a website where the homepage looks like the this :
I want to move the ficstore logo in the middle and split the bar into two halves and put one on either side , like this :
I've split my bar image into two different parts for each side and tried to put the images in different columns. But it just doesn't seem to work.
This is the snippet for the current code :
<div class="container">
<div class="row">
<div class="col-xs-8">
<h2 style="font-family:helvetica;"><span>Home Page</span></h2>
</div>
<div class="col-xs-4">
<img src="http://lorempixel.com/400/200/" class="img-responsive right" style="width:400px; z-index:1;" />
</div>
<img src="http://lorempixel.com/400/200/" class="img-responsive right" style="position: absolute; margin-top: 135px; z-index: -2;" />
</div>
<hr class="style18" />
Can someone help?
I've tried the following code as well :
<div class="container">
<div class="row">
<div class="col-xs-8">
<h2 style="font-family:helvetica;"><span>Book Info</span></h2>
</div>
<div class="flex-row">
<div>
<img src="http://lorempixel.com/400/200/" class="img-responsive right" style="width:400px; z-index:1;" />
</div>
<div>
<img src="http://lorempixel.com/400/100/" class="img-responsive right" style="position: absolute; margin-top: 135px; z-index: -2;" />
</div>
<div>
<img src="http://lorempixel.com/400/100/" class="img-responsive right" style="position: absolute; margin-top: 135px; z-index: -2;" />
</div>
</div>
</div>
<hr class="style18" />
Css :
.flex-row {
display: flex;
align-items: center;
justify-content: center;
}
This is a great time to use flex:
HTML:
<div class='flex-row'>
<div><img src="left.png"></div>
<div><img src="center.png"></div>
<div><img src="right.png"></div>
</div>
CSS:
.flex-row {
display: flex;
align-items: center;
justify-content: center;
}
This is one way to do it. I would encourage you to ditch whatever framework you are using. col-x-whatever is bad news bears.
Here's a fiddle too - with an inline-block way.
https://jsfiddle.net/sheriffderek/fcwyg0zb/
inline-block
.images {
text-align: center;
}
.images .image-w {
display: inline-block;
vertical-align: middle;
}
flexbox
.image-w img {
display: block;
width: 100%;
height: auto;
}
.one {
max-width: 200px;
}
.two {
max-width: 400px;
margin: 0 1rem;
}
.three {
max-width: 200px;
}
.images {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
<section class='images'>
<div class='image-w one'>
<img src='https://placehold.it/300x150' alt='left'>
</div>
<div class='image-w two'>
<img src='https://placehold.it/600x300' alt='center'>
</div>
<div class='image-w three'>
<img src='https://placehold.it/300x150' alt='right'>
</div>
</section>
I suggest you have to have 3 images. The bar should divided in two. Put the Fictore in the middle then add display:block.