Using flexbox to change ordering in Bootstrap 4 - css

I'm currently building a site that has a team section that should look like the following:
Here is my current scss file:
.team-member-card {
&__text-content {
background-color: red;
padding: 16px;
overflow-y: scroll;
}
&__name {
font-family: CircularStd;
font-size: 24px;
font-weight: bold;
font-stretch: normal;
font-style: normal;
line-height: normal;
letter-spacing: normal;
color: $white;
}
&__role {
font-family: CircularStd;
font-size: 18px;
font-weight: 500;
font-stretch: normal;
font-style: normal;
line-height: 1.44;
letter-spacing: normal;
color: $white;
}
&__biography {
font-family: Balto;
font-size: 16px;
font-weight: normal;
font-stretch: normal;
font-style: normal;
line-height: 1.5;
letter-spacing: normal;
color: $white;
}
&__image-container {
position: relative;
}
&__image {
height: auto;
max-width: 100%;
object-fit: contain;
background-color: #ffffff;
}
&__social-link {
position: absolute;
width: 48px;
height: 48px;
object-fit: contain;
}
}
I have broken the component down into the obvious sections I can see but as you can see, every n+1 team member has their image on the other side, is there a way to inverse the column order?

https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Ordering_Flex_Items
please check documentation. To understand code check below
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
.box {
display: flex;
flex-direction: row;
}
.box :nth-child(1) { order: 2; }
.box :nth-child(2) { order: 3; }
.box :nth-child(3) { order: 1; }
.box :nth-child(4) { order: 3; }
.box :nth-child(5) { order: 1; }

Please try to look for the css nth element selector. It has odd and even selector.
:nth-child(odd) {
float: right;
}
//or with flex-direction
flex-direction: row-reverse;
Please have a look here

Related

How to make the flex item text wrapped under the adjutants item

How to get the text wrapped under the points?
https://codepen.io/neginbasiri/pen/ZEGReRZ
<div class="pointLine__PointLine-wgyo1p-1 bUhvVh">
<svg class="icon--icon--base--17 pointLine__RooIcon-wgyo1p-0 iBQvHK">IMAGE</svg>
<div class="pointLine__Content-wgyo1p-2 cPwDGx"><div class="pointLine__Point-wgyo1p-3
pointLine__DefaultPoint-wgyo1p-4 enMiay">16,000</div><p class="Text__StyledText-zy9rxk-0 dufgDt">
Points when you join or switch <span id="super-node-187"><sup class="super--super--root--13">
<span>3</span></sup> </span></p></div>
In the example switch should show under 16,000.
.bUhvVh {
display: flex;
margin-bottom: 20px;
width: 300px;
}
.iBQvHK {
color: #e40000;
font-size: 24px;
margin-right: 10px;
border: 1px solid red;
width: 20px;
}
.icon--icon--base--17 {
height: 1em;
min-width: 1em;
vertical-align: middle;
fill: currentColor;
}
.cPwDGx {
font-family: Ciutadella Regular;
font-size: 18px;
color: #555;
letter-spacing: normal;
line-height: 1.5;
}
.enMiay {
float: left;
font-family: Ciutadella Medium;
margin-right: 4px;
position: relative;
color: #323232;
}
.dufgDt {
margin: 0;
font-family: 'Ciutadella Regular',sans-serif;
font-size: 18px;
color: #555;
letter-spacing: normal;
line-height: 1.5;
}
<div class="pointLine__PointLine-wgyo1p-1 bUhvVh">
<svg class="icon--icon--base--17 pointLine__RooIcon-wgyo1p-0 iBQvHK">IMAGE</svg>
<div class="pointLine__Content-wgyo1p-2 cPwDGx"><div class="pointLine__Point-wgyo1p-3 pointLine__DefaultPoint-wgyo1p-4 enMiay">16,000</div><p class="Text__StyledText-zy9rxk-0 dufgDt"> Points when you join or switch <span id="super-node-187"><sup class="super--super--root--13"><span>3</span></sup> </span></p></div>
</div>
Remove display: flex; flex: 1 from .cPwDGx.
Remove display: inline-block from .enMiay and add float: left for this element.
Update width to min-width for icon--icon--base--17. It will not shrink if text is larger.
Refer : https://codepen.io/bala_tamizh/pen/WNvyEPg

