align center with all padding - html

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.

Related

Using "justify-content: center" despite using flex-end on parent flex container

I am trying to achieve something like this:
As you can see, the "TITLE" should be centered, whilst the little boxes in the top right corner should be set to flex-end.
After having tried it myself, I wasn't able to achieve what I desired, because the title is also set to flex-end.
Is there any way to do this using flex, and if not, what else could I do to achieve this, whilst also making it somewhat responsive.
Here is a snippet of my HTML and CSS:
#boxContainer {
display: flex;
flex-flow: row;
justify-content: space-evenly;
align-items: center;
height: 120vh;
width: 100%;
background-color: gray;
padding-top: 20vh;
}
.box { /* parent container */
display: flex;
position: static;
justify-content: flex-end;
}
.boxImg {
max-width: 20vw;
height: 70vh;
}
.boxTitle {
position: absolute;
text-align: center;
align-self: center;
font-size: 2.5em;
font-weight: bold;
color: white;
}
.topRightBox {
max-width: 2.5vw;
height: 5vh;
position: absolute;
align-self: flex-start;
margin: 0.5% 0.5% 0 0;
}
<div id="boxContainer">
<div class="box">
<img class="boxImg" src ="https://wallpapercave.com/wp/wp5389930.jpg" alt="giraffe">
<div class="boxTitle">TITLE</div>
<img class="topRightBox" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1" alt="square">
</div>
<div class="box">
<img class="boxImg" src ="https://wallpapercave.com/wp/wp5389930.jpg" alt="giraffe">
<div class="boxTitle">TITLE</div>
<img class="topRightBox" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1" alt="square">
</div>
<div class="box">
<img class="boxImg" src ="https://wallpapercave.com/wp/wp5389930.jpg" alt="giraffe">
<div class="boxTitle">TITLE</div>
<img class="topRightBox" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1" alt="square">
</div>
<div class="box">
<img class="boxImg" src ="https://wallpapercave.com/wp/wp5389930.jpg" alt="giraffe">
<div class="boxTitle">TITLE</div>
<img class="topRightBox" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1" alt="square">
</div>
</div>
Codepen
Thanks in advance.
You can use this code.
For responsive put your style in this block:
#media (max-width: 768px) {}
#boxContainer {
display: flex;
flex-direction: row;
max-width: 1200px;
margin: 0 auto;
}
.box {
position: relative;
width: 23%;
margin: 1%;
border: 1px solid #333;
min-height: 300px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.boxImg {
width: 100%;
}
.topRightBox {
width: 30px;
height: 30px;
border: 1px solid #333;
position: absolute;
top: 5px;
right: 5px;
}
.boxTitle {
position: absolute;
font-size: 2.5em;
font-weight: bold;
color: white;
}
#media (max-width: 768px) {
#boxContainer {
flex-direction: column;
}
.box {
width: 90%;
margin: 0 auto 20px;
}
}
<div id="boxContainer">
<div class="box">
<img alt="giraffe" class="boxImg" src="https://wallpapercave.com/wp/wp5389930.jpg">
<div class="boxTitle">TITLE</div>
<img alt="square"
class="topRightBox"
src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1">
</div>
<div class="box">
<img alt="giraffe" class="boxImg" src="https://wallpapercave.com/wp/wp5389930.jpg">
<div class="boxTitle">TITLE</div>
<img alt="square"
class="topRightBox"
src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1">
</div>
<div class="box">
<img alt="giraffe" class="boxImg" src="https://wallpapercave.com/wp/wp5389930.jpg">
<div class="boxTitle">TITLE</div>
<img alt="square"
class="topRightBox"
src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1">
</div>
<div class="box">
<img alt="giraffe" class="boxImg" src="https://wallpapercave.com/wp/wp5389930.jpg">
<div class="boxTitle">TITLE</div>
<img alt="square"
class="topRightBox"
src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1">
</div>
</div>
Im not sure how to do with with flexbox, but using this code for the .topRightBox achieves the same thing:
.box { /* parent container */
display: flex;
position: relative;
just
.topRightBox {
width: 30px;
height: 30px;
border: 1px solid #333;
position: absolute;
top: 5px;
right: 5px;
}
You can use top and right properties for topRightBox. I specified codes that were added. also, I deleted some codes:
#boxContainer {
display: flex;
flex-flow: row;
justify-content: space-evenly;
align-items: center;
height: 120vh;
width: 100%;
background-color: gray;
padding-top: 20vh;
}
.box {
/* parent container */
flex-basis: 20%;/*here*/
display: flex;
justify-content: center;/*here*/
position: relative;/*here*/
}
.boxImg {
width: 100%;/*here*/
height: 70vh;
}
.boxTitle {
position: absolute;
align-self: center;
font-size: 2.5em;
font-weight: bold;
color: white;
}
.topRightBox {
position: absolute;
top: 5px; /*here*/
right: 5px; /*here*/
max-width: 2.5vw;
height: 5vh;
}
<div id="boxContainer">
<div class="box">
<img class="boxImg" src="https://wallpapercave.com/wp/wp5389930.jpg" alt="giraffe">
<div class="boxTitle">TITLE</div>
<img class="topRightBox" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1" alt="square">
</div>
<div class="box">
<img class="boxImg" src="https://wallpapercave.com/wp/wp5389930.jpg" alt="giraffe">
<div class="boxTitle">TITLE</div>
<img class="topRightBox" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1" alt="square">
</div>
<div class="box">
<img class="boxImg" src="https://wallpapercave.com/wp/wp5389930.jpg" alt="giraffe">
<div class="boxTitle">TITLE</div>
<img class="topRightBox" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1" alt="square">
</div>
<div class="box">
<img class="boxImg" src="https://wallpapercave.com/wp/wp5389930.jpg" alt="giraffe">
<div class="boxTitle">TITLE</div>
<img class="topRightBox" src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.iconsdb.com%2Ficons%2Fdownload%2Fpersian-red%2Fsquare-outline-512.gif&f=1&nofb=1" alt="square">
</div>
</div>

Html Profil Card align right

I don't understand where I made a mistake, I want this round logo on the right. and I want the header below, but where's my fault?
If we briefly summarize the event, as shown in the pictures ..
<div class="video-clip mb-5">
<div class="clip-pic">
<img src="https://www.chiquita.com/wp-content/uploads/2019/12/Chiquita_Banana_Class_Extra_Yellow.jpg" alt="" width="">
</div>
<div class="clip-detail mt-2">
<div class="clip-logo">
<img src="https://www.chiquita.com/wp-content/uploads/2019/12/Chiquita_Banana_Class_Extra_Yellow.jpg" alt="" class="img-circle">
</div>
<div class="clip-desc">
<div class="clip-category">Category Title</div>
<div class="clip-title">Clip Title</div>
</div>
</div>
</div>
.video-clip {
width: 305px;
height: 265px;
}
.clip-pic img {
width: 305px;
height: 180px;
}
.clip-detail {
background-color: black;
display: flex;
margin: 0;
padding: 0;
}
.clip-logo {
width: 80px;
height: 80px;
overflow: hidden;
border: 5px solid #0b75c9;
position: relative;
top: -50px;
max-width: 100%;
max-height: 100%;
border-radius: 50%;
}
.clip-desc {
flex: 1;
min-width: 1px;
position: relative;
}
the image i want
i created
I made a quick remake. I hope this can help you.
.card {
width: 300px;
display: flex;
flex-direction: column;
}
.card-pic img {
width: 100%;
height: 100%;
max-height: 350px;
object-fit: cover;
}
.card-info-logo {
position: absolute;
right: 22px;
top: -22px;
}
.card-info-logo img {
width: 40px;
border-radius: 50%;
border: 4px solid gray;
}
.card-info {
position: relative;
background-color: black;
height: 100px;
padding: 15px;
display: flex;
flex-direction: column;
}
.card-info-top {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.card-info .title {
color: lightgray;
font-size: 14px;
}
.card-info .subtitle {
color: lightgray;
font-size: 18px;
padding-bottom: 10px;
}
.card-info-bottom {
border-top: solid 1px white;
padding-top: 10px;
display: flex;
align-items: center;
line-height: 1;
justify-content: space-between;
}
.card-info .card-info-bottom .views{
color: lightgray;
font-size: 12px;
}
.card-info .card-info-bottom .date {
color: lightgray;
font-size: 12px;
}
<div class="card">
<div class="card-pic">
<img src="https://www.chiquita.com/wp-content/uploads/2019/12/Chiquita_Banana_Class_Extra_Yellow.jpg" alt="">
</div>
<div class="card-info">
<div class="card-info-logo">
<img src="https://www.chiquita.com/wp-content/uploads/2019/12/Chiquita_Banana_Class_Extra_Yellow.jpg">
</div>
<div class="card-info-top">
<div class="title">This is a title</div>
<div class="subtitle">This is a subtitle</div>
</div>
<div class="card-info-bottom">
<div class="views">
VIEWS 10K
</div>
<div class="date">
yesterday
</div>
</div>
</div>
</div>

Scaling the grid in different mobile screens

I'm working on creating UI (header, grid, and buttons) and would like it to be the same on every mobile screen. These are the screenshots from different mobile screens right now:
Samsung S5
Pixel 2 XL
Ipad
I'd like the grid in Pixel 2 XL and Ipad to scale like it's scaled in Samsung S5, i.e. in those two screenshots there is a decent amount of white space after Exit button.
I'd like those buttons be on the bottom of the screen, header - on the very top, and the rest covered by the grid.
I feel like I'm doing something wrong with assigning height of the grid - if I make it higher then the buttons would be beyond in Samsung S5. Could somebody help me out with that ?
Code:
HTML:
<div className="component">
<div className="header">
<h3 className="header-title">
Let&apos;s play!
</h3>
<div>
Click the tiles!
</div>
</div>
<div className="grid">
<div className="box"><div className="inner">1</div></div>
<div className="box"><div className="inner">2</div></div>
<div className="box"><div className="inner">3</div></div>
<div className="box"><div className="inner">4</div></div>
<div className="box"><div className="inner">5</div></div>
<div className="box"><div className="inner">6</div></div>
</div>
<div className="buttonAndInput">
<div className="button">
<button
className="primary button-continue">
Start the Game
</button>
</div>
<div className="link">
<a
className="link-text">
Exit
</a>
</div>
</div>
</div>
CSS:
.component {
width: 100%;
height: 100%;
background-color: white;
text-align: center;
}
.header {
margin: 1rem 0;
height: 10%;
}
.grid {
margin: 0 auto;
width: 90%;
height: 70%;
display: flex;
flex-wrap: wrap;
}
.box {
width: 44%;
margin: 5px;
color: black;
font-weight: bold;
flex: 1 0 auto;
position: relative;
border: 1px solid #d2d2d2;
border-radius: 5px;
background: white;
cursor: pointer;
text-align: center;
}
.box .inner {
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
display: flex;
align-items: center;
justify-content: center;
}
.buttonAndInput {
width: 100%;
height: 20%;
margin-top: 0.5rem;
background-color: white;
animation-fill-mode: backwards;
}
.input-text {
width: 100%;
height: 35px;
font-size: 0.833rem;
padding: 0 1rem;
border-radius: 5px;
border: 1px solid #d2d2d2;
-webkit-appearance: none;
-moz-appearance: none;
}
.button {
margin-top: 0.5rem;
&-continue {
height: 35px;
width: 250px;
padding: 0 !important;
}
}
.link {
margin-top: 0.5rem;
a {
text-align: center;
}
}
Give your .component a height: 100vh and flex each of the children (.header, .grid and .buttonAndInput)
html,
body {
margin: 0;
}
.component {
height: 100vh;
text-align: center;
display: flex;
flex-direction: column;
}
.header {
padding: 1rem 0;
flex: 1 1 10%;
}
.grid {
width: 90%;
margin: 0 auto;
flex: 1 1 70%;
display: flex;
flex-wrap: wrap;
}
.box {
flex: 1 1 50%;
position: relative;
cursor: pointer;
}
.box .inner {
border-radius: 5px;
margin: 5px;
border: 1px solid #d2d2d2;
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
display: flex;
align-items: center;
justify-content: center;
}
.buttonAndInput {
width: 100%;
flex: 1 1 20%;
padding-top: 0.5rem;
}
.button {
margin-top: 0.5rem;
}
.button-continue {
height: 35px;
width: 250px;
}
.link {
margin-top: 0.5rem;
}
.link a {
text-align: center;
}
<div class="component">
<div class="header">
<h3 class="header-title">
Let&apos;s play!
</h3>
<div>
Click the tiles!
</div>
</div>
<div class="grid">
<div class="box">
<div class="inner">1</div>
</div>
<div class="box">
<div class="inner">2</div>
</div>
<div class="box">
<div class="inner">3</div>
</div>
<div class="box">
<div class="inner">4</div>
</div>
<div class="box">
<div class="inner">5</div>
</div>
<div class="box">
<div class="inner">6</div>
</div>
</div>
<div class="buttonAndInput">
<div class="button">
<button class="primary button-continue">
Start the Game
</button>
</div>
<div class="link">
<a class="link-text">
Exit
</a>
</div>
</div>
</div>

Align elements with different heights on the same row

I am trying to display multiple circles on the same horizontal axis but with different width and height. The problem is that the circles are shrinked.
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
.circles-container {
display: table;
border-spacing: 40px;
}
.row {
display: table-row;
}
.circle {
width: 100px;
height: 100px;
border: 1px solid #000;
border-radius: 50%;
text-align: center;
vertical-align: middle;
display: table-cell;
}
.cell {
display: table-cell;
}
.big-circle {
width: 300px;
height: 300px;
}
<div class="circles-container">
<div class="row">
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
</div>
</div>
JSFIDDLE: https://jsfiddle.net/cxuxgy0u/
You should not use the table layout for this. Your HTML does not semantically represent a table, so table element is worng to use.
What you want to do can be achieved with Flexbox.
article {
display: flex;
align-items: center;
}
article > div + div {
margin-left: 1rem;
}
article > div {
flex-shrink: 0;
height: 4rem;
width: 4rem;
border-radius: 50%;
border: solid 1px black;
display: flex;
justify-content: center;
align-items: center;
}
article > div:nth-child(2) {
height: 6rem;
width: 6rem;
}
<article>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
</article>
You might want to read more about Flexbox on MDN.
A simple flexbox solution. Just be sure to set flex-shrink to 0, because the initial value is 1, which allows flex items to shrink when necessary to prevent overflowing the container.
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
.circles-container {
display: flex;
align-items: center;
}
.circle {
display: flex;
align-items: center;
justify-content: center;
text-align: center;
flex: 0 0 100px; /* flex-shrink: 0, to disable shrinking default */
height: 100px;
border-radius: 50%;
margin: 20px;
border: 1px solid #000;
}
.big-circle {
flex-basis: 300px;
height: 300px;
}
<div class="circles-container">
<div class="circle">
<span>TEXT</span>
</div>
<div class="circle">
<span>TEXT</span>
</div>
<div class="big-circle circle">
<span>TEXT</span>
</div>
<div class="circle">
<span>TEXT</span>
</div>
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
https://jsfiddle.net/cxuxgy0u/7/
Try this:
HTML
<div class="container">
<div class="circle">Text</div>
<div class="circle">Text</div>
<div class="circle">Text</div>
<div class="circle">Text</div>
</div>
CSS
.container {
display:flex;
justify-content: space-around;
align-items: center;
height: 100vh;
}
.circle {
background: white;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
}
.circle:nth-child(odd) { width: 100px; height: 100px; }
.circle:nth-child(even) { width: 200px; height: 200px; }
Uses flexbox and is the simplest way to achieve what you want.
Here's a fiddle https://jsfiddle.net/itsag/sk3tdo4L/
Hope it helps!
I think your problem is found in the styling.
For each circle, you need to remove the style
display:table-cell
vertical-align: middle;
and then u need to bring in line-height. The line-height should be equal to the height of the circle, for for the smaller circle, you will have
line-height:100px //this brings the text to the middle of the circle vertically.
Then also, you need to increase the border-radius from 50% to 100%
border-radius:100%;
Therefore, your css will not look like this
body, html {
height: 100%;
margin: 0;
padding: 0;
}
.circles-container{
display: table;
border-spacing: 40px;
}
.row {
display: table-row;
}
.circle {
width: 100px;
height: 100px;
border: 1px solid #000;
border-radius: 100%;
text-align: center;
line-height:100px;
}
.cell {
display: table-cell;
}
.big-circle {
width: 300px;
height: 300px;
line-height:300px;
}
This should help you.
Flexbox:
container {
display: flex;
justify-content: center;
}
If you want space between the pictures, use:
margin-left:
or
margin-right:
try this
body, html {
height: 100%;
margin: 0;
padding: 0;
}
.circles-container{
display: table;
border-spacing: 40px;
}
.row {
display: flex;
}
.circle {
padding: 40px 30px;
border: 1px solid #000;
border-radius: 50%;
text-align: center;
vertical-align: middle;
position: relative;
}
.cell {
}
.big-circle {
padding: 150px;
}
<div class="circles-container">
<div class="row">
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
</div>
</div>

Trouble centering divs within a row in brackets

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!