I am stuck with a problem, I am using argon creative Tim and ReactStrap for making this UI, It's working fine, but when am trying to view it on Mobile View it is not working as expected.
image is not responsive when i want to view on mobile view
login.jsx
Below I share my all code for making UI. let me know if you have any question.
import React, { useState } from "react";
import { useEffect } from "react";
import { NavLink } from "react-router-dom";
import { Button, Row, Col, FormGroup, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Label } from "reactstrap";
import { useHistory } from "react-router";
import "./Login.css";
const Login = ({ user }) => {
return (
<>
<div className="section section-hero section-shaped">
<div className="shape shape-style-1 shape-primary">
<span className="span-150"></span>
<span className="span-50"></span>
<span className="span-50"></span>
<span className="span-75"></span>
<span className="span-100"></span>
<span className="span-75"></span>
<span className="span-50"></span>
<span className="span-100"></span>
<span className="span-50"></span>
<span className="span-100"></span>
</div>
<div className="outer">
<div className="inner" style={{ width: "450px", height: "450px", marginBottom:"80px" }}>
<h3>{user} Log In</h3>
<br />
<Form role="form" method="POST">
<FormGroup className="mb-3">
<Label for="email">Email</Label>
<InputGroup className="input-group-alternative">
<InputGroupAddon addonType="prepend">
<InputGroupText>
<i className="fas fa-envelope"></i>
</InputGroupText>
</InputGroupAddon>
<Input type="email"
/>
</InputGroup>
</FormGroup>
<FormGroup>
<Label for="password">Password</Label>
<InputGroup className="input-group-alternative">
<InputGroupAddon addonType="prepend">
<InputGroupText>
<i className="fas fa-key"></i>
</InputGroupText>
</InputGroupAddon>
<Input
type="password"
autoComplete="off"
required="required"
/>
</InputGroup>
</FormGroup>
<div className="custom-control custom-control-alternative custom-checkbox">
<input
className="custom-control-input"
id=" customCheckLogin"
type="checkbox"
/>
<label
className="custom-control-label"
htmlFor=" customCheckLogin"
>
<span>Remember me</span>
</label>
</div>
<div className="text-center">
<Button
className="my-4"
color="primary"
type="button"
onClick={login}
>
Sign in
</Button>
</div>
</Form>
<Row className="mt-3">
<Col xs="6">
<a
className="text-light"
href="#"
onClick={e => e.preventDefault()}
>
<small>Forgot password?</small>
</a>
</Col>
{bool ? <Col className="text-right" xs="6">
<NavLink exact to='./signup' className="text-light">Create new account</NavLink>
</Col>
: <Col className="text-right" xs="6">
<NavLink exact to='./vendorsignup' className="text-light">Create new account</NavLink>
</Col>}
</Row>
</div>
</div>
</div>
</>
)
}
export default Login;
Login.css
.outer {
height: 100vh;
background-position: fixed;
overflow: scroll;
overflow: hidden;
}
.form-group label {
display: block;
margin: 0 0 10px;
color: black;
font-size: 15px;
font-weight: 500;
line-height: 1;
letter-spacing: 0.2em;
}
.form-group input {
outline: none;
display: block;
background: rgba(0, 0, 0, 0.1);
width: 100%;
border: 0;
border-radius: 4px;
box-sizing: border-box;
padding: 12px 20px;
color: rgba(0, 0, 0, 1.6);
font-family: inherit;
font-size: 17px;
font-weight: 500;
line-height: inherit;
transition: 0.3s ease;
}
.signinp {
padding-left: 10px !important;
}
.whiteinput {
background-color: white !important;
}
/* .form-group input:focus {
background-color: transparent;
}
.form-group input:focus {
border: 1px solid black;
} */
.outer {
display: flex;
justify-content: center;
flex-direction: column;
text-align: left;
}
.inner {
width: 450px;
margin: auto;
background: #ffffff;
box-shadow: 0px 14px 80px rgb(34 35 58 / 20%);
padding: 40px 55px 45px 55px;
border-radius: 15px;
transition: all 0.3s;
}
.outer .form-control:focus {
border-color: #167bff;
box-shadow: none;
}
.outer h3 {
text-align: center;
margin: 0;
line-height: 1;
padding-bottom: 20px;
}
.custom-control-label {
font-weight: 400;
}
.forgot-password,
.forgot-password a {
text-align: right;
font-size: 13px;
padding-top: 10px;
color: #7f7d7d;
margin: 0;
}
.forgot-password a {
color: #167bff;
}
In your case you aren't using any code to have responsiveness in your App.
You can use the #media rule. Also good practice is to use CSS Grid system.
There are also CSS Frameworks like Bootstrap which have their implementation of responsive grid system which is very easy to use.
Its not related to Reactjs, you will have to modify your css code, for that you can use CSS media queries to target the screen/mobile sizes as per your need.
Example :
/* For screen size more than 400px */
#media screen and (min-width: 400px) {
body {
background-color: lightgreen;
}
}
/* For screen size less than 600px */
#media screen and (max-width: 600px) {
body {
background-color: lavender;
}
}
Reference : https://www.w3schools.com/cssref/css3_pr_mediaquery.asp
You can also try bootstrap, foundation, materialize css libraries which has ready made classes for responsive screen sizes.
https://www.w3schools.com/bootstrap/bootstrap_grid_stacked_to_horizontal.asp
You have to make changes to CSS so that the DOM elements rendered on screen look good on different screen sizes
Some things which you can explore are
Media queries
Material UI Grid
Bootstrap's breakpoints
I think the single most important thing you can do if you want to start working with "intuitive" responsive design is to update your box-model to use the border-box.
Box Sizing CSS-Tricks
Add the following to your CSS
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
This will size your containers to match what you specify in CSS, with the padding on the inside and the margins outside. I am still amazed this isn't the default. All projects should implement this fix/change.
To specifically address the responsive issue with the login modal, set the max-width to a static value, i.e. the 450px and set the width to a relative value, i.e. 90%.
.inner {
max-width: 550px; // <-- static max value
width: 90%; // <-- dynamic relative value
margin: auto;
background: #ffffff;
box-shadow: 0px 14px 80px rgb(34 35 58 / 20%);
padding: 40px 55px 45px 55px;
border-radius: 15px;
transition: all 0.3s;
}
Play around and resize the view window, and then test out toggling the responsive view in the preview window.
Related
I have tried looking at many questions on StackOverflow and none of them have helped me. I think that I have a more specific problem, there might be some type of CSS attribute that is stopping the div from centering. Maybe I need to use flexbox to solve this?
here is the JSX:
import { useState } from 'react'
import styles from '../styles/login.module.css'
import Head from 'next/head'
export default function Login() {
const [loginDetails, setLoginDetails] = useState({username: "", password: ""});
function handleUsernameChange(e) {
var value = e.target.value;
setLoginDetails({username: value, password: loginDetails.password});
}
function handlePasswordChange(e) {
var value = e.target.value;
setLoginDetails({username: loginDetails.username, password: value});
}
function SubmitLogin() {
console.log(loginDetails);
}
return (
<>
<Head>
<title>Login</title>
</Head>
<div className={styles.container}>
<h1 className={styles.subheading}>Login</h1>
<label>Username:</label>
<input type="text" placeholder="username" className={styles.input} onChange={handleUsernameChange} />
<label>Password:</label>
<input type="password" placeholder="password" className={styles.input} onChange={handlePasswordChange} />
<button className={styles.button} onClick={SubmitLogin}>Login</button>
</div>
</>
);
}
Here is the CSS:
.heading {
font-size: 3rem;
}
.subheading {
font-size: 2rem;
}
.pheading {
font-size: 1.5rem;
}
.paragraph {
margin-left: 1rem;
}
.container {
display: flex;
flex-direction: column;
gap: 10px;
margin: 0 auto;
width: 25%;
}
.input {
border-radius: 5px;
max-width: 200px;
height: 30px;
border: 1px solid #d7dbd9;
}
.input:focus {
outline: none;
border: 1px solid #67f0ab;
}
.button {
border: 2px solid #67f0ab;
border-radius: 5px;
color: #67f0ab;
background: none;
max-width: 100px;
height: 30px;
}
.button:hover {
background-color: #67f0ab;
color: #FFF;
}
.button:active {
background-color: #49de93;
}
The element I am trying to center is the div wrapping the login form. It has the class of .container, this class is what I was editing in my CSS to try and solve the problem. I can get the element to move to different spots, but I can't center it.
Ok so I figured out what the problem was, it was that the max-width of my container was larger than that of my widest element inside of the container, in this case it happened to be the inputs
I changed the max-width value of my container to 200px which is the same as my .input class, and the container and all of its elements were then centered.
Here is how the result I want to achieve:
enter image description here
Here is my code base:
let skillSetStr = useSkillset(userInfo.Skills);
// In some cases the db returns the userInfo in different objects.
// For now this fixes the problem.
if (userInfo.Skills === undefined) {
skillSetStr = skillStr;
}
return (
<div className="container--inner_modal user-preview-modal">
{skillSetStr ?
<div className="user-preview-info">
<div className="grid-item">Skillsets:</div>
<div className="grid-item user-preview-info_data">{skillSetStr}</div>
</div> : ""}
{location ?
<div className="user-preview-info">
<div className="grid-item">Location:</div>
<div className="grid-item user-preview-info_data">{location}</div>
</div> : ""}
{major ?
<div className="user-preview-info">
<div className="grid-item">Major:</div>
<div className="grid-item user-preview-info_data">{major}</div>
</div> : ""}
</div>
Here is how my website look like right now:
enter image description here
How can I achieve this in my react project?
Here is my scss file:
.user-preview-info {
display: grid;
grid-template-columns: 1fr 2fr;
.grid-item {
font-size: 18px;
text-align: left;
padding: 18px 0;
font-weight: 700;
}
.user-preview-info_data {
color: rgba(0, 27,17,0.7);
font-weight: 300;
}
}
.user-preview_message-button {
padding: 10px 20px;
background-color: #00B790;
border-radius: 24px;
color: white;
width: 200px;
font-size: 14px;
border: 0;
margin-top: 10px;
}
Skillsets section should include a component which accepts skillSetStr as props and returns a bunch of <span>s which you can style however you want.
All you need is some padding and a background/background-color.
I have never used React before, so I don't have a solid solution that answers your question, but this is how you can do it in plain CSS
For example:
<style>
.padding { padding: 5px 10px;}
/* for the most part background & background-color does the same thing */
.infoBg {background: #e7edff;}
.infoColor {color: #6380f1;}
.fit {width: fit-content; height: fit-content;}
.borderRound { border-radius: 5px;}
</style>
<h3 class="padding infoColor infoBg fit borderRound">Hello</h3>
I'm working on some basic styling for my personal project, and for some reason, most of the class selectors in my css file Header.css works, except headerOptionCount. Earlier, some other classes weren't working, but putting Header.css in a styles directory seemed to help, but now it is happening again. When changing margin-left and margin-right of headerOptionCount, nothing changes. When inspecting the element in dev tools, the styles dont show up at all.
Header.css:
.header {
height: 60px;
display: flex;
align-items: center;
background-color: #131921;
position: sticky;
top: 0;
z-index: 100;
}
.headerLogo {
width: 60px;
object-fit: contain;
margin: 0 10px;
}
.headerSearch {
display: flex;
flex: 1;
align-items: center;
border-radius: 24px;
}
.headerSearchInput {
width: 100%;
height: 12px;
padding: 10px;
border: none;
}
.headerSearchIcon {
padding: 5px;
height: 22px !important;
background-color: tomato;
}
.headerOptionLineOne {
font-size: 10px;
}
.headerOptionLineTwo {
font-size: 13px;
font-weight: 800;
}
.headerOptionBasket {
display: flex;
align-items: center;
color: white;
}
.headerOptionCount {
margin-left: 10px;
margin-right: 10px;
}
.headerNav {
display: flex;
justify-content: space-evenly;
}
.headerOption {
display: flex;
flex-direction: column;
margin-left: 10px;
margin-right: 10px;
color: white;
}
Here is my Header component that imports this css file.
Header.js:
import React from "react";
import logo from "../zipshopIcon.png";
import { Search, ShoppingCart } from "#material-ui/icons";
import "../styles/Header.css";
const Header = () => {
return (
<div className="header">
<img className="headerLogo" src={logo} alt="Logo" />
<div className="headerSearch">
<input className="headerSearchInput" type="text" />
{/* Logo */}
<Search className="headerSearchIcon" />
</div>
<div className="headerNav">
<div className="headerOption">
<span className="headerOptionLineOne">Hello Guest</span>
<span className="headerOptionLineTwo">Sign In</span>
</div>
<div className="headerOption">
<span className="headerOptionLineOne">Returns</span>
<span className="headerOptionLineTwo">& Orders</span>
</div>
<div className="headerOption">
<span className="headerOptionLineOne">Your</span>
<span className="headerOptionLineTwo">Prime</span>
</div>
<div className="headerOptionBasket">
<ShoppingCart />
<span className="headerOptionTwo headerBasketCount">0</span>
</div>
</div>
</div>
);
};
export default Header;
The import directory is definitely correct since the other styles work. I've tried using css modules, but it didnt fix anything. Should i try using scss? it just baffles me why class selectors cant even work when imported as css files. Any advice would be appreciated, thanks!
None of your elements in the js have the classname headerOptionCount, you need to give the element you want to have those styles the classname for it to work.
I would like to use a custom image in an input-group instead of a Bootstrap glyphicon without padding bottom (my image touch the bottom of the button), as you can see on this picture:
Actually, I use Bootstrap's glyphicon glyphicon-search:
<div class="input-group">
<input type="text" class="form-control" placeholder="Rechercher un produit, une référence ..."/>
<span class="input-group-addon">
<span aria-hidden="true" class="glyphicon glyphicon-search"></span>
<span class="hidden-xs text-upper-style">
Rechercher</span>
</span>
</div>
My issue is that I fail to replace glyphicon by my picture in my search bar.
I've tried to create CSS to mimic those of Bootstrap, but it always render bad:
CSS
.glyphi {
position: relative;
top: 1px;
display: inline-block;
font-style: normal;
font-weight: normal;
line-height: 1;
float: left;
display: block;
}
.glyphi.search {
background: url(../img/header/search.png);
background-size: cover;
}
.glyphi.normal {
width: 28px; //But Bootstrap glyphicon is 16x16...
height: 16px;
}
HTML
<span class="glyphicon glyphicon-search"></span>
Note that my image is not square (60x37 px).
Here is the picture that should replace the glyphicon:
What is the best Bootstrap way to do that?
Here is a Bootply of my code.
Thanks! :)
You can use simple img inside .input-group-addon instead of span.glyphicon and with some negative margins you can get the result you want.
HTML
<div class="input-group">
<input type="text" class="form-control" placeholder="Rechercher un produit, une référence ...">
<span class="input-group-addon">
<img src="http://i.stack.imgur.com/vr0uy.png">
<span class="hidden-xs text-upper-style">Rechercher</span>
</span>
</div>
CSS
.rechercheProduit .input-group-addon img{
height: 24px;
margin-right: -16px;
margin-bottom: -6px;
vertical-align:text-bottom; /* align the text */
}
Updated Bootply
You should have a look on how the glyphicon span works:
If you inspect it, you will see that the interesting part in this span is actually its pseudo-element, the :before that calls a font of icons as a content.
A few solutions are actually possible to resolve your problem.
Override
One of the solution would be to override that pseudo element by
redeclaring its content:
.rechercheProduit .input-group-addon {
/* Declaring the parent as relative so the .glyphicon-search child span
as a position absolute to its parent..
That probably doesn't make any sense. */
position: relative;
}
.rechercheProduit .glyphicon-search {
/* 'absolute' in the .input-group-addon context */
position: absolute;
top: auto;
bottom: 0;
left: 5px;
height: 80%;
width: auto;
overflow: hidden;
}
.rechercheProduit .glyphicon-search:before {
content: '';
display: block;
width: 50px; /* Generic width */
height: 100%;
background: url('http://i.stack.imgur.com/vr0uy.png') no-repeat;
background-size: auto 100%;
}
.rechercheProduit .text-upper-style {
/* relative to its context. Especially here to deal with the display order. */
position: relative;
margin-left: 20px;
}
Demo 1
Custom span
Another solution, which would probably be better, would be to
actually create your own span with your own pseudo-element (CSS is
similar to the last example, renaming the .glyphicon-search part
obviously):
<span class="input-group-addon">
<span class="search-icon"></span>
<span class="hidden-xs text-upper-style">
Rechercher</span>
</span>
Demo 2
Image
Even if I personally prefer having the icon as a background image
here (have a look on this question and its answers), declaring
the icon as an image is another solution that works.
c.f. the answer of tmg about that.
About the rest
To go beyond with your code, you should think about the fact that you are working in a form with an input[type="text"] as main input.
You’ll have to submit this form and unless you deal with a click event on this main span to submit your form, you’ll have to declare your rechercher span as an input as well (type=“submit”).
That would be semantically more correct and easier for you to deal with this button action in the future.
My final proposition would then be:
(also considering the "custom" span icon solution)
<div class="input-group">
<input type="text" class="form-control" placeholder="Rechercher un produit, une référence ...">
<label class="input-group-addon">
<span class="search-icon"></span>
<input type="submit" value="Rechercher" class="hidden-xs text-upper-style" />
</label>
</div>
-
.text-upper-style {
background: none;
text-transform: uppercase;
border: 0;
outline: 0;
}
.rechercheProduit .input-group-addon {
border: 0;
}
Demo 3
About the responsive, just declare a min-width on your label:
.rechercheProduit .input-group-addon {
min-width: 40px;
overflow: hidden;
}
Hope this makes sense. I'm open to any kind of suggestion, edit, etc...
Bon chance!
It's as easy as replace span glyphicon tag for your custom image tag forcing correct height and deleting top and bottom padding from text 'rechercher'.
So, add this to your html:
<span class="input-group-addon">
<img height="25" src="http://i.stack.imgur.com/vr0uy.png" alt="custom-magnifier">
<span class="hidden-xs text-upper-style">
Rechercher</span>
</span>
So, add this to your css:
.rechercheProduit .input-group-addon {
padding: 0 12px;
}
.rechercheProduit .input-group-addon {
vertical-align: bottom;
}
Here you have an example:
http://www.bootply.com/CAPEgZTt3J
You have to hide the default glyphicon then use custom image.
Try these lines:
.glyphicon-search::before {
content:none!important;
}
.glyphicon-search {
background-image:url(../ur-image);
height:20px;
width:20px;
background-repeat:no-repeat;
background-size:cover;
}
Here is the css that will replace the search icon
.glyphi {
background: rgba(0, 0, 0, 0) url("http://i.stack.imgur.com/vr0uy.png") no-repeat scroll 0 0 / contain;
display: inline-block;
font-style: normal;
font-weight: 400;
height: 16px;
line-height: 1;
position: relative;
top: 1px;
width: 60px;
}
You also need to resize the search icon because the parent element has padding.
This is my attemp, i hope this one can help you. i use absolute. Just try to view in full page, i working the responsive design.
* {
border-radius: 0 !important;
}
.rechercheProduit .input-group-addon {
border: 0px;
color: #ffffff;
background: #004392;
cursor: pointer;
}
.rechercheProduit:hover {
color: #fbba00;
}
.rechercheProduit .form-control,
.rechercheProduit .input-group-addon {
border: solid 2px #004392;
}
.rechercheProduit .input-group-addon {
-moz-border-radius: 0;
-webkit-border-w: 0;
border-radius: 0;
color: #ffffff;
background: #004392;
cursor: pointer;
}
.rechercheProduit .input-group-addon:hover {
color: #fbba00;
}
.text-upper-style {
text-transform: uppercase;
padding-left: 20px;
}
.glyphicon-search:before {
background: url(http://i.stack.imgur.com/vr0uy.png)center center;
background-size: contain;
background-repeat: no-repeat;
height: 25px;
width: 42px;
content: '';
z-index: 99;
position: absolute;
top: -15px;
left: -8px;
}
.glyphicon-search:before{
content: '' !important;
}
#media screen and (max-width: 767px){
.cus-icon{
padding: 0 10px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-8 col-md-6">
<form class="form-horizontal rechercheProduit">
<div class="input-group">
<input type="text" class="form-control" placeholder="Rechercher un produit, une référence ...">
<span class="input-group-addon">
<span aria-hidden="true" class="glyphicon glyphicon-search cus-icon"></span>
<span class="hidden-xs text-upper-style">
Rechercher</span>
</span>
</div>
</form>
</div>
One way would be to use a background-image on the input-group-addon + some padding-left and remove the glyphicon entirely:
* {
border-radius: 0 !important;
}
.rechercheProduit .input-group-addon {
border: 0px;
color: #ffffff;
background: #004392;
cursor: pointer;
}
.rechercheProduit:hover {
color: #fbba00;
}
.rechercheProduit .form-control,
.rechercheProduit .input-group-addon {
border: solid 2px #004392;
}
.rechercheProduit .input-group-addon {
-moz-border-radius: 0;
-webkit-border-w: 0;
border-radius: 0;
color: #ffffff;
background: #004392;
cursor: pointer;
background-image: url("http://i.stack.imgur.com/vr0uy.png");
background-position: 6px 3px;
background-repeat: no-repeat;
background-size: contain;
padding-left: 38px;
}
.rechercheProduit .input-group-addon:hover {
color: #fbba00;
}
.text-upper-style {
text-transform: uppercase;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-8 col-md-6">
<form class="form-horizontal rechercheProduit">
<div class="input-group">
<input class="form-control" placeholder="Rechercher un produit, une référence ..." type="text">
<span class="input-group-addon">
<span class="text-upper-style">
Rechercher</span>
</span>
</div>
</form>
</div>
You need of course to change the background-position, background-size, padding-left so it fits your image.
Adjust the background-size to define the size of the image, change the background-position to position the image inside the span and change the padding-left value to move the text further to the right.
You can override .glyphicon and set your image as a background for it and remove its icon
.rechercheProduit .input-group-addon span.glyphicon{
background: url(http://i.stack.imgur.com/vr0uy.png);
background-size: 100% 100%;
height: 24px;
width: 38px;
vertical-align: text-bottom;
margin: -6px -13px 0 0;
top: auto;
bottom: -6px;
z-index: 0;
}
.rechercheProduit .input-group-addon span.glyphicon:before{
content:''; // To remove its default icon
}
https://jsfiddle.net/ms5e0535/
Here is the HTML markup
<div class='container'>
<li class="options list-unstyled">
<div class="rank-label">
<span class="rank theme-inverse-color">1</span>
<span class="name">AAAAA</span>
<div class="move-btns">
<button type="button" class="btn btn-icon btn-up"><span class="icon icon-down">Down</span></button>
<button type="button" class="btn btn-icon btn-down"><span class="icon icon-up">Up</span></button>
</div>
</div>
</li>
</div>
And here is the less (css) code
.square (#size) {
width: #size;
height: #size;
}
.options {
li {
display: block;
width: 100%;
margin-bottom: 5px;
}
}
.container {
width: 50%;
border: 1px solid red;
}
.options {
font-size: 30px;
}
.text {
.flex-grow(1);
.align-items(center);
.justify-content(center);
}
.inverse-color {
color: blue;
}
.rank {
margin: auto;
padding-top: 2px;
display: inline-block;
.align-items(center);
.justify-content(center);
text-align: center;
background-color: rgba(0, 0, 0, 0.3);
border-radius: 50%;
.square(40px);
min-width: 40px;
margin-right: 10px;
}
.rank-label {
.display(flex);
}
.btn {
margin: 10px;
border: 1px solid red;
}
.name {
.display(flex);
.flex-grow(1);
.align-items(center);
padding-right: 30px;
min-height: 35px;
}
.move-btns {
.display(flex);
.flex-basis(auto);
.flex-shrink(0);
.flex-grow(0);
.justify-content(center);
}
So in browsers like chrome, Safari and IE11, the output looks exactly like I expected:
However in IE10, the alignment is off. It has somehow become:
the number and text 'AAAAA' are all shifted to right-hand side.
I have tried tweaking flex-grow and other parameters but they have no effect.
How can I fix this issue?
Here is a link to the code in codepen.io: http://codepen.io/kongakong/pen/bpygoV
I think all you need to do is turn on the autoprefixer in your code pen css settings and it will start working. Basically E10 runs on the old version of the flexbox syntax. So it needs the vendor prefixes. Good Luck.
Thanks to #orangeh0g 's answer, I checked the css generated by autoprefixer in my codepen code. I find that I only need to add
-ms-flex-positive: 1;
to the text css class and the misalignment will be fixed.