How to changed normal nested css to styled-components?

I have this CSS styles which I want to change to styled-components in react:
.movie-page .movie-details {
display: flex;
flex-direction: column;
max-width: 800px;
margin: 20px auto 60px auto;
}
.movie-page .movie-details h1 {
line-height: 1.5em;
}
.movie-page .movie-details h1 span {
font-size: inherit;
font-weight: normal;
padding-left: 1rem;
color: #bbb;
line-height: inherit;
}
I'm a bit confused how does the tags nesting work. I'm doing this with styled-components:
const MovieDetails = styled.div`
display: flex;
flex-direction: column;
max-width: 800px;
margin: 20px auto 60px auto;
h1 {
line-height: 1.5em;
}
h1 span {
font-size: inherit;
font-weight: normal;
padding-left: 1rem;
color: #bbb;
line-height: inherit;
}
`;
Does this code seem to be ok? My h1 tag looks like p tag
You should be able to select like that. Bt you can also do like the following which will look neater:
const MovieDetailsHeader = styled.h1 `
line-height: 1.5em;
span {
font-size: inherit;
font-weight: normal;
padding-left: 1rem;
color: #bbb;
line-height: inherit;
}
`

How to vertically center this span equal to h1

I got it this far:
Jsfiddle
How can I change the css of the span so it's vertically centered to the h1 on the left of it?
Hope it's not to complicated!
Your best bet is using Flex styles.
Remove all styles for '.title i', '.title span', '.title h1'
Edit title as below:
Flex title style:
.title {
width: 100%;
margin: 30px auto;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
justify-content: center; - This re-aligns your H1, dash, and span in the middle.
align-items: center; - This gives you that vertical alignment.
Add a wrapper around h1 and span, then set it as a inline-flex. The wrapper will be centered because of the text-align with title.
Fiddle
.title {
width: 100%;
margin: 30px auto;
text-align: center;
}
.wrapper {
display: inline-flex;
justify-content: flex-start;
align-items: center;
}
.title i {
color: var(--grey-500);
}
.title span {
font-size: var(--caption);
line-height: 40px;
color: #9E9E9E;
}
.title h1 {
color: var(--black);
font-size: var(--h1);
text-align: center;
font-weight: 500;
margin: 65px auto;
}
<div class="title">
<div class="wrapper">
<h1>Title 1</h1> <i class="material-icons separateTitleType">remove</i> <span>Page</span>
</div>
</div>
Add this code to .title
display: flex;
justify-content:center;
align-items:center;
Also, i removed margin: 65px auto from h1 so it wouldn't take all the place in flex-container.
/* Titles */
.title {
width: 100%;
margin: 30px auto;
text-align: center;
display: flex;
justify-content:center;
align-items:center;
}
.title i {
color: var(--grey-500);
}
.title span {
font-size: var(--caption);
line-height: 40px;
color: #9E9E9E;
}
.title h1 {
color: var(--black);
font-size: var(--h1);
text-align: center;
font-weight: 500;
}
:root {
--black: #000000;
--h1: 2.125em;
--caption: 0.875em;
--grey-500: #9E9E9E;
}
/* fallback */
#font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: local('Material Icons'), local('MaterialIcons-Regular'), url(https://fonts.gstatic.com/s/materialicons/v22/2fcrYFNaTjcS6g4U3t-Y5ZjZjT5FdEJ140U2DJYC3mY.woff2) format('woff2');
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
}
body {
font-family: 'Roboto', sans-serif;
background-color: #fff;
}
<div class="title">
<h1>Title 1</h1> <i class="material-icons separateTitleType">remove</i> <span>Page</span>
</div>

Is it possible to use :hover on :first-child:after?

