image will not scale to 100% of div properly? - css

I am trying to make the image take up the whole page for my component but cannot figure out what I am doing wrong?
this is how it currently looks and I cannot figure out how to ensure it takes up the extra whitespace marked in red too.
I tried setting the min width and height of the div it is contained in. Is it maybe I need to set the image up in the body but I was confused how to do that in react.
current page:
css:
.container {
background-image: url("../images/img.jpg");
background-repeat: no-repeat;
background-size: contain;
min-height: 100%;
min-width: 100%;
}
.default-button {
align-items: center;
background-clip: padding-box;
background-color: #fa6400;
border: 1px solid transparent;
border-radius: .25rem;
box-shadow: rgba(0, 0, 0, 0.02) 0 1px 3px 0;
box-sizing: border-box;
color: #fff;
cursor: pointer;
display: inline-flex;
font-family: "Rams Black";
font-size: 16px;
font-weight: 600;
justify-content: center;
line-height: 1.25;
margin: 0;
min-height: 3rem;
padding: calc(.875rem - 1px) calc(1.5rem - 1px);
position: relative;
text-decoration: none;
transition: all 250ms;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
vertical-align: baseline;
width: auto;
}
.default-button:hover,
.default-button:focus {
background-color: #fb8332;
box-shadow: rgba(0, 0, 0, 0.1) 0 4px 12px;
}
.default-button:hover {
transform: translateY(-1px);
}
.default-button:active {
background-color: #c85000;
box-shadow: rgba(0, 0, 0, .06) 0 2px 4px;
transform: translateY(0);
}
.powered-by-strava {
display: flex;
align-items: center;
justify-content: center;
}
.connect-btn {
background-color: transparent;
padding: 0;
border: none;
background: none;
}
component where image is rendered:
return (
<div className="container">
<button className="connect-btn" onClick={stravaAuth}><img src={connectSVG}
alt="Connect to Strava"/></button>
<button onClick={changeTheme}>Change mode</button>
<div className="powered-by-strava">
<img className="strava-img" src={poweredSVG}/>
</div>
</div>
);

Related

CSS pseudo element should stay if parent is active

I am playing with CSS pseudo elements. As soon as the menu button gets hovered it receives a small orange underline. This element should stay as soon as the dropdown-container is visible. Is there a light weight solution to achieve such behaviors?
In case pseudo elements arenĀ“t the best solution for my need, I am open minded for different solutions.
https://jsfiddle.net/j3g49fwd/
$(".dropdown-btn").click(function() {
this.classList.toggle("increase")
$(".dropdown-container").toggle()
})
.wrapper {
position: relative;
top: 5vh;
margin: 40px 30px 30px 30px;
height: fit-content;
background: white;
border-radius: 10px;
box-shadow: -10px -10px 10px rgba(255, 255, 255, 0.5),
15px 15px 15px rgba(70, 70, 70, 0.12);
padding: 1vw;
}
.dropdown-btn {
display: flex;
justify-content: center;
padding: 10px 0px 10px 20px;
text-decoration: none;
display: block;
border: 1px solid transparent;
background: none;
height: fit-content;
min-height: 5vh;
width: 100%;
text-align: left;
cursor: pointer;
outline: none;
transition: all 0.3s ease-in-out;
}
.dropdown-btn:after {
content: "";
display: block;
margin: 3px 0 0 0;
width: 0;
height: 1px;
background: rgb(242, 123, 57);
transition: all 0.4s;
}
.dropdown-btn:hover::after {
width: 100%;
}
.dropdown-container {
display: none;
padding: 10px 20px 10px 20px;
margin: 0 0 2vh 0;
}
.increase {
font-size: 20px !important;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div class="wrapper">
<button class="dropdown-btn">I am a menu button
<label class="menu-title" id="flow-menu-title"></label>
<i class="fa-solid fa-gear col-1 dropdown-icon"></i>
</button>
<div class="dropdown-container">
Hello Stackoverflow
</div>
</div>
</body>
</html>
if I understand you correctly, you should be able to edit the CSS just like this:
.dropdown-btn.increase::after,.dropdown-btn:hover::after {
width: 100%;
}
https://jsfiddle.net/bkefg9dt/

Tooltip gets cut off by div pure CSS

.color-palette {
border-top: 2px solid lightgrey;
max-height: 32vh;
z-index: 1;
background: rgba(0, 0, 0, 0.75);
width: 90vw;
bottom: 2.75rem;
border-radius: 10px;
display: flex;
flex-flow: row wrap;
justify-content: center;
align-items: flex-end;
padding: 0.75rem 0.5rem;
position: absolute;
overflow-y: auto;
overflow-x: hidden;
box-shadow: 0px 5px 10px black;
animation-name: zoomIn;
animation-duration: 0.5s;
}
button {
font-family: inherit;
font-size: 0.8rem;
line-height: 0.9;
width: 3.75rem;
height: 3.75rem;
margin: 0.45rem 0.3rem;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
transition: all 0.5s;
border: none;
outline: none;
text-decoration: none;
text-align: center;
text-shadow: 0 -1px 0px rgba(0, 0, 0, 0.3);
box-shadow: inset 0px 1px 0px grey, 0px 3px 0px 0px lightgrey,
0px 8px 5px #999;
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
font-family: "Comic Neue", cursive;
width: 8.5rem;
font-size: 1rem;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 500;
bottom: 110%;
left: 35%;
margin-left: -60px;
}
span {
display: none;
}
.tooltip .tooltiptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: black transparent transparent transparent;
}
.tooltip:hover .tooltiptext {
visibility: visible;
display: block;
}
<div class="color-palette">
<button class="tooltip">
<span class="tooltiptext">Cannot duplicate</span>
</button>
</div>
I got the tooltip code from https://www.w3schools.com/css/css_tooltip.asp.
I tried the answer here: CSS tooltip getting cut off
And have applied overflow: visible on my color-palette instead of overflow-y: auto; overflow-x: hidden; but this happened:
Yes, the tooltip worked, but my buttons were already outside the div (.color-palette).
I want this to work without removing the bottom arrow of the tooltip, without moving the tooltip downwards, without increasing the div to make the tooltip fit inside. All I want is to make the tooltip overlap. What to do?
Try changing value from 110 to 95 in the class:
.tooltip .tooltiptext {
bottom: 95%;
}
Update:
change top value in class
.tooltip .tooltiptext::after {
top: 100%;
}
Try this fiddle: https://jsfiddle.net/ecxobpg3/38/

CSS transition - invert the origin/direction

I'd like to make my label animation from top to bottom instead of from bottom to top. So the top is going to open and the bottom stay there:
div.label4 {
background-color: #4D6EF6;
width: 278px;
height: 388px;
margin: 10px auto;
text-align: center;
vertical-align: middle;
color: #4D6EF6;
font-size: 30px;
font-weight: bold;
border-radius: 4px;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-decoration: none;
border: transparent;
float: left;
transition: width 1.5s, height 1.5s;
transition-duration: 1.5s
}
div.label4:hover {
height: 194px;
}
<div class="label4"></div>
Just wrap it in a parent with flex-direction: column-reverse and you're done:
.parent {
display: flex;
flex-direction: column-reverse;
height: 388px;
width: 278px;
}
div.label4 {
background-color: #4D6EF6;
width: 278px;
height: 388px;
margin: 10px auto;
text-align: center;
vertical-align: middle;
color: #4D6EF6;
font-size: 30px;
font-weight: bold;
border-radius: 4px;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-decoration: none;
border: transparent;
float: left;
transition: width 1.5s, height 1.5s;
transition-duration: 1.5s
}
div.label4:hover {
height: 194px;
}
.parent {
display: flex;
flex-direction: column-reverse;
height: 388px;
width: 278px;
}
<div class="parent">
<div class="label4"></div>
</div>
If you can alter the HTML you could create a container, and then position .label4 using position: absolute and bottom
.parent {
height: 388px;
padding-top: 10px;
position: relative;
}
div.label4 {
background-color: #4D6EF6;
width: 278px;
height: 388px;
margin: 10px auto;
text-align: center;
vertical-align: middle;
color: #4D6EF6;
font-size: 30px;
font-weight: bold;
border-radius: 4px;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-decoration: none;
border: transparent;
float: left;
transition: width 1.5s, height 1.5s;
transition-duration: 1.5s;
position: absolute;
bottom: 0;
}
div.label4:hover {
height: 194px;
}
<div class="parent">
<div class="label4"></div>
</div>
You can achieve your desire animation by transform which is more flexible and better and set transform-origin to each side your element,
div.label4 {
background-color: #4D6EF6;
width: 278px;
height: 388px;
margin: 10px auto;
text-align: center;
color: #4D6EF6;
font-size: 30px;
font-weight: bold;
border-radius: 4px;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-decoration: none;
border: transparent;
transition: transform 1.5s;
transform: scaleY(1);
transform-origin: bottom center;
}
div.label4:hover {
transform: scaleY(0.5);
}
<div class="label4"></div>

flex box parent wrappers do not fill height of the page

Here is my JSFiddle...https://jsfiddle.net/5xt7pt7f/
I get that there is a lot going on here, I will try to isolate my issue as best as possible.
There are two parent wrappers...
<div class="video-section">
...
<div class="chat-section">
As you can see in the fiddle, their height is not 100%, it seems to have some sort of max-height because they do not always fill the page. My html structure is something like...
<div id="app">
...
<div class="chat-navbar">....</div>
<div class="chat-wrapper">
<div class="video-section">
<div class="chat-section">
...
#app is the main container. I want .chat-navbar to be at the top and the .chat-wrapper to be below it. I accomplished this through...
div#app {
display: flex;
flex: 1;
flex-direction: column; }
Next I wanted .video-section and .chat-section to be side by side, I accomplished this through...
.chat-wrapper {
display: flex;
flex: 1;
flex-direction: row;
}
However, these two wrappers do not fill the height of the page. I do not care if the canvas elements inside fill the page, but I do need the parent wrappers to fill up the page.
This is what it look like on my local...
As you can see there is a lot of white space at the bottom because the elements do not have full height. I thought flex:1 would have resolved this.
Try using display:flex; on the div containing chat-navbar and chat-wrapper (I gave it id="chatcon") and then use flex-grow:1; on chat-wrapper. I commented one of the canvases and changed navbar color to red, to help notice the difference.
Here's a codepen
body, html {
margin: 0;
font-family: 'Libre Baskerville', serif; }
#chatcon{
min-height:100vh;
display:flex;
flex-direction:column;
}
a {
text-decoration: none;
margin: 5px; }
a:active, a:visited {
color: inherit; }
.chat-wrapper {
display: flex;
flex: 1;
flex-direction: row;
}
.chat-section {
border: none;
border-left: 1px solid #ccc;
box-sizing: border-box;
padding-left: 0.5em;
display: flex;
flex: 1;
flex-direction: column;
margin-left: 5px; }
div#app {
display: flex;
flex: 1;
flex-direction: column; }
.chat-section ul {
overflow-y: auto;
flex: 1;
margin-bottom: 0;
padding-left: 0.5em; }
.chat-section ul li {
text-decoration: none;
list-style-type: none; }
.chat-section ul li + li {
margin-top: 7px; }
.chat-section textarea {
resize: none;
border: none;
border-top: 1px solid #ccc;
box-sizing: border-box;
margin-left: -0.5em; }
.chat-section textarea:focus {
outline: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none; }
.video-section {
display: flex;
flex: 1;
text-align: center; }
.videos {
flex: 1;
display: flex;
max-width: 800px;
flex-direction: column;
align-content: stretch; }
.chat-navbar {
border-left: 1px solid #ccc;
box-sizing: border-box;
padding-top: 1em;
display: flex;
flex: 1; }
.localCanvas, .remoteCanvas {
background-color: black;
margin-left: 5px;
margin-right: 5px;
-webkit-box-shadow: 9px 5px 17px -6px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 9px 5px 17px -6px rgba(0, 0, 0, 0.75);
box-shadow: 9px 5px 17px -6px rgba(0, 0, 0, 0.75); }
.localCanvas {
margin-top: 5px;
margin-bottom: 5px; }
canvas.remoteCanvas {
margin-top: 5px; }
.auth-container {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
flex-direction: column;
background: #004FF9;
/* For browsers that do not support gradients */
background: -webkit-linear-gradient(to right, #FFF94C, #004FF9);
/* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(to right, #FFF94C, #004FF9);
/* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(to right, #FFF94C, #004FF9);
/* For Firefox 3.6 to 15 */
background: linear-gradient(to right, #FFF94C, #004FF9);
/* Standard syntax */
background-size: cover; }
.loginForm, .registerForm {
width: 500px;
height: 600px;
display: block;
margin-left: auto;
margin-right: auto;
position: absolute;
top: 130px;
left: 0;
right: 0; }
.loginWrap {
width: 500px;
float: left;
height: 100%;
background: rgba(255, 255, 255, 0.75);
-webkit-box-shadow: 4px 3px 14px -5px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 4px 3px 14px -5px rgba(0, 0, 0, 0.75);
box-shadow: 4px 3px 14px -5px rgba(0, 0, 0, 0.75); }
.bodyLogin {
overflow: hidden;
height: 100%; }
.bg_image {
height: 1000px;
width: 100%; }
h1 {
font-family: 'Roboto', sans-serif;
color: #87909c;
font-weight: bolder;
text-align: center;
font-size: 1.5em;
margin-top: 20px; }
img.logo_image {
width: 500px; }
img.title_image {
width: 200px;
margin-left: auto;
display: block;
margin-right: auto;
margin-top: -90px; }
label {
font-size: 12px;
font-weight: bold;
color: #87909c;
float: left;
clear: both;
font-family: 'Roboto', sans-serif;
margin-left: 30px;
margin-top: 15px; }
input[type="text"], input[type="password"] {
float: left;
margin-top: 15px;
clear: both;
margin-left: 30px;
font-size: 1.3em;
width: 80%;
outline: none;
border: none;
padding: 10px;
padding-left: 10px; }
.login_btn, .register_btn {
float: left;
clear: left;
font-family: 'Roboto', sans-serif;
background: #7289da;
border: solid 1px #7289da;
width: 84%;
margin-left: 30px;
margin-top: 50px;
padding: 20px;
border-radius: 5px;
font-size: 1em;
color: white;
cursor: pointer; }
.registerLinkWrap, .loginLinkWrap {
float: left;
clear: left;
margin-left: 30px; }
a.register_link, a.login_link {
float: left;
margin-top: 11px;
font-size: 13px;
color: black;
font-family: 'Roboto', sans-serif; }
a.register_link:hover, a.login_link:hover {
text-decoration: underline; }
p.register_sentence, p.login_sentence {
clear: left;
float: left;
font-size: 12px;
color: #3e4956;
font-family: 'Roboto', sans-serif; }
.errUsername, .errPassword, .errRegister {
float: left;
margin-left: 30px;
margin-top: 3px;
color: red;
font-size: 0.8em;
font-family: 'Roboto', sans-serif; }
.reg_success {
position: absolute;
background: #f2fae3;
width: 100%;
text-align: center;
padding: 10px;
font-family: 'Roboto', sans-serif;
color: #94b639;
border-bottom: solid 3px #94b639; }
.reg_neutral {
display: none; }
/*# sourceMappingURL=styles.css.map*/
.chat-navbar{
flex-shrink:0;
flex-grow:0;
height:70px;
background-color:red;
}
<div id="app">
<div id="chatcon" data-reactroot="">
<div class="chat-navbar">
Logout
</div>
<div class="chat-wrapper">
<div class="video-section">
<div class="videos">
<canvas class="remoteCanvas" width="320" height="240"></canvas>
<!-- <canvas class="localCanvas" width="320" height="240"></canvas> -->
</div>
</div>
<div class="chat-section">
<ul>No messages</ul>
<textarea placeholder="Type a message" rows="2"></textarea>
</div>
</div></div></div>
To simplify your requirement, add relative heights wherever required so that your wrappers occupy the entirety of the page.
Give html, body { height: 100%; } which resolves the majority of issues and then further on.
Created a fiddle for you: https://jsfiddle.net/nashcheez/u7bmL0nm/
body,
html {
margin: 0;
font-family: 'Libre Baskerville', serif;
height: 100%;
}
a {
text-decoration: none;
margin: 5px;
}
a:active,
a:visited {
color: inherit;
}
.chat-wrapper {
display: flex;
flex: 1;
flex-direction: row;
height: 100%;
}
.chat-section {
border: none;
border-left: 1px solid #ccc;
box-sizing: border-box;
padding-left: 0.5em;
display: flex;
flex: 1;
flex-direction: column;
margin-left: 5px;
}
div#app {
display: flex;
flex: 1;
flex-direction: column;
height: 100%;
}
.chat-section ul {
overflow-y: auto;
flex: 1;
margin-bottom: 0;
padding-left: 0.5em;
}
.chat-section ul li {
text-decoration: none;
list-style-type: none;
}
.chat-section ul li + li {
margin-top: 7px;
}
.chat-section textarea {
resize: none;
border: none;
border-top: 1px solid #ccc;
box-sizing: border-box;
margin-left: -0.5em;
}
.chat-section textarea:focus {
outline: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.video-section {
display: flex;
flex: 1;
text-align: center;
}
.videos {
flex: 1;
display: flex;
max-width: 800px;
flex-direction: column;
align-content: stretch;
}
.chat-navbar {
border-left: 1px solid #ccc;
box-sizing: border-box;
padding-top: 1em;
display: flex;
flex: 1;
}
.localCanvas,
.remoteCanvas {
background-color: black;
margin-left: 5px;
margin-right: 5px;
-webkit-box-shadow: 9px 5px 17px -6px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 9px 5px 17px -6px rgba(0, 0, 0, 0.75);
box-shadow: 9px 5px 17px -6px rgba(0, 0, 0, 0.75);
height: 50%;
}
.localCanvas {
margin-top: 5px;
margin-bottom: 5px;
}
canvas.remoteCanvas {
margin-top: 5px;
}
.auth-container {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
flex-direction: column;
background: #004FF9;
/* For browsers that do not support gradients */
background: -webkit-linear-gradient(to right, #FFF94C, #004FF9);
/* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(to right, #FFF94C, #004FF9);
/* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(to right, #FFF94C, #004FF9);
/* For Firefox 3.6 to 15 */
background: linear-gradient(to right, #FFF94C, #004FF9);
/* Standard syntax */
background-size: cover;
}
.loginForm,
.registerForm {
width: 500px;
height: 600px;
display: block;
margin-left: auto;
margin-right: auto;
position: absolute;
top: 130px;
left: 0;
right: 0;
}
.loginWrap {
width: 500px;
float: left;
height: 100%;
background: rgba(255, 255, 255, 0.75);
-webkit-box-shadow: 4px 3px 14px -5px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 4px 3px 14px -5px rgba(0, 0, 0, 0.75);
box-shadow: 4px 3px 14px -5px rgba(0, 0, 0, 0.75);
}
.bodyLogin {
overflow: hidden;
height: 100%;
}
.bg_image {
height: 1000px;
width: 100%;
}
h1 {
font-family: 'Roboto', sans-serif;
color: #87909c;
font-weight: bolder;
text-align: center;
font-size: 1.5em;
margin-top: 20px;
}
img.logo_image {
width: 500px;
}
img.title_image {
width: 200px;
margin-left: auto;
display: block;
margin-right: auto;
margin-top: -90px;
}
label {
font-size: 12px;
font-weight: bold;
color: #87909c;
float: left;
clear: both;
font-family: 'Roboto', sans-serif;
margin-left: 30px;
margin-top: 15px;
}
input[type="text"],
input[type="password"] {
float: left;
margin-top: 15px;
clear: both;
margin-left: 30px;
font-size: 1.3em;
width: 80%;
outline: none;
border: none;
padding: 10px;
padding-left: 10px;
}
.login_btn,
.register_btn {
float: left;
clear: left;
font-family: 'Roboto', sans-serif;
background: #7289da;
border: solid 1px #7289da;
width: 84%;
margin-left: 30px;
margin-top: 50px;
padding: 20px;
border-radius: 5px;
font-size: 1em;
color: white;
cursor: pointer;
}
.registerLinkWrap,
.loginLinkWrap {
float: left;
clear: left;
margin-left: 30px;
}
a.register_link,
a.login_link {
float: left;
margin-top: 11px;
font-size: 13px;
color: black;
font-family: 'Roboto', sans-serif;
}
a.register_link:hover,
a.login_link:hover {
text-decoration: underline;
}
p.register_sentence,
p.login_sentence {
clear: left;
float: left;
font-size: 12px;
color: #3e4956;
font-family: 'Roboto', sans-serif;
}
.errUsername,
.errPassword,
.errRegister {
float: left;
margin-left: 30px;
margin-top: 3px;
color: red;
font-size: 0.8em;
font-family: 'Roboto', sans-serif;
}
.reg_success {
position: absolute;
background: #f2fae3;
width: 100%;
text-align: center;
padding: 10px;
font-family: 'Roboto', sans-serif;
color: #94b639;
border-bottom: solid 3px #94b639;
}
.reg_neutral {
display: none;
}
<div id="app">
<div style="height: 100%;" data-reactroot="">
<div class="chat-navbar">
Logout
</div>
<div class="chat-wrapper">
<div class="video-section">
<div class="videos">
<canvas class="remoteCanvas" width="320" height="240"></canvas>
<canvas class="localCanvas" width="320" height="240"></canvas>
</div>
</div>
<div class="chat-section">
<ul>No messages</ul>
<textarea placeholder="Type a message" rows="2"></textarea>
</div>
</div>
</div>
</div>
I see that you gave div#app both display: flex and flex: 1. Do note that the flex: 1 does not do anything here, it is a flex child property.
So for div#app to fill page it need a height, here given min-height: 100vh. Now you can give for example the <div data-reactroot> element flex: 1 to fill its parent (light blue).
Any child having a parent with display: flex; flex-direction: column only need flex: 1 to fill vertical space, if it has flex-direction: row it will need a height, where height: 100% normally work.
These 2 rules shows how to
div#app {
display: flex;
flex-direction: column;
min-height: 100vh;
}
div[data-reactroot] {
flex: 1;
background: lightblue;
}
Hope this makes it clear how it works, and from here you can apply the same logic your way down in the markup.
body,
html {
margin: 0;
font-family: 'Libre Baskerville', serif;
}
a {
text-decoration: none;
margin: 5px;
}
a:active,
a:visited {
color: inherit;
}
.chat-wrapper {
display: flex;
flex: 1;
flex-direction: row;
}
.chat-section {
border: none;
border-left: 1px solid #ccc;
box-sizing: border-box;
padding-left: 0.5em;
display: flex;
flex: 1;
flex-direction: column;
margin-left: 5px;
}
div#app {
display: flex;
flex-direction: column;
min-height: 100vh;
}
div[data-reactroot] {
flex: 1;
background: lightblue;
}
.chat-section ul {
overflow-y: auto;
flex: 1;
margin-bottom: 0;
padding-left: 0.5em;
}
.chat-section ul li {
text-decoration: none;
list-style-type: none;
}
.chat-section ul li + li {
margin-top: 7px;
}
.chat-section textarea {
resize: none;
border: none;
border-top: 1px solid #ccc;
box-sizing: border-box;
margin-left: -0.5em;
}
.chat-section textarea:focus {
outline: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.video-section {
display: flex;
flex: 1;
text-align: center;
}
.videos {
flex: 1;
display: flex;
max-width: 800px;
flex-direction: column;
align-content: stretch;
}
.chat-navbar {
border-left: 1px solid #ccc;
box-sizing: border-box;
padding-top: 1em;
display: flex;
flex: 1;
}
.localCanvas,
.remoteCanvas {
background-color: black;
margin-left: 5px;
margin-right: 5px;
-webkit-box-shadow: 9px 5px 17px -6px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 9px 5px 17px -6px rgba(0, 0, 0, 0.75);
box-shadow: 9px 5px 17px -6px rgba(0, 0, 0, 0.75);
}
.localCanvas {
margin-top: 5px;
margin-bottom: 5px;
}
canvas.remoteCanvas {
margin-top: 5px;
}
.auth-container {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
flex-direction: column;
background: #004FF9;
/* For browsers that do not support gradients */
background: -webkit-linear-gradient(to right, #FFF94C, #004FF9);
/* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(to right, #FFF94C, #004FF9);
/* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(to right, #FFF94C, #004FF9);
/* For Firefox 3.6 to 15 */
background: linear-gradient(to right, #FFF94C, #004FF9);
/* Standard syntax */
background-size: cover;
}
.loginForm,
.registerForm {
width: 500px;
height: 600px;
display: block;
margin-left: auto;
margin-right: auto;
position: absolute;
top: 130px;
left: 0;
right: 0;
}
.loginWrap {
width: 500px;
float: left;
height: 100%;
background: rgba(255, 255, 255, 0.75);
-webkit-box-shadow: 4px 3px 14px -5px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 4px 3px 14px -5px rgba(0, 0, 0, 0.75);
box-shadow: 4px 3px 14px -5px rgba(0, 0, 0, 0.75);
}
.bodyLogin {
overflow: hidden;
height: 100%;
}
.bg_image {
height: 1000px;
width: 100%;
}
h1 {
font-family: 'Roboto', sans-serif;
color: #87909c;
font-weight: bolder;
text-align: center;
font-size: 1.5em;
margin-top: 20px;
}
img.logo_image {
width: 500px;
}
img.title_image {
width: 200px;
margin-left: auto;
display: block;
margin-right: auto;
margin-top: -90px;
}
label {
font-size: 12px;
font-weight: bold;
color: #87909c;
float: left;
clear: both;
font-family: 'Roboto', sans-serif;
margin-left: 30px;
margin-top: 15px;
}
input[type="text"],
input[type="password"] {
float: left;
margin-top: 15px;
clear: both;
margin-left: 30px;
font-size: 1.3em;
width: 80%;
outline: none;
border: none;
padding: 10px;
padding-left: 10px;
}
.login_btn,
.register_btn {
float: left;
clear: left;
font-family: 'Roboto', sans-serif;
background: #7289da;
border: solid 1px #7289da;
width: 84%;
margin-left: 30px;
margin-top: 50px;
padding: 20px;
border-radius: 5px;
font-size: 1em;
color: white;
cursor: pointer;
}
.registerLinkWrap,
.loginLinkWrap {
float: left;
clear: left;
margin-left: 30px;
}
a.register_link,
a.login_link {
float: left;
margin-top: 11px;
font-size: 13px;
color: black;
font-family: 'Roboto', sans-serif;
}
a.register_link:hover,
a.login_link:hover {
text-decoration: underline;
}
p.register_sentence,
p.login_sentence {
clear: left;
float: left;
font-size: 12px;
color: #3e4956;
font-family: 'Roboto', sans-serif;
}
.errUsername,
.errPassword,
.errRegister {
float: left;
margin-left: 30px;
margin-top: 3px;
color: red;
font-size: 0.8em;
font-family: 'Roboto', sans-serif;
}
.reg_success {
position: absolute;
background: #f2fae3;
width: 100%;
text-align: center;
padding: 10px;
font-family: 'Roboto', sans-serif;
color: #94b639;
border-bottom: solid 3px #94b639;
}
.reg_neutral {
display: none;
}
/*# sourceMappingURL=styles.css.map*/
<div id="app">
<div data-reactroot="">
<div class="chat-navbar">
Logout
</div>
<div class="chat-wrapper">
<div class="video-section">
<div class="videos">
<canvas class="remoteCanvas" width="320" height="240"></canvas>
<canvas class="localCanvas" width="320" height="240"></canvas>
</div>
</div>
<div class="chat-section">
<ul>No messages</ul>
<textarea placeholder="Type a message" rows="2"></textarea>
</div>
</div>
</div>
</div>

Text wont align on horizontal and vertical centers

I am trying to work on the following example for a user profile.
I have a problem with the text on my various fields though. I would like them to be centered horizontally and vertically.
Using
vertical-align: middle;
Did not work for me, or I did something wrong.
How can I make it so each text snippet is perfectly centered on its respective container?
Here's the solution:
/* --------------------------------
Primary style
-------------------------------- */
#font-face {
font-family: 'Roboto';
src: url('../fonts/roboto/Roboto-Regular.ttf');
font-weight: normal;
font-style: normal;
}
*,
*:before,
*:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
div {
display: block;
}
html,
body {
background: #f1f1f1;
font-family: 'Roboto', sans-serif;
padding: 1em;
}
h1 {
text-align: center;
color: #a8a8a8;
font-size: 200%;
}
.user-data {
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
position: relative;
overflow: hidden;
cursor: pointer;
display: table;
width: 100%;
height: 85px;
background: white;
margin: 0 auto;
margin-top: 1em;
margin-bottom: 20px;
border-radius: 8px;
-webkit-transition: all 250ms;
transition: all 250ms;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.response-layer {
vertical-align: middle;
display: table-cell;
text-align: center;
font-size: 200%;
color: #a8a8a8;
}
#user-action-text {
color: #f1f1f1;
font-size: 400%;
}
#user-name {
border: 0;
outline: 0;
padding: 0;
margin: 0px;
margin-top: 10px;
width: 304px;
height: 55px;
color: white;
}
#user-action {
background: #e74c3c;
height: 134px;
}
#user-position {
height: 74px;
}
#user-uuid {
height: 54px;
}
section {
max-width: 650px;
text-align: center;
margin: 20px auto;
}
section img {
border: 0;
outline: 0;
padding: 0;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
display: block;
width: 100%;
margin-top: 1em;
-webkit-transition: all 250ms;
transition: all 250ms;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
resize: none;
}
.half {
float: left;
width: 48%;
margin-bottom: 1em;
}
.right {
width: 50%;
}
.left {
margin-right: 2%;
}
.user-data:hover {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
section img:hover {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
#-webkit-keyframes loading {
0%, 100% {
margin-top: -50px;
box-shadow: 0px 55px 40px 0px rgba(0, 0, 0, 0.3);
}
30%,
80% {
margin-top: 0px;
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.5);
}
}
#keyframes loading {
0%, 100% {
margin-top: -50px;
box-shadow: 0px 55px 40px 0px rgba(0, 0, 0, 0.3);
}
30%,
80% {
margin-top: 0px;
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.5);
}
}
#media (max-width: 690px) {
.half {
width: 304px;
float: none;
margin-bottom: 0;
}
}
/* Clearfix */
.activity-detail:before,
.activity-detail:after {
content: " ";
/* 1 */
display: table;
/* 2 */
}
.activity-detail:after {
clear: both;
}
<h1>New Activity Details</h1>
<section class="activity-detail">
<div class="half right" id="image-data">
<img src="img/default-avatar.png" alt="Profile Photo" style="width:304px;height:304px;" id="profile-photo">
<a class="user-data" id="user-name">
<div class="response-layer">Green Leaf</div>
</a>
</div>
<div class="half left" id="general-data">
<a class="user-data" id="user-action">
<div class="response-layer" id="user-action-text">Greetings</div>
</a>
<a class="user-data" id="user-position">
<div class="response-layer">Developer</div>
</a>
<a class="user-data" id="user-uuid">
<div class="response-layer">324124535345</div>
</a>
</div>
</section>
On the parent div .user-data I changed display to table.
On the child div .response-layer (the one containing "Greetings") I changed the display to table-cell. Now the vertical align works.
Here's the link to the codepen: Codepen
Replacing
vertical-align: middle;
with
position: relative;
top: 25%;
does the trick.
Edit: The answer above is much cleaner

Resources