I'm trying to center 4 columns inside a a row. Trying in code pen or similar works like I want, but in adobe-brackets is not working, I don't know if there is a bug or something...
Does anyone has any idea?
PD.: in my brackets output, everything is on the left.
body {
position: relative;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.container-fluid {
width: inherit;
height: inherit;
margin: 0;
padding: 0;
}
.content {
padding: 100px 0;
}
.content-2 {
color: violet;
background-color: blueviolet;
}
div.img {
margin: 5px;
float: center;
width: 180px;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
.row-centered {
text-align: center;
}
.col-centered {
display: inline-block;
float: none;
margin-right: 0 auto;
width: 90%;
}
<section class="content content-2">
<div class="container">
<div class="row row-centered">
<div class="img col-md-2 col-centered">
<img src="forest.jpg" alt="Forest">
<div class="desc">
<h3>CREATIVIDAD</h3>
<p>hhhhhhhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="forest.jpg" alt="Forest">
<div class="desc">
<h3>DISEÑO</h3>
<p>hhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="forest.jpg" alt="Forest">
<div class="desc">
<h3>MULTIMEDIA</h3>
<p>hhhhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="forest.jpg" alt="Forest">
<div class="desc">
<h3>WEB</h3>
<p>hhhhhhhhhhh</p>
</div>
</div>
</div>
</div>
</section>
Use CSS Flexbox. Apply flexbox properties to .row-centered as well as .col-centered:
.row-centered {
display: flex; /* Flex Container */
flex-wrap: wrap; /* Wrap the content to next line if required */
justify-content: center; /* Horizontally content to center */
align-items: center;
}
.col-centered {
display: flex; /* Flex Container */
flex-direction: column; /* Flex Direction - Column */
justify-content: center; /* Vertically Center Alignment */
float: none;
margin-right: 0 auto;
width: 90%;
}
Have a look at this snippet below (use full screen):
body {
position: relative;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.container-fluid {
width: inherit;
height: inherit;
margin: 0;
padding: 0;
}
.content {
padding: 100px 0;
}
.content-2 {
color: violet;
background-color: blueviolet;
}
div.img {
margin: 5px;
float: center;
width: 180px;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
.row-centered {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.col-centered {
display: flex;
flex-direction: column;
justify-content: center;
float: none;
margin-right: 0 auto;
width: 90%;
}
<section class="content content-2">
<div class="container">
<div class="row row-centered">
<div class="img col-md-2 col-centered">
<img src="http://placehold.it/30x30" alt="Forest">
<div class="desc">
<h3>CREATIVIDAD</h3>
<p>hhhhhhhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="http://placehold.it/30x30" alt="Forest">
<div class="desc">
<h3>DISEÑO</h3>
<p>hhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="http://placehold.it/30x30" alt="Forest">
<div class="desc">
<h3>MULTIMEDIA</h3>
<p>hhhhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="http://placehold.it/30x30" alt="Forest">
<div class="desc">
<h3>WEB</h3>
<p>hhhhhhhhhhh</p>
</div>
</div>
</div>
</div>
</section>
Hope this helps!
Related
I need to align the elements so that everyone in the block stands exactly without extra spaces
I do it with justify-content: center, elements are centered but look like this
enter image description here
But I need everything to be even, but at the same time it also remains in the center, without extra spaces, like this
enter image description here
important note, when the screen width is larger, the elements should not be in a column but in a row, this is now done, I deliberately reduced the width so that they do not fit
.flex {
display: flex;
justify-content: center;
margin-bottom: 24px;
flex-wrap: wrap;
width: 200px;
}
.item {
position: relative;
padding-left: 28px;
display: flex;
}
.item:not(:last-child) {
margin-right: 16px;
}
.item svg {
position: absolute;
top: 5px;
left: 0;
}
.item span {
display: block;
font-size: 16px;
line-height: 1.5;
max-width: 200px;
}
.item img {
width: 30px;
margin-left: 7px;
display: inline-block;
}
<div class="flex">
<div class="item">
<span>Australia <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Italy <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Germany <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
</div>
Add a wrapper (i.e., <div class="wrapper">), everything else can stay the same. The trick is that now the wrapper is centered.
See the snippet below.
.flex {
display: flex;
justify-content: center;
margin-bottom: 24px;
flex-wrap: wrap;
width: 200px;
border: 1px solid red;
}
.item {
position: relative;
padding-left: 28px;
display: flex;
}
.item:not(:last-child) {
margin-right: 16px;
}
.item svg {
position: absolute;
top: 5px;
left: 0;
}
.item span {
display: block;
font-size: 16px;
line-height: 1.5;
max-width: 200px;
}
.item img {
width: 30px;
margin-left: 7px;
display: inline-block;
}
<div class="flex">
<div class="wrapper">
<div class="item">
<span>Australia <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Italy <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Germany <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
</div>
</div>
EDIT 1
.flex {
display: flex;
justify-content: center;
margin-bottom: 24px;
flex-wrap: wrap;
border: 1px solid red;
}
.item {
padding-left: 28px;
display: inline-block;
}
.item:not(:last-child) {
margin-right: 16px;
}
.item svg {
position: absolute;
top: 5px;
left: 0;
}
.item span {
display: block;
font-size: 16px;
line-height: 1.5;
max-width: 200px;
}
.item img {
width: 30px;
margin-left: 7px;
}
<div class="flex">
<div class="wrapper">
<div class="item">
<span>Australia <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Italy <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Germany <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
</div>
</div>
EDIT 2
.flex {
display: flex;
justify-content: center;
margin-bottom: 24px;
flex-wrap: wrap;
border: 1px solid red;
}
.item {
padding-left: 28px;
display: inline-block;
}
.item:not(:last-child) {
margin-right: 16px;
}
.item svg {
position: absolute;
top: 5px;
left: 0;
}
.item span {
display: block;
font-size: 16px;
line-height: 1.5;
max-width: 200px;
}
.item img {
width: 30px;
margin-left: 7px;
}
#media screen and (max-width: 576px) {
.item {
display: flex;
}
}
<div class="flex">
<div class="wrapper">
<div class="item">
<span>Australia <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Italy <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Germany <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
</div>
</div>
This is because you are adding img after the text of span, not after span itself.
.flex {
display: flex;
justify-content: center;
margin-bottom: 24px;
flex-wrap: wrap;
width: 200px;
}
.item {
position: relative;
display: flex;
}
.item svg {
position: absolute;
top: 5px;
left: 0;
}
.item span {
display: block;
font-size: 16px;
line-height: 1.5;
min-width: 100px;
max-width: 200px;
}
.item img {
width: 30px;
display: inline-block;
}
<div class="flex">
<div class="item">
<span>Australia</span><img src="https://i.imgur.com/Ad3jzMI.jpg">
</div>
<div class="item">
<span>Italy</span><img src="https://i.imgur.com/Ad3jzMI.jpg">
</div>
<div class="item">
<span>Germany</span><img src="https://i.imgur.com/Ad3jzMI.jpg">
</div>
</div>
Do you mean something like this? Hope this answer helps.
You can find more information on flexbox layout here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.flex {
margin-bottom: 24px;
flex-wrap: wrap;
width: 200px;
}
.item {
position: relative;
padding-left: 28px;
}
.item .wrapper{
font-size: 16px;
line-height: 1.5;
max-width: 200px;
display: flex;
align-items: center;
text-align: left;
}
.item img {
width: 30px;
margin-left: 7px;
display: inline-block;
}
<div class="flex">
<div class="item">
<span class="wrapper"><span class='country'>Australia</span> <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span class="wrapper"><span class='country'>Italy</span> <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span class="wrapper"><span class='country'>Germany</span> <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
</div>
.flex {
display: flex;
flex-wrap: wrap;
}
.item {
margin: 0 10px 10px 0;
width: 200px;
display: flex;
justify-content: space-between;
}
.item svg {
position: absolute;
top: 5px;
left: 0;
}
.item span {
display: block;
font-size: 16px;
line-height: 1.5;
max-width: 200px;
}
.item img {
width: 30px;
margin-left: 7px;
display: inline-block;
}
<div class="flex">
<div class="item">
<span>Australia</span> <img src="https://i.imgur.com/Ad3jzMI.jpg">
</div>
<div class="item">
<span>Italy</span> <img src="https://i.imgur.com/Ad3jzMI.jpg">
</div>
<div class="item">
<span>Germany</span> <img src="https://i.imgur.com/Ad3jzMI.jpg">
</div>
</div>
<div class="flex">
<div>
<div class="item">
<span>Australia <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Italy <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
<div class="item">
<span>Germany <img src="https://i.imgur.com/Ad3jzMI.jpg"></span>
</div>
</div>
</div>
Add one more child and wrap all child elements. Its will center the inner content, still keep the child elements in same position.
I'm learning HTML and I'm working on this project where basically I'm trying to show 8 pictures inside a section with 4 each in one row. To solve this problem, I looked up how to make rows and columns without using Table (I'm not allowed to for this project).
I came across this:
* {
box-sizing: border-box;
}
/* Create four equal columns that floats next to each other */
.column {
float: left;
width: 25%;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
<h2>Four Equal Columns</h2>
<div class="row">
<div class="column" style="background-color:#aaa;">
<h2>Column 1</h2>
<p>Some text..</p>
</div>
<div class="column" style="background-color:#bbb;">
<h2>Column 2</h2>
<p>Some text..</p>
</div>
<div class="column" style="background-color:#ccc;">
<h2>Column 3</h2>
<p>Some text..</p>
</div>
<div class="column" style="background-color:#ddd;">
<h2>Column 4</h2>
<p>Some text..</p>
</div>
</div>
I used this trick and made two Rows to solve my problem. I put these two Rows inside a <section> I created myself called gallery1:
.gallery1 {
align-items: center;
justify-content: center;
margin: auto;
}
Using above code, final code looks like this:
.whitetitle {
color: white;
}
.green {
background-color: #4AB19A;
}
.gallery1 {
align-items: center;
justify-content: center;
margin: auto;
}
.gallery1 img {
border: 1px solid whitesmoke;
border-radius: 90px;
margin: 15px;
height: 150px;
width: 150px;
}
.column {
align-items: center;
justify-content: center;
float: left;
display: flex;
width: 20%;
padding: 10px;
margin: auto;
}
.row:after {
content: "";
display: table;
clear: both;
align-items: center;
justify-content: center;
margin: auto;
}
<section class=" green gallery1">
<h2 class="whitetitle"> Graphic Designing </h2>
<section class="row">
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
</section>
<section class="row">
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
</section>
</section>
So it turned out good and all but I have a problem! I want the pictures to be in the center, horizontally and vertically. To be exact, I want the title and two rows to be in center, both ways.
I tried the following
align-items: center;
justify-content: center;
margin: auto;
Inside the Gallery in CSS but it didn't work. can anyone help me on this please? what should I have done to fix/avoid this.
Also, I tried flex-box thing and put display: flex; inside Gallery but it shows everything (title and two rows) in one row which is not what I want.
Since you have two sections you can simply wrap them into one section and give it class called main then apply the flex-box centralization on it.
Here is an Example
.whitetitle {
color: white;
}
.main {
background-color: #4AB19A;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.green {
text-align: center;
background-color: #4AB19A;
}
.gallery1 {
align-items: center;
justify-content: center;
margin: auto;
}
.gallery1 img {
border: 1px solid whitesmoke;
border-radius: 90px;
margin: 15px;
height: 150px;
width: 150px;
}
.column {
align-items: center;
justify-content: center;
float: left;
display: flex;
width: 20%;
padding: 10px;
margin: auto;
}
.row:after {
content: "";
display: table;
clear: both;
align-items: center;
justify-content: center;
margin: auto;
}
<section class="main">
<section class=" green gallery1">
<h2 class="whitetitle"> Graphic Designing </h2>
<section class="row">
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
</section>
<section class="row">
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
</section>
</section>
</section>
Or you can simply achieve it with the grid-box the following is an example
.whitetitle {
color: white;
}
.green {
background-color: #4AB19A;
display: grid;
text-align: center;
}
.gallery1 {
align-items: center;
justify-content: center;
margin: auto;
}
.gallery1 img {
border: 1px solid whitesmoke;
border-radius: 90px;
margin: 15px;
height: 150px;
width: 150px;
}
.column {
align-items: center;
justify-content: center;
float: left;
display: flex;
width: 20%;
padding: 10px;
margin: auto;
}
.row:after {
content: "";
display: table;
clear: both;
align-items: center;
justify-content: center;
margin: auto;
}
<section class=" green gallery1">
<h2 class="whitetitle"> Graphic Designing </h2>
<section class="row">
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
</section>
<section class="row">
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
</section>
</section>
All lines marked with /* <-- */ are new.
.whitetitle {
color: white;
margin-left: auto; /* <-- */
margin-right: auto; /* <-- */
text-align: center; /* <-- */
}
.green {
background-color: #4AB19A;
}
.gallery1 {
align-items: center;
justify-content: center;
margin: auto;
display: flex; /* <-- */
flex-wrap: wrap; /* <-- */
align-items: center; /* <-- */
justify-content: center; /* <-- */
}
.gallery1 img {
border: 1px solid whitesmoke;
border-radius: 90px;
margin: 15px;
height: 150px;
width: 150px;
}
.column {
align-items: center;
justify-content: center;
float: left;
display: flex;
width: 20%;
padding: 10px;
margin: auto;
}
.row::after {
content: "";
display: table;
clear: both;
align-items: center;
justify-content: center;
margin: auto;
}
<section class=" green gallery1">
<h2 class="whitetitle"> Graphic Designing </h2>
<section class="row">
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
</section>
<section class="row">
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
<div class="column">
<img src="https://i.imgur.com/yX7UIXh.jpg">
</div>
</section>
</section>
I am trying to align some pictures perfectly according to their height while maintaining their ability to scale. I have made a column layout using floats in CSS. There are three columns and have equal width so they scale equally but I can't seem to make the images have optimal height so they all fit in their containers with equal height. The images in my middle column are flowing out.
.section__banner-row {
max-width: 100%;
margin: 0 auto;
}
.section__banner-row:not(:last-child) {
margin-bottom: 1rem;
}
.section__banner-row::after {
content: "";
display: table;
clear: both;
}
.section__banner-row [class^="col-"] {
float: left;
}
.section__banner-row [class^="col-"]:not(:last-child) {
margin-right: 1rem;
}
.section__banner-row .col-1-of-2 {
width: calc((99.9% - 1rem) / 2);
}
.section__banner-row .col-1-of-3 {
width: calc((99.9% - 2 * 1rem) / 3);
}
.section__inside-banner {
margin-top: 1rem;
}
.container-shadow-box {
position: relative;
overflow: hidden;
}
.container-shadow-box img {
width: 100%;
display: block;
transition: all 0.5s;
}
.container-shadow-box:hover img {
transform: scale(1.11);
}
<div class="section__banner-row">
<div class="col-1-of-3">
<div class="container-shadow-box">
<img src="https://i.ibb.co/FhQFN40/blog-masonry-01.jpg" alt="Masonry 1">
</div>
</div>
<div class="col-1-of-3">
<div class="container-shadow-box">
<img src="https://i.ibb.co/0JHHwbm/blog-masonry-02.jpg" alt="Masonry 2">
</div>
<div class="section__inside-banner">
<div class="col-1-of-2">
<div class="container-shadow-box">
<img src="https://i.ibb.co/NycZ9KN/blog-masonry-03.jpg" alt="Masonry 3">
</div>
</div>
<div class="col-1-of-2">
<div class="container-shadow-box">
<img src="https://i.ibb.co/qRNZm1q/blog-masonry-04.jpg" alt="Masonry 4">
</div>
</div>
</div>
</div>
<div class="col-1-of-3">
<div class="container-shadow-box">
<img src="https://i.ibb.co/PmcznpR/blog-masonry-05.jpg" alt="Masonry 5">
</div>
</div>
</div>
Flexbox example:
body * {
box-sizing: border-box;
}
.grid-box {
padding-bottom: 28%; /* adjust this for container aspect ratio */
height: 0;
position: relative;
background: pink;
}
.section__banner-row {
display: flex;
}
.section__banner-row.outer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: 5px;
}
.section__banner-row .col {
flex: 1 1 auto;
display: flex;
flex-direction: column;
justify-content: stretch;
align-items: stretch;
}
.section__banner-row .col > div {
flex-basis: 50%;
flex-grow: 1;
}
.container-shadow-box {
margin: 10px;
height: 100%;
background: #ddd;
}
.container-shadow-box>div {
background-size: cover;
height: 100%;
}
<div class="grid-box">
<div class="section__banner-row outer">
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/FhQFN40/blog-masonry-01.jpg);"></div>
</div>
</div>
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/0JHHwbm/blog-masonry-02.jpg);"></div>
</div>
<div class="section__banner-row">
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/NycZ9KN/blog-masonry-03.jpg);"></div>
</div>
</div>
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/qRNZm1q/blog-masonry-04.jpg);"></div>
</div>
</div>
</div>
</div>
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/PmcznpR/blog-masonry-05.jpg);"></div>
</div>
</div>
</div>
</div>
Fiddle demo
Does my browser support flexbox?
I am using a centred div to contain an image and some text but want my title to have the same margin/alignment as the text. Right now the title is placed on the extreme left of the page and I want it to have a responsive margin on the left.
.row {
margin: auto;
max-width: 1150px;
display: flex;
align-items: center;
img {
width: auto;
}
}
<div class="container-fluid">
<h1>Choosing a Console</h1>
<div class="row">
<div class="col-sm" id="textbox">
<p>
Some Text
</p>
</div>
<div class="col-sm" id="img">
<img style="height: 350px" src="which.png" alt="Which One">
</div>
</div>
</div>
there are two ways you could do this;
Add margin-left to the div h2 tag or add a container
.row {
margin: auto;
max-width: 1150px;
display: flex;
align-items: center;
img {
width: auto;
}
}
.container-fluid h1 {
margin-left: 150px;
}
or you can over complicate it like I do and contain containers, I have added border outlines so you understand what that container is containing, if you wish to move the h1 and p text, you can margin-left them both.
.row {
max-width: 1150px;
height: auto;
border: 1px solid red;
}
.rowTextContainer {
float: left;
width: auto;
margin-left: 50px;
}
.rowText {
text-align: center;
border: 1px solid blue;
}
.row img {
width: auto;
padding-left: 20px;
}
<div class="row">
<div class="rowTextContainer">
<div class="rowText">
<h1>Title Text</h1>
<p>Text here.</p>
</div>
</div>
<img src="https://via.placeholder.com/350.png">
</div>
.row {
margin: auto;
max-width: 1150px;
display: flex;
flex-direction: column;
align-items: center;
}
.col-sm {
display: flex;
flex-direction: row;
margin-left: 10%;
}
img {
width: auto;
margin-left: 10px;
}
<div class="container-fluid">
<h1>Choosing a Console</h1>
<div class="row">
<div class="col-sm" id="textbox">
<p>
Some Text go ahead . . . . .
</p>
<img style="height: 350px" src="https://picsum.photos/200" alt="Which One">
</div>
</div>
</div>
I hope it will solve your problem.
I have a series of flexbox items that contain an image and content. I'd like to alternate which side of the flexbox item the image appears (i.e., the left side of the box in one, the right side in the next). I can't seem to get it to work. Any suggestions are appreciated!
CSS
.offerings {
width: 100%;
height: auto;
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: flex-start;
align-items: stretch;
}
.offeringsItem {
width: 90%;
height: auto;
margin: 10px;
padding: 15px;
border: 2px solid #dedede;
}
.offeringsContent {
margin: 10px;
position: relative;
}
.offeringsImg {
margin: 10px;
float: left;
}
.offeringsImg img {
max-width: 100%;
height: auto;
display: block;
}
.offeringsImg:nth-of-type(odd) img {
float: right;
}
.offeringsImg:nth-of-type(even) img {
float: left;
}
HTML
<div class="offerings">
<div class="offeringsItem">
<div class="offeringsImg">
<img src="https://s3.amazonaws.com/tpd-files/images/Artboard-2.png">
</div>
<div class="offeringsContent">
Hi.
</div>
</div>
<div class="offeringsItem">
<div class="offeringsImg">
<img src="https://s3.amazonaws.com/tpd-files/images/Artboard-2.png">
</div>
</div>
If you are about using flex, i believe using it on .offeringsItem is plenty enough. and flex-flow:row-reverse will do the job.
.offeringsItem {
display: flex;
flex-wrap: wrap;
margin: 10px;
padding: 15px;
border: 2px solid #dedede;
}
.offeringsItem:nth-of-type(odd) {
flex-flow: row-reverse;
}
.offeringsContent,
.offeringsImg {
margin: 10px;
}
.offeringsContent {
flex: 1;
}
.offeringsImg img {
max-width: 100%;
}
<div class="offerings">
<div class="offeringsItem">
<div class="offeringsImg">
<img src="https://s3.amazonaws.com/tpd-files/images/Artboard-2.png">
</div>
<div class="offeringsContent">
Hi.
</div>
</div>
<div class="offeringsItem">
<div class="offeringsImg">
<img src="https://s3.amazonaws.com/tpd-files/images/Artboard-2.png">
</div>
<div class="offeringsContent">
Hi.
</div>
</div>
</div>
I 'have removed some styles that did not seem necessary, it also makes the CSS update easier to read ;)
Do you want something like this?
The CSS class should be corrected to.
.offeringsItem:nth-of-type(odd) img {
float: right;
}
.offeringsItem:nth-of-type(even) img {
float: left;
}
Instead of applying on the div with the class offeringsImg, you need to apply the nth-of-type() selecor to the div with the class offeringsItem because only these elements have a common parent and the index will be taken properly, before they had separate parents hence it did not work!, One more correction is that you had missed the final closing div in the HTML.
.offerings {
width: 100%;
height: auto;
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: flex-start;
align-items: stretch;
}
.offeringsItem {
width: 90%;
height: auto;
margin: 10px;
padding: 15px;
border: 2px solid #dedede;
}
.offeringsContent {
margin: 10px;
position: relative;
}
.offeringsImg {
margin: 10px;
}
.offeringsImg img {
max-width: 100%;
height: auto;
display: block;
}
.offeringsItem:nth-of-type(odd) img {
float: right;
}
.offeringsItem:nth-of-type(even) img {
float: left;
}
<div class="offerings">
<div class="offeringsItem">
<div class="offeringsImg">
<img src="https://s3.amazonaws.com/tpd-files/images/Artboard-2.png">
</div>
<div class="offeringsContent">
Hi.
</div>
</div>
<div class="offeringsItem">
<div class="offeringsImg">
<img src="https://s3.amazonaws.com/tpd-files/images/Artboard-2.png">
</div>
</div>
<div class="offeringsItem">
<div class="offeringsImg">
<img src="https://s3.amazonaws.com/tpd-files/images/Artboard-2.png">
</div>
</div>
</div>
Instead of using float, try using margin-left: auto and margin-right: auto on the boxes with your images