HTML
<div>
<div></div>
</div>
CSS
div > :first-child:after {
background-color: orange;
color: #fff;
font-family: sans-serif;
font-size: 50px;
line-height: 50px;
text-align: center;
vertical-align: middle;
-webkit-font-smoothing: antialiased;
content: "hello world";
display: block;
font-size: 50px;
height: 160px;
line-height: 160px;
margin-top: 14px;
font-weight: normal;
}
div > :first-child:after:hover {
background-color: #44b800;
}
Fiddle
http://jsfiddle.net/VSBr6/
Basically, all I want to do is change the background-color on hover but it doesn't seem to work.
You can do it like this:
div:first-child:hover::after {
background-color: #44b800;
}

CSS - how to dry up?

Is there a way to DRY this CSS up? Only difference is color?
div.base-text-gold {
position: absolute; bottom: 9px; color: #FED577; font-size: 10px;
font-weight: bolder; text-align: center; width: 61px; text-transform: uppercase;
}
div.base-text-grey {
position: absolute; bottom: 9px; color: #D1D2D4; font-size: 10px;
font-weight: bolder; text-align: center; width: 61px; text-transform: uppercase;
}
Separate out the colours into different CSS classes like so:
div.base-text {
position: absolute; bottom: 9px; font-size: 10px;
font-weight: bolder; text-align: center; width: 61px; text-transform: uppercase;
}
div.gold {
color: #FED577;
}
div.grey {
color: #D1D2D4;
}
and then simply apply two classes to the elements instead:
<div class="base-text gold">...</div>
You could try one of the lessCSS or dotlesscss
librarys available
You could create a "base class" base-text, and then just keep the colors in the "sub-classes":
div.base-text {
position: absolute; bottom: 9px; font-size: 10px;
font-weight: bolder; text-align: center; width: 61px; text-transform: uppercase;
}
div.base-text-gold {
color: #FED577;
}
div.base-text-grey {
color: #D1D2D4;
}
Of course, the disadvantage is that you will have to add 2 classes to your div's instead of a single one:
<div class="base-text base-text-gold">...</div>
My initial reaction is to tell you that it's probably not a good idea to specify colors in your CSS class names. At that point, it's really no better than inline CSS. You're better to go with .emphasized or .strong for the gold text, depending on your situation. And even then, you can just style and use <em> or <strong> tag. That said, how about I answer your question?
The answer is in attempting to never use the same declaration twice.
div.base-text-gold, div.base-text-grey {
position: absolute; bottom: 9px; font-size: 10px;
font-weight: bolder; text-align: center; width: 61px; text-transform: uppercase;
}
div.base-text-gold { color: #FED577; }
div.base-text-grey { color: #D1D2D4; }
You could inherit from a class "base-text" which doesn't define color.
Then you have two choices:
have a style="" next to it...
<style>
div.base-text {
position: absolute; bottom: 9px; font-size: 10px;
font-weight: bolder; text-align: center; width: 61px; text-transform: uppercase;
}
</style>
<html><head>[the style thingie above]</head><body>
<div class="base-text" style="color:BLARGH"> RAWR~ </div>
</body></html>
OR
inherit from classes gold and grey too
<style>
div.base-text {
position: absolute; bottom: 9px; font-size: 10px;
font-weight: bolder; text-align: center; width: 61px; text-transform: uppercase;
}
div.grey {
color: #999999;
}
div.gold {
color: #DDDD99;
}
</style>
<html><head>[the style thingie above]</head><body>
<div class="base-text gold" style="color:BLARGH"> RAWR~ </div>
<div class="base-text grey" style="color:BLARGH"> DADADEEEEE~ </div>
</body></html>
Well... one thing you could do is:
div.base-text {
position: absolute; bottom: 9px; font-size: 10px;
font-weight: bolder; text-align: center; width: 61px; text-transform: uppercase;
}
div.base-text-gold {
color: #FED577;
}
div.base-text-grey {
color: #D1D2D4;
}
And in each of your divs, just go:
<div class="base-text base-text-gold">This is the gold div.</div>
<div class="base-text base-text-grey">This is the grey div.</div>

Resources