How to vertically center this span equal to h1 - css

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>

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

Using flexbox to change ordering in Bootstrap 4

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

Horizontally and vertically flexbox css not working [duplicate]

This question already has answers here:
How can I vertically center a div element for all browsers using CSS?
(48 answers)
Closed 3 years ago.
I'm trying to center the below HTML vertically and horizontally but it's not working vertically, only horizontally. Please could someone help explain why it's not working?
<body>
<header class="nav">
<img class="icon" src="./img/eiffel-tower.svg" attr="Icon made by Monkik from www.flaticon.com">
<a class="home-anchor" href="./index.html">Learn</a>
</header>
<div class="quiz-container">
<p class="word-to-conjugate" id="randomWord"></p>
<input type="text" id="userGuess">
<button class="answer-button" id="checkAnswer">Answer</button>
</div>
</body>
My CSS using flexbox trying to center the quiz horizontally and vertically
.quiz-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.word-to-conjugate {
font-size: 2rem;
font-family: 'Source Sans Pro', sans-serif;
text-align: center;
}
input {
font-family: 'Roboto', sans-serif;
font-weight: bold;
padding: 10px;
font-size: 1.5rem;
border: 1px solid #333;
border-radius: 5px;
margin-bottom: 20px;
}
.answer-button {
background-color: #505FDF;
font-size: 1.5rem;
text-align: center;
color: #FFFFFF;
padding: 10px;
border-radius: 5px;
border: none;
font-family: 'Roboto', sans-serif;
margin-bottom: 3%;
}
That's because you have nothing making the quiz-container aligning vertically.
See example below, trick is to add a wrapper around your quiz element which aligns it vertically. Lastly, be sure to set the height of html, body and wrapper element to 100%;
html,
body,
.wrapper {
height: 100%;
}
.wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.quiz-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.word-to-conjugate {
font-size: 2rem;
font-family: 'Source Sans Pro', sans-serif;
text-align: center;
}
input {
font-family: 'Roboto', sans-serif;
font-weight: bold;
padding: 10px;
font-size: 1.5rem;
border: 1px solid #333;
border-radius: 5px;
margin-bottom: 20px;
}
.answer-button {
background-color: #505FDF;
font-size: 1.5rem;
text-align: center;
color: #FFFFFF;
padding: 10px;
border-radius: 5px;
border: none;
font-family: 'Roboto', sans-serif;
margin-bottom: 3%;
}
<body>
<header class="nav">
<img class="icon" src="./img/eiffel-tower.svg" attr="Icon made by Monkik from www.flaticon.com">
<a class="home-anchor" href="./index.html">Learn</a>
</header>
<div class="wrapper">
<div class="quiz-container">
<p class="word-to-conjugate" id="randomWord"></p>
<input type="text" id="userGuess">
<button class="answer-button" id="checkAnswer">Answer</button>
</div>
</div>
</body>
p, input, button are already centered with respect to their parent: .quiz-container
Maybe you are looking for it to be centered with respect to the complete screen/viewport. In that case you need to set the min-height of html, body and quiz-container to 100%.
Now .quizcontainer has 100% height and its children will be centered
both vertically and horizontally.
body, html{
min-height: 100%; /*add this*/
}
.quiz-container {
min-height: 100%; /*add this*/
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.word-to-conjugate {
font-size: 2rem;
font-family: 'Source Sans Pro', sans-serif;
text-align: center;
}
input {
font-family: 'Roboto', sans-serif;
font-weight: bold;
padding: 10px;
font-size: 1.5rem;
border: 1px solid #333;
border-radius: 5px;
margin-bottom: 20px;
}
.answer-button {
background-color: #505FDF;
font-size: 1.5rem;
text-align: center;
color: #FFFFFF;
padding: 10px;
border-radius: 5px;
border: none;
font-family: 'Roboto', sans-serif;
margin-bottom: 3%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<header class="nav">
<img class="icon" src="./img/eiffel-tower.svg" attr="Icon made by Monkik from www.flaticon.com">
<a class="home-anchor" href="./index.html">Learn</a>
</header>
<div class="quiz-container">
<p class="word-to-conjugate" id="randomWord"></p>
<input type="text" id="userGuess">
<button class="answer-button" id="checkAnswer">Answer</button>
</div>
</body>
</html>

Need to center align a span inside a div both vertically and horizontally using less(css)

I am using LESS (CSS) trying to align a span (button text) inside a div (button). The span is centrally aligned horizontally but is top aligned vertically. I would also like the span object to adjust itself to the text size automatically.
Here's the LESS code:
.button(#color:#crimson-red) {
border-radius: #small-border-radius;
border-style: none;
background-color: #color;
text-align: center;
display: inline-block;
}
.button-font {
vertical-align: middle;
overflow: auto;
font-family: "Helvetica Neue", sans-serif;
color: #off-white;
font-weight: bold;
font-size: 10pt;
position: relative;
}
.blue-button {
.button(#blue);
}
You can achieve this by using the flexbox layout.
So by adding the following properties and values to the .button selector you can center the span.
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
Here is the full less file for reference.
#off-white: #fefefe;
#blue: #4286f4;
#small-border-radius: 5px;
.button(#color:#crimson-red) {
border-radius: #small-border-radius;
border-style: none;
background-color: #color;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.button-font {
font-family: "Helvetica Neue", sans-serif;
color: #off-white;
font-weight: bold;
font-size: 10pt;
position: relative;
}
.blue-button {
.button(#blue);
width: 300px;
height: 100px;
}
This would be the html:
<button class="blue-button">
<span class="button-font">Hello, lots of text here</span>
</button>
Here is a link to a JSFiddle with compiled css.

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;
}

Resources