Evenly distribute scaled items? - css

How can I modify the styles below to result in the elements having the same spacing between each after the scaling? (without absolutely positioning them)
Desired Result:
.menu-next, .menu-previous1 {
transform: scale(.9); transform-origin: left;
}
.menu-previous2 { transform: scale(.7); transform-origin: left;}
.menu-previous3 { transform: scale(.55); transform-origin: left;}
.menu {
background-color: gray;
padding: 10px;
}
.menu div {
display: block;
width: 20%;
padding: 10px;
background-color: white;
color: green;
}
<div class="menu">
<div class="menu-previous3">Items</div>
<div class="menu-previous2">Store</div>
<div class="menu-previous1">Friends</div>
<div class="menu-current" >Settings</div>
<div class="menu-next" >Other</div>
</div>

Use scale(x, y) and not scale(value) + transform-origin
.menu-next,
.menu-previous1 {
transform: scale(.9, 1);
transform-origin: left;
}
.menu-previous2 {
transform: scale(.7, 1);
transform-origin: left;
}
.menu-previous3 {
transform: scale(.55, 1);
transform-origin: left;
}
.menu {
display: flex;
flex-direction: column;
justify-content: center;
background-color: gray;
padding: 10px;
}
.menu div {
display: block;
width: 20%;
padding: 10px;
background-color: white;
border: 1px solid green;
color: green;
}
<div class="menu">
<div class="menu-previous3">Items</div>
<div class="menu-previous2">Store</div>
<div class="menu-previous1">Friends</div>
<div class="menu-current">Settings</div>
<div class="menu-next">Other</div>
</div>
With thatthere is an other problem : scalling text. But you can fix that with pseudo-element (like here)

The best way is to wrap the scaling items and apply the other ui properties seperately of items to that wrapping div and then apply the scaling to the item inside it only.
Here is your code with this theory applied and a little change of padding and margin for equal spacing:
.itemwrapper .menu-next, .itemwrapper .menu-previous1 {
transform: scale(.9); transform-origin: left;
}
.itemwrapper .menu-previous2 { transform: scale(.7); transform-origin: left;}
.itemwrapper .menu-previous3 { transform: scale(.55); transform-origin: left;}
.menu {
background-color: gray;
padding: 10px;
}
.itemwrapper{
display: block;
width: 20%;
padding: 5px 10px;
margin:2px;
background-color: white;
color: green;
}
<div class="menu">
<div class="itemwrapper"><div class="menu-previous3">Items</div></div>
<div class="itemwrapper"><div class="menu-previous2">Store</div></div>
<div class="itemwrapper"><div class="menu-previous1">Friends</div></div>
<div class="itemwrapper"><div class="menu-current" >Settings</div></div>
<div class="itemwrapper"><div class="menu-next" >Other</div></div>
</div>
Hope this helps.

May be you can adjust it by hand ... Not really a good solution, but it is difficult to go any better.
.menu-next,
.menu-previous1 {
transform: scale(.9);
}
.menu-previous2 {
transform: scale(.7);
margin-bottom: -6px;
}
.menu-previous3 {
transform: scale(.55);
margin-bottom: -12px;
}
.menu {
background-color: gray;
padding: 10px;
}
.menu div {
display: block;
width: 20%;
padding: 10px;
background-color: white;
color: green;
transform-origin: left;
}
<div class="menu">
<div class="menu-previous3">Items</div>
<div class="menu-previous2">Store</div>
<div class="menu-previous1">Friends</div>
<div class="menu-current">Settings</div>
<div class="menu-next">Other</div>
</div>

Based a bit off this answer and sort of hack-y: https://stackoverflow.com/a/16388428/1204415
Wrap your scaled divs, resize the wrappers, and move the scaled divs with negative margins within the wrappers. scale() seems to also scale borders, margins, and padding.
HTML
<div class="menu">
<div class="wrap1">
<div class="item menu-previous3">Items</div>
</div>
<div class="wrap2">
<div class="item menu-previous2">Store</div>
</div>
<div class="item menu-previous1">Friends</div>
<div class="item menu-current" >Settings</div>
<div class="item menu-next" >Other</div>
</div>
CSS
.wrap1 {
height: 20px;
margin: 0;
overflow: hidden;
background-color: black;
}
.wrap2 {
height: 32px;
margin: -5px 0 0 0;
overflow: hidden;
background-color: blue;
}
.menu-next, .menu-previous1 {
transform: scale(.9); transform-origin: left;
}
.menu-previous2 { transform: scale(.7); transform-origin: left;}
.menu-previous3 { transform: scale(.55); transform-origin: left; margin: -8px 0 0 0; }
.menu {
background-color: gray;
padding: 10px;
}
.menu .item {
display: block;
outline:1px solid red;
width: 20%;
padding: 10px;
background-color: white;
color: green;
}
A pen: https://codepen.io/dmoz/pen/vmjybo

Related

overflow-x hidden and overflow-y visible

I am building a carousel and I want the container to have overflow-x hidden and overflow-y visible.When the items are hovered
a transform: scale() is applied and I want them to overflow from the container but only on the y axis.
I tried to set the container to overflow-x: hidden and the child to overflow-y: visible but that didn't work.
:root {
--item-margin: 5px;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
position: relative;
width: 80vw;
margin-top: 60px;
overflow-x: hidden;
}
.wrapper {
height: 90%;
display: flex;
position: relative;
left: calc(-20% - 5px);
transition: .5s ease all;
overflow-y: visible;
}
.left-arrow,
.right-arrow {
display: flex;
cursor: pointer;
justify-content: center;
align-items: center;
font-size: 2rem;
color: white;
width: 50px;
height: 50px;
background: #ED4956;
border-radius: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
.left-arrow {
left: 2%;
top: 50%;
}
.right-arrow {
left: 98%;
top: 50%;
}
.child {
display: inline-flex;
justify-content: center;
align-items: center;
flex-shrink: 0;
height: 250px;
width: 20%;
font-weight: bold;
font-size: 4rem;
transition: .4s ease transform;
}
.child {
margin-right: var(--item-margin);
}
.child:hover {
transform: scale(1.5);
}
.child1 {
background: green;
}
.child2 {
background: blue;
}
.child3 {
background: yellow;
}
.child4 {
background: navy;
}
.child5 {
background: red;
}
.child6 {
background: pink;
}
.child7 {
background: grey;
}
.child8 {
background: brown;
}
.child9 {
background: #ff80ed;
}
#media (max-width: 1400px) {
.child {
width: calc(25% - var(--item-margin));
}
.wrapper {
left: -25%;
}
}
<div class="container">
<div class="wrapper">
<div class="child child1">1</div>
<div class="child child2">2</div>
<div class="child child3">3</div>
<div class="child child4">4</div>
<div class="child child5">5</div>
<div class="child child6">6</div>
<div class="child child7">7</div>
<div class="child child8">8</div>
<div class="child child9">9</div>
</div>
<div class="left-arrow"> ← </div>
<div class="right-arrow"> → </div>
</div>
You just have to give the .container a height, for example: 100vh.
Because the tops of the children are cut off i recommend to use padding-top: 60px instead of margin-top: 60px.
Because of the changed height the arrows are wrong positioned. To adjust this i used a different top value: half of the childrens height plus the containers padding-top (125px + 60px).
Because the .wrapper doesn't need position: relative in this example i removed it. Maybe in your project it is necessary for the arrow function(s)...
Working example: (watch it in "Full page" mode to see it without scrollbars)
:root {
--item-margin: 5px;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
position: relative;
width: 80vw;
height: 100vh;
padding-top: 60px;
overflow-x: hidden;
}
.wrapper {
height: 90%;
display: flex;
left: calc(-20% - 5px);
transition: .5s ease all;
overflow-y: visible;
}
.left-arrow,
.right-arrow {
display: flex;
cursor: pointer;
justify-content: center;
align-items: center;
font-size: 2rem;
color: white;
width: 50px;
height: 50px;
background: #ED4956;
border-radius: 50%;
transform: translate(-50%, -50%);
position: absolute;
top: 185px;
}
.left-arrow {
left: 2%;
}
.right-arrow {
left: 98%;
}
.child {
display: inline-flex;
justify-content: center;
align-items: center;
flex-shrink: 0;
height: 250px;
width: 20%;
font-weight: bold;
font-size: 4rem;
transition: .4s ease transform;
}
.child {
margin-right: var(--item-margin);
}
.child:hover {
transform: scale(1.5);
}
.child1 {
background: green;
}
.child2 {
background: blue;
}
.child3 {
background: yellow;
}
.child4 {
background: navy;
}
.child5 {
background: red;
}
.child6 {
background: pink;
}
.child7 {
background: grey;
}
.child8 {
background: brown;
}
.child9 {
background: #ff80ed;
}
#media (max-width: 1400px) {
.child {
width: calc(25% - var(--item-margin));
}
.wrapper {
left: -25%;
}
}
<div class="container">
<div class="wrapper">
<div class="child child1">1</div>
<div class="child child2">2</div>
<div class="child child3">3</div>
<div class="child child4">4</div>
<div class="child child5">5</div>
<div class="child child6">6</div>
<div class="child child7">7</div>
<div class="child child8">8</div>
<div class="child child9">9</div>
</div>
<div class="left-arrow"> ← </div>
<div class="right-arrow"> → </div>
</div>
Because the arrows are still cut of you could add an extra container (here .parent) and add height, padding-top and overflow-x to it (instead of to the container).
Working example: (watch in "Full page" mode to see it without scrollbars)
:root {
--item-margin: 5px;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
position: relative;
width: 80vw;
}
.parent {
height: 100vh;
padding-top: 60px;
overflow-x: hidden;
}
.wrapper {
height: 90%;
display: flex;
left: calc(-20% - 5px);
transition: .5s ease all;
overflow: visible;
}
.left-arrow,
.right-arrow {
display: flex;
cursor: pointer;
justify-content: center;
align-items: center;
font-size: 2rem;
color: white;
width: 50px;
height: 50px;
background: #ED4956;
border-radius: 50%;
transform: translate(-50%, -50%);
position: absolute;
top: 185px;
}
.left-arrow {
left: 2%;
}
.right-arrow {
left: 98%;
}
.child {
display: inline-flex;
justify-content: center;
align-items: center;
flex-shrink: 0;
height: 250px;
width: 20%;
font-weight: bold;
font-size: 4rem;
transition: .4s ease transform;
}
.child {
margin-right: var(--item-margin);
}
.child:hover {
transform: scale(1.5);
}
.child1 {
background: green;
}
.child2 {
background: blue;
}
.child3 {
background: yellow;
}
.child4 {
background: navy;
}
.child5 {
background: red;
}
.child6 {
background: pink;
}
.child7 {
background: grey;
}
.child8 {
background: brown;
}
.child9 {
background: #ff80ed;
}
#media (max-width: 1400px) {
.child {
width: calc(25% - var(--item-margin));
}
.wrapper {
left: -25%;
}
}
<div class="container">
<div class="parent">
<div class="wrapper">
<div class="child child1">1</div>
<div class="child child2">2</div>
<div class="child child3">3</div>
<div class="child child4">4</div>
<div class="child child5">5</div>
<div class="child child6">6</div>
<div class="child child7">7</div>
<div class="child child8">8</div>
<div class="child child9">9</div>
</div>
</div>
<div class="left-arrow"> ← </div>
<div class="right-arrow"> → </div>
</div>

Issue with opacity fade in CSS

I have an issue in CSS while trying to fade in some elements in CSS.
I would like to show with a fade in effect some elements in my image right after the rotate transition but it doesn't work.
I did a jsfiddle and you can activate the effect with an hover on the image :
https://jsfiddle.net/egfjp36h/
Here's my HTML code :
<div class="flip-box">
<div class="fut-player-card card-display">
<div class="fut-front">
<div class="player-card-top player-card-top-color">
<div class="player-master-info">
<div class="player-rating">
<span>97</span>
</div>
<div class="player-position">
<span>RW</span>
</div>
<div class="player-nation">
<img src="https://selimdoyranli.com/cdn/fut_card/img/argentina.svg" alt="Argentina" draggable="false">
</div>
<div class="player-club">
<img src="https://selimdoyranli.com/cdn/fut_card/img/barcelona.svg" alt="Barcelona" draggable="false">
</div>
</div>
<div class="player-picture">
<img src="https://selimdoyranli.com/cdn/fut_card/img/messi.png" alt="Messi" draggable="false">
</div>
</div>
<div class="player-card-bottom">
<div class="player-info player-info-color">
<div class="player-name player-name-border"><span>MESSI</span></div>
<div class="player-features">
<div class="player-features-col player-features-col-border">
<span>
<div class="player-feature-value">97</div>
<div class="player-feature-title">RDV</div>
</span>
<span>
<div class="player-feature-value">95</div>
<div class="player-feature-title">CTR</div>
</span>
<span>
<div class="player-feature-value">94</div>
<div class="player-feature-title">TRANSF</div>
</span>
</div>
<div class="player-features-col player-features-col-border">
<span>
<div class="player-feature-value">99K€</div>
<div class="player-feature-title">CA</div>
</span>
<span>
<div class="player-feature-value">35</div>
<div class="player-feature-title">DEF</div>
</span>
<span>
<div class="player-feature-value">68</div>
<div class="player-feature-title">PHY</div>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And my CSS :
.fut-player-card{
position: relative;
width:300px;
height:485px;
background-position: center center;
background-size:100% 100%;
background-repeat: no-repeat;
padding:5.9rem 0;
z-index: 2;
transition: 200ms ease-in;
margin-left: auto;
margin-right: auto;
}
.card-display{
background-image: url(https://selimdoyranli.com/cdn/fut_card/img/card_bg.png);
}
.card-display2{
background-image: url("img/fut/fut1.png");
}
.card-display3{
background-image: url("img/fut/fut2.png");
}
.card-display4{
background-image: url("img/fut/fut3.png");
}
.player-card-top{
position: relative;
display: flex;
padding: 0 3.5rem;
}
.player-master-info{
position: absolute;
line-height: 3.2rem;
font-weight: 300;
padding: 3rem 0;
text-transform: uppercase;
}
.player-rating{
font-size:3rem;
}
.player-position{
font-size: 2.2rem;
}
.player-nation{
display: block;
width:3rem;
height:25px;
margin: 0.5rem 0;
}
.player-nation img{
width:100%;
height: 100%;
object-fit: contain;
}
.player-club{
display: block;
width:3.1rem;
height:40px;
}
.player-club img{
width:100%;
height: 100%;
object-fit: contain;
}
.player-picture{
width:200px;
height:200px;
margin: 0 auto;
overflow: hidden;
}
.player-picture img{
width:100%;
height:100%;
object-fit: contain;
position: relative;
right: -1.5rem;
bottom: 0;
}
.player-extra{
position: absolute;
right:0;
bottom: -0.5rem;
overflow: hidden;
font-size:1rem;
font-weight: 700;
text-transform: uppercase;
width:100%;
height:2rem;
padding:0 1.5rem;
text-align: right;
background:none;
}
.player-extra span{
margin-left: 0.6rem;
text-shadow:2px 2px #333;
}
.player-card-bottom{
position: relative;
}
.player-info{
display: block;
padding:1rem 0;
width:90%;
margin:0 auto;
height: auto;
position: relative;
z-index: 2;
}
.player-info-color, .player-card-top-color{
color:#e9cc74;
}
.player-info-color2, .player-card-top-color2{
color:#130d40;
}
.player-name{
width:100%;
display: block;
text-align: center;
font-size:2.2rem;
text-transform: uppercase;
padding-bottom: 0.3rem;
overflow: hidden;
}
.player-name-border{
border-bottom: 2px solid;
border-color: rgba(233,204,116, 0.1);
}
.player-name-border2{
border-bottom: 2px solid;
border-color: rgba(13, 33, 74, 0.2);
}
.player-name span{
display: block;
text-shadow:2px 2px #111;
}
.player-name2 span{
display: block;
text-shadow:2px 2px #fff;
}
.player-features{
margin: 1rem auto;
display: flex;
justify-content: center;
}
.player-features-col{
border-right: 2px solid;
padding: 0 3rem;
}
.player-features-col-border{
border-color: rgba(233,204,116, 0.1);
}
.player-features-col-border2{
border-color: rgba(13,33,74, 0.2);
}
.player-features-col span{
display: flex;
font-size: 2rem;
text-transform: uppercase;
}
.player-feature-value{
margin-right: 1rem;
font-weight: 700;
}
.player-feature-title{
font-weight: 300;
}
.player-features-col:last-child{
border:0;
}
.flip-box {
perspective: 1000px;
display: inline-block;
}
.fut-player-card{
position: relative;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.flip-box:hover .fut-player-card{
transform: rotateY(180deg);
}
.flip-box:hover .fut-front{
filter: alpha(opacity=100);
opacity:1;
}
.fut-front{
position: absolute;
}
.fut-front{
transition: opacity 0.8s linear 1.2s;
filter: alpha(opacity=0);
opacity: 0;
}
I thought it was OK with those elements but the transition is effective when the mouse leave the image and not when the mouse comes over the image :
.flip-box:hover .fut-front{
filter: alpha(opacity=100);
opacity:1;
}
.fut-front{
transition: opacity 0.8s linear 1.2s;
filter: alpha(opacity=0);
opacity: 0;
}
EDIT : It works on Firefox but not on Chrome
You can select the element with javascript and add:
addEventListener("mouseenter", function( event ) {
//change opacity here
})

flipping images using css

I have a group of images and what I want is to be able to flip the image. For the front of the image it will show numbers(see image below) and on the back it will have a picture. If the user clicks another image and it matches the first picture clicked, then it will disappear after a couple of seconds. Right now I am stuck on getting the images to flip. I will paste my html code and css down below.
To make the image flip I tried using the hover effect but this did not work either
#flipper:hover {
transform: rotateY(180deg);
}
body {
color: black;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
h2 {
text-align: center;
}
body {
background-color: white;
}
img {
width: 30%;
float: left;
margin: 1.66%;
}
p {
margin-left: 1.66%;
font-family: "Contrail One", cursive;
font-size: 35px;
text-transform: uppercase;
border-bottom: 2px solid black;
width: 30%;
padding-bottom: 20px;
}
div.a {
text-align: center;
font-family: sans-serif;
}
#flipper:hover {
transform: rotateY(180deg);
}
<link href="https://fonts.googleapis.com/css?family=Contrail+One" rel="stylesheet">
<div id="flipper">
<img class="flip" src="http://c1.staticflickr.com/9/8450/8026519634_f33f3724ea_b.jpg" alt="">
<img src="http://c1.staticflickr.com/9/8450/8026519634_f33f3724ea_b.jpg" alt="">
<img src="http://c2.staticflickr.com/8/7218/7209301894_c99d3a33c2_h.jpg " alt="">
<img src="http://c2.staticflickr.com/8/7218/7209301894_c99d3a33c2_h.jpg " alt="">
<img src="http://c2.staticflickr.com/8/7231/6947093326_df216540ff_b.jpg " alt="">
<img src="http://c2.staticflickr.com/8/7231/6947093326_df216540ff_b.jpg " alt="">
<img src="http://c1.staticflickr.com/9/8788/17367410309_78abb9e5b6_b.jpg " alt="">
<img src="http://c1.staticflickr.com/9/8788/17367410309_78abb9e5b6_b.jpg " alt="">
</div>
I think to start off, i couldnt tell if you had already linked your written CSS to your HTML. I see only 1 link and its not to your css. Looks like a google font.
I created a https://codepen.io/robert9111/pen/MzabWZ
<!-- HTML -->
<div id="f1_container">
<div id="f1_card" class="shadow">
<div class="front face">
<img class="size" src="http://c1.staticflickr.com/9/8450/8026519634_f33f3724ea_b.jpg/">
</div>
<div class="back face center">
<p>This is nice for exposing more information about an image.</p>
<p>Any content can go here.</p>
</div>
</div>
</div>
<!-- CSS -->
#f1_container {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
.size {
width: 450px;
height: 281px;
}
#f1_container {
perspective: 1000;
}
#f1_card {
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#f1_container:hover #f1_card {
transform: rotateY(180deg);
box-shadow: -5px 5px 5px #aaa;
}
.face {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.face.back {
display: block;
transform: rotateY(180deg);
box-sizing: border-box;
padding: 10px;
color: white;
text-align: center;
background-color: #aaa;
}
for you to check out. I think this may solve your issue.
I didn't do them all as I think it would be good for you to write out some of that code.

Positioning buttons on the sides of the view CSS

I am trying to place a pair of buttons in line of the divs storing images on sides.
Currently i got this but it is not quite what i want:
* {
box-sizing: border-box;
}
body {
font-family: sans-serif;
background-color: darkgrey;
height: 100vh;
margin: 0;
/* for centering block both horizontally and vertically */
display: flex;
justify-content: center;
align-items: center;
}
.wrapper {
display: flex;
justify-content: center;
flex-wrap: wrap;
/*maximum 3 items, (320px + 2px border + 0.5rem margin-left + 0.5rem margin-right) � 3 */
max-width: calc(325.33px * 3 + 0.5rem * 6);
}
.wrapper > div {
margin: 0.5rem;
}
img {
width: 323.33px;
max-height: 100%;
}
.border {
border: 1px solid #fff;
position: relative;
}
.txt {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.5);
padding: 10px 20px;
color: white;
}
#media (max-width: 750px) {
.border {
width: calc(50% - 2rem);
}
.border > img {
width: 100%;
}
}
.left {
float: left;
text-align: center;
display: inline-block;
vertical-align: middle;
width: 3.5em;
height: 3.5em;
background: white;
border-radius: 50%;
margin-left: 1.5em;
}
.left:after {
border-radius: 4px;
content: '';
display: inline-block;
margin-top: 0.85em;
margin-left: 0.6em;
width: 1.2em;
height: 1.2em;
border-top: 0.6em solid #333;
border-right: 0.6em solid #333;
-moz-transform: rotate(-135deg);
-webkit-transform: rotate(-135deg);
transform: rotate(-135deg);
}
.right {
float: right;
text-align: center;
display: inline-block;
vertical-align: middle;
width: 3.5em;
height: 3.5em;
background: white;
border-radius: 50%;
margin-right: 1.5em;
}
.right:after {
border-radius: 4px;
content: '';
display: inline-block;
margin-top: 0.85em;
margin-left: -0.6em;
width: 1.2em;
height: 1.2em;
border-top: 0.6em solid #333;
border-right: 0.6em solid #333;
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
<div>
<span class='left' ></span>
<span class= 'right'></span>
<div class="wrapper">
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c119.0.842.842/18299802_1402951239794126_7834789447697694720_n.jpg">
<div class="txt">div text 1</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c135.0.810.810/17332427_1876651042606993_1501112703702269952_n.jpg">
<div class="txt">div text 2</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c84.0.912.912/16583397_677753229099565_4518661686835544064_n.jpg">
<div class="txt">Omelette du fromage</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c135.0.810.810/16230268_1353432401412243_430046279255457792_n.jpg">
<div class="txt">How you doin?</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c0.45.1080.1080/14547823_248508785596143_6915357097039233024_n.jpg">
<div class="txt">div text 5</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c135.0.810.810/15801844_242832729497192_6894626767370190848_n.jpg">
<div class="txt">div text 6</div>
</div>
</div>
</div>
Click "Full page" to get a better view of the snippet.
I tried to use
float with margins but it doesn't work very well:
This is what i am trying to achieve:
Is it possible to change position of those buttons without changing what is inside div with class called wrapper? It would break positioning of those divs. If it was possible to resize buttons with divs in line that would be great!
removed display flex from body
2.
.right {
/* float: right; */ instead of using thing use left: 0;
text-align: center;
display: inline-block;
/* vertical-align: middle; */ not needed
width: 3.5em;
height: 3.5em;
background: white;
border-radius: 50%;
right: 0;
/* margin-top: 50%; */ instead of this, use top: 50% or top: 100%
position: absolute; needs to be absolute pos
top: 100%;
transform: translateY(-50%); this centers the buttons vertically
}
3.
.wrapper {
display: flex;
justify-content: center;
flex-wrap: wrap;
width: 100%;
padding: 0 48px;
}
Working:
* {
box-sizing: border-box;
}
body {
font-family: sans-serif;
background-color: darkgrey;
height: 100vh;
margin: 0;
}
.wrapper {
display: flex;
justify-content: center;
flex-wrap: wrap;
/*maximum 3 items, (320px + 2px border + 0.5rem margin-left + 0.5rem margin-right) � 3 */
width: 100%;
}
.wrapper {
display: flex;
justify-content: center;
flex-wrap: wrap;
width: 100%;
padding: 0 48px;
}
img {
width: 323.33px;
max-height: 100%;
}
.border {
border: 1px solid #fff;
position: relative;
}
.txt {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.5);
padding: 10px 20px;
color: white;
}
#media (max-width: 750px) {
.border {
width: calc(50% - 2rem);
}
.border > img {
width: 100%;
}
}
.left {
/* float: right; */
text-align: center;
display: inline-block;
/* vertical-align: middle; */
width: 3.5em;
height: 3.5em;
background: white;
border-radius: 50%;
left: 0;
/* margin-top: 50%; */
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.left:after {
border-radius: 4px;
content: '';
display: inline-block;
margin-top: 0.85em;
margin-left: 0.6em;
width: 1.2em;
height: 1.2em;
border-top: 0.6em solid #333;
border-right: 0.6em solid #333;
-moz-transform: rotate(-135deg);
-webkit-transform: rotate(-135deg);
transform: rotate(-135deg);
}
.right {
/* float: right; */
text-align: center;
display: inline-block;
/* vertical-align: middle; */
width: 3.5em;
height: 3.5em;
background: white;
border-radius: 50%;
right: 0;
/* margin-top: 50%; */
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.right:after {
border-radius: 4px;
content: '';
display: inline-block;
margin-top: 0.85em;
margin-left: -0.6em;
width: 1.2em;
height: 1.2em;
border-top: 0.6em solid #333;
border-right: 0.6em solid #333;
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
<div>
<span class='left' ></span>
<span class= 'right'></span>
<div class="wrapper">
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c119.0.842.842/18299802_1402951239794126_7834789447697694720_n.jpg">
<div class="txt">div text 1</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c135.0.810.810/17332427_1876651042606993_1501112703702269952_n.jpg">
<div class="txt">div text 2</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c84.0.912.912/16583397_677753229099565_4518661686835544064_n.jpg">
<div class="txt">Omelette du fromage</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c135.0.810.810/16230268_1353432401412243_430046279255457792_n.jpg">
<div class="txt">How you doin?</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c0.45.1080.1080/14547823_248508785596143_6915357097039233024_n.jpg">
<div class="txt">div text 5</div>
</div>
<div class="border">
<img src="https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c135.0.810.810/15801844_242832729497192_6894626767370190848_n.jpg">
<div class="txt">div text 6</div>
</div>
</div>
</div>

Align two span elements to same line irrespective of font size and content length using CSS

I have two rows. First row has an indicator and a number. Second row has only a number. I want the numbers of both the rows to align in a line vertically. But I am unable to do so. The spans should align irrespective of font size and content length.
Below is the snippet:
#top-area {
border: 3px solid #000;
}
#top-area>div:nth-of-type(1) {
width: 100%;
}
div#header {
background-color: #000;
color: #fff;
padding-top: 2px;
padding-bottom: 2px;
}
div {
text-align: center;
}
#top-area>div:nth-of-type(2) {
width: 100%;
font-weight: bold;
margin-bottom: -1px;
}
.DownTrend-diamond {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
transform-origin: 50% 50%;
margin-right: 10px;
display: inline-block;
}
#top-area>div:nth-of-type(3) {
width: 100%;
}
<div id="top-area">
<div id="header" style="font-weight:normal;font-size: 16px;background-color: #5F6B6D;color: #000;">Header</div>
<div style="font-size:14px; color: #008000!important ;font-weight:normal;background-color:#fff" class="DownTrend ">
<div class="DownTrend-diamond" style="background-color:#FF0000 !important;width:10.5px;height:10.5px;"></div>
<span style="color:#000 !important;">15.0</span>
</div>
<div style="font-size:14px; color: #000 !important ;font-weight:normal;background-color:#fff" class=" "><span style="color:#000 !important;">250.0</span></div>
</div>
How can I fix this issue? I cannot change the HTML structure much. Can it be done using pure CSS? Any help will be appreciated.
Expected Output :
Use flex to get the same
Update html add class
<div id="top-area">
<div id="header" style="font-weight:normal;font-size: 16px;background-color: #5F6B6D;color: #000;">Header</div>
<div style="font-size:14px; color: #008000!important ;font-weight:normal;background-color:#fff; margin-top:5px;" class="DownTrend ">
<div class="squre">
<div class="DownTrend-diamond" style="background-color:#FF0000 !important;width:10.5px;height:10.5px;"> </div>
</div>
<div class="value">
<span style="color:#000 !important;">15.0</span>
</div>
</div>
<div>
<div class="squre">
<div class="" style="background-color:#FF0000 !important;"></div>
</div>
<div class="value">
<span style="color:#000 !important;">25000.0</span>
</div>
</div>
Update css part
#top-area>div:nth-of-type(2) {
width: 100%;
font-weight: bold;
margin-bottom: -1px;
display: flex;
justify-content: center;
align-items: center;
flex-flow: row wrap;
}
#top-area>div:nth-of-type(3) {
display: flex;
justify-content: center;
align-items: center;
flex-flow: row wrap;
}
.value {
flex: 1 0 35%;
align-self: flex-start;
text-align: left;
}
.squre {
flex: 1 0 30%;
align-self: flex-start;
text-align: right;
}
#top-area {
border: 3px solid #000;
}
#top-area>div:nth-of-type(1) {
width: 100%;
}
div#header {
background-color: #000;
color: #fff;
padding-top: 2px;
padding-bottom: 2px;
}
div {
text-align: center;
}
#top-area>div:nth-of-type(2) {
width: 100%;
font-weight: bold;
margin-bottom: -1px;
display: flex;
justify-content: center;
align-items: center;
flex-flow: row wrap;
}
#top-area>div:nth-of-type(3) {
display: flex;
justify-content: center;
align-items: center;
flex-flow: row wrap;
}
.value {
flex: 1 0 35%;
align-self: flex-start;
text-align: left;
}
.squre {
flex: 1 0 30%;
align-self: flex-start;
text-align: right;
}
.text-left {
text-align: left;
}
.DownTrend-diamond {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
transform-origin: 50% 50%;
margin-right: 10px;
display: inline-block;
}
<div id="top-area">
<div id="header" style="font-weight:normal;font-size: 16px;background-color: #5F6B6D;color: #000;">Header</div>
<div style="font-size:14px; color: #008000!important ;font-weight:normal;background-color:#fff; margin-top:5px;" class="DownTrend ">
<div class="squre">
<div class="DownTrend-diamond" style="background-color:#FF0000 !important;width:10.5px;height:10.5px;"> </div>
</div>
<div class="value">
<span style="color:#000 !important;">15.0</span>
</div>
</div>
<div>
<div class="squre">
<div class="" style="background-color:#FF0000 !important;"></div>
</div>
<div class="value">
<span style="color:#000 !important;">25000.0</span>
</div>
</div>
Please check this:
#top-area {
border: 3px solid #000;
}
#top-area>div:nth-of-type(1) {
width: 100%;
}
div#header {
background-color: #000;
color: #fff;
padding-top: 2px;
padding-bottom: 2px;
}
div {
text-align: center;
}
#top-area>div:nth-of-type(2) {
width: 100%;
font-weight: bold;
margin-bottom: -1px;
}
.DownTrend-diamond {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
transform-origin: 50% 50%;
margin-right: 10px;
display: inline-block;
}
#top-area>div:nth-of-type(3) {
width: 100%;
}
<div id="top-area">
<div id="header" style="font-weight:normal;font-size: 16px;background-color: #5F6B6D;color: #000;">Header</div>
<div style="font-size:14px; color: #008000!important ;font-weight:normal;background-color:#fff; padding-left: 50%; text-align: left; width: 50%" class="DownTrend ">
<div class="DownTrend-diamond" style="background-color:#FF0000 !important;width:10.5px;height:10.5px; position: absolute; margin-left: -30px; margin-top: 4px"></div>
<span style="color:#000 !important;">15.0</span>
</div>
<div style="font-size:14px; color: #000 !important ;font-weight:normal;background-color:#fff; padding-left: 50%; text-align: left; width: 50%" class=" "><span style="color:#000 !important;">250.0</span></div>
</div>
Try this
Add a margin-left in the style of the span
<div style="font-size:14px; color: #000 !important ;font-weight:normal;background-color:#fff" class=" "><span style="color:#000 !important;margin-left: 30px;">250.0</span></div>
and you will get your expected result
#row1 div {
float: left;
left: 47%;
margin-right: 0 !important;
margin-top: 3px;
position: relative;
}
#row1 span {
float: left;
left: 48.3%;
position: relative;
}
#row2 {
clear: left;
position: relative;
text-align: left;
}
#row2 span {
left: 50%;
position: relative;
}
https://jsfiddle.net/wazz/77r72nwL/

Resources