I am developing an application in Microsoft Blazor and I have a problem with the UI when I am resizing the window.
Normally if the content fits into the window, there is no blank space on the topbar/header:
But when I am shrinking the window and scrolling to the right side, there is blank space:
Seems that even the content of the container "content" is large, header is not stretching...
Here is my MainLayout:
<div class="page">
<Sidebar />
<div class="main">
<Header />
<article class="content px-4">
<AuthorizeView>
<NotAuthorized>
<div class="row">
<div class="col-md-4">
<p>Please sign in to use the Platform...</p>
</div>
</div>
</NotAuthorized>
<Authorized>
#Body
</Authorized>
</AuthorizeView>
</article>
</div>
Here is the css of the Page:
.page {
position: relative;
display: flex;
flex-direction: row;
height: 100vh;
width: 100%;
}
Here is the css of the Main:
.main {
flex: 1;
top: 0px;
left: 0px;
overflow-y: scroll;
}
Here is the css od the Sidebar:
.sidebar {
top: 0px;
left: 0px;
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
.sidebar_clp { //Colapsed State
width: 110px;
overflow-x: hidden;
overflow-y: hidden;
}
.sidebar_exp { //Expanded State
width: 300px;
overflow-x: hidden;
overflow-y: scroll;
}
Here is the css of the Header:
.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
position: sticky;
top: 0;
z-index: 1;
}
Here is the css of the Content:
.content {
padding-top: 1.1rem;
flex: 1;
top: 0px;
left: 0px;
}
Any ideas how can this be fixed?
After lot of trials, I ended up with this setting:
.top-row {
top: 0;
z-index: 1;
display: flex;
height: 3.5rem;
position: absolute;
align-items: center;
justify-content: flex-end;
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
width: -webkit-fill-available;
}
The lines that are making the difference are:
position: absolute;
width: -webkit-fill-available;
Related
This question already has answers here:
Center image using text-align center?
(28 answers)
How to vertically align an image inside a div
(37 answers)
Closed last month.
I have a login form and would like to center the logo the same way the "signin" text is centered.
In fact, the logo always remains at the top left. I don't understand why the logo is not centered? If you have a solution to propose I am very very interested.
I would also like to understand the technique to make this logo responsive, please.
Thank you for your answer.
.parent {
position: absolute;
top: 10%;
left: 15%;
}
.wrapper {
position: relative;
width: 70vw;
height: 80vh;
background: #fff;
border-radius: 15px;
box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.3), 0 6px 20px 0 rgba(0, 0, 0, 0.3);
overflow: hidden;
}
.wrapper::before {
content: "";
position: absolute;
top: 0;
left: -50%;
width: 100%;
height: 100%;
background: linear-gradient(-45deg, #79df4a, #8673A1);
z-index: 6;
transform: translateX(100%);
transition: 1s ease-in-out;
}
.logo img {
position: absolute;
display: flex;
align-items: center;
justify-content: space-around;
height: 75px;
}
.signin {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: space-around;
z-index: 5;
}
form {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 40%;
min-width: 238px;
padding: 0 10px;
}
form.sign-in-form {
opacity: 1;
transition: 0.5s ease-in-out;
transition-delay: 1s;
}
.title {
font-size: 35px;
color: #8673A1;
margin-bottom: 10px;
}
.panels-wrapper {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: space-around;
}
.panel {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
width: 35%;
min-width: 238px;
padding: 0 10px;
text-align: center;
z-index: 6;
}
.left-panel {
pointer-events: none;
}
.content {
color: #fff;
transition: 1.1s ease-in-out;
transition-delay: 0.5s;
}
.left-panel .content {
transform: translateX(-200%);
}
.right-panel .content {
transform: translateX(0);
}
.signin_item_block {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 40%;
min-width: 238px;
padding: 0 10px;
}
.signin_item_block.sign-in-block-form {
opacity: 0;
transition: 0.5s ease-in-out;
transition-delay: 1s;
}
/*Responsive*/
#media (max-width:779px) {
.wrapper {
width: 100vw;
height: 100vh;
background-color: red;
}
}
#media (max-width:635px) {
.wrapper::before {
display: none;
}
form {
width: 80%;
}
.signin_item_block.sign-in-block-form {
display: none;
}
.wrapper.sign-up-mode2 form.sign-in-block-form {
display: flex;
opacity: 1;
}
.wrapper.sign-up-mode2 form.sign-in-form {
display: none;
}
.panels-wrapper {
display: none;
}
}
#media (max-width:320px) {
form {
width: 90%;
}
}
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Titre de la page</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
</head>
<body>
<div class="parent">
<div class="wrapper">
<div class="logo">
<img src="https://zupimages.net/up/23/02/0itb.png" alt="image">
</div>
<div class="signin">
<form (ngSubmit)="logon()" class="sign-in-form">
<!-- Signin -->
<h3 class="title">Signin</h3>
</form>
<div class="signin_item_block sign-in-block-form"></div>
</div>
<div class="panels-wrapper">
<div class="panel left-panel"></div>
<div class="panel right-panel">
<div class="content">
...
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Working: https://stackblitz.com/edit/js-ndbzyq?file=style.css
Firstly, The code was a bit untidy and a lot of unnecessary CSS was used example position: absolute.
The major changes involve are:
moving the logo div inside the signin div.
Changing the flex-direction to column to signing div.
using display flex for logo class which allows me to justify-content centre.
<div class="signin">
<div class="logo">
<img src="https://zupimages.net/up/23/02/0itb.png" alt="image" />
</div>
<div>
<form (ngSubmit)="logon()" class="sign-in-form">
<h3 class="title">Signin</h3>
</form>
</div>
<div class="signin_item_block sign-in-block-form"></div>
</div>
.logo {
justify-content: center;
display: flex;
width: 50%;
min-width: 238px;
}
.signin {
width: 100%;
height: 100%;
display: flex;
justify-content: space-around;
z-index: 5;
flex-direction: column;
}
To be fair, I suggest to re-write the whole structure of the HTML. Use Flex or Grid to achieve similarly and avoid position absolute in this case.
I have a pop-up modal which works overall, however the one annoyance is it has a hardcoded max-height which I'd like to eliminate.
Option #1:
Initially I explored using height: auto on the modal, which does keep the modal height to the natural height of the contents. However this effects the collapsing of the modal when you scale the browser viewport to a short height. The modal overflows out of the viewport, instead of only the green image area overflowing.
Option #2: I'm aware of the possibility of max-content (for height... or even max-height ?) but I haven't been able to get it to work anywhere, and anyhow it has spotty browser support.
Option #3 (current): Setting the modal to height: 100% and max-height: 500px is good enough, however obviously the content needs to be shorter than that.
Overall, requirements are:
A - In small screens, the modal should collapse with the green image area overflowing, thereby maintaining modal title and buttons in view.
B - In large screens, the modal height should only be as big as the contents.
C - Whatever happens, the modal should never visibly go past the global padding (2em).
See #modal in CSS below:
Demo and code here (Codepen)
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
#app {
background-color: gray;
width: 75%;
height: 75%;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
padding: 2em;
}
#container {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
#modal {
/* OPTION #1 */
/* FAILS in small screen: overflow of green image not invoked */
/* height: auto; */
/* OPTION #2 */
/* Not working? */
/* height: max-content; */
/* OPTION #3 */
/* WORKS but specifying a max-height is not ideal */
height: 100%;
max-height: 500px;
width: auto;
position: relative;
background-color: pink;
overflow: hidden;
}
#modal_inner {
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
padding: 2em;
box-sizing: border-box;
}
#image {
overflow-y: auto;
overflow-x: hidden;
flex: 1;
}
#image .inner {
background-color: lime;
padding: 1em;
width: 400px;
height: 200px;
}
#controls {
background-color: yellow;
display: flex;
justify-content: center;
max-width: 20em;
width: 100%;
padding: 1em;
margin-top: 1em;
}
#cta {
background-color: white;
display: flex;
justify-content: center;
max-width: 10em;
padding: 1em;
margin-top: 1em;
}
<div id="app">
<div id="container">
<div id="modal">
<div id="modal_inner">
<div id="title">TITLE</div>
<div id="image">
<div class="inner">image</div>
</div>
<div id="controls">controls</div>
<div id="cta">submit</div>
</div>
</div>
</div>
</div>
You are almost good, use max-height:100% and also add display:flex that will give the height:100% effect you are trying to achieve on the modal_inner
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
#app {
background-color: gray;
width: 75%;
height: 75%;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
padding: 2em;
}
#container {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
#modal {
max-height: 100%;
display:flex;
position: relative;
background-color: pink;
overflow: hidden;
}
#modal_inner {
display: flex;
flex-direction: column;
align-items: center;
/*height: 100%; remove this*/
padding: 2em;
box-sizing: border-box;
}
#image {
overflow-y: auto;
overflow-x: hidden;
flex: 1;
}
#image .inner {
background-color: lime;
padding: 1em;
width: 400px;
height: 200px;
}
#controls {
background-color: yellow;
display: flex;
justify-content: center;
max-width: 20em;
width: 100%;
padding: 1em;
margin-top: 1em;
}
#cta {
background-color: white;
display: flex;
justify-content: center;
max-width: 10em;
padding: 1em;
margin-top: 1em;
}
<div id="app">
<div id="container">
<div id="modal">
<div id="modal_inner">
<div id="title">TITLE</div>
<div id="image">
<div class="inner">image</div>
</div>
<div id="controls">controls</div>
<div id="cta">submit</div>
</div>
</div>
</div>
</div>
I'm awfully new to the whole game and approach problems pretty much everyday. Most of the time I solve them with google, learning a lot, but this time I can't find anything.
So, I've got this lovely header that moves to the right and makes some space for another element. I'd like this element (the bonobo head) to appear when I hover over the header.
So, I set the display of the image to none, and block on header:hover, but the image seems glued to the header.
I would like it to appear next to it, in any given location. What do ?
.header {
position: relative;
display: block;
left: 0%;
padding: 15px;
background-color: #54e954;
text-align: center;
width: 100%;
height: auto;
transition: 2s;
border-radius: 8px;
}
.header:hover {
left: 15%;
background-color: #d0f307;
}
.photo {
position: relative;
display: none;
}
.header:hover .photo {
display: block;
}
<div class="header">
<h1 class="h1header">Lorem Ipsum</h1>
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/4/4b/Bonobo-Head.jpg" class="photo">
</div>
</div>
Is that what you want it to look like ? If you want this, I did it using the display flex structure.
.header {
position: relative;
display: flex; /* added */
justify-content: center;
align-items: center;
left: 0%;
padding: 15px;
background-color: #54e954;
text-align: center;
width: 100%;
height: auto;
transition: 2s;
border-radius: 8px;
}
.header:hover {
left: 15%;
background-color: #d0f307;
}
.photo {
position: relative;
display: none;
}
.header:hover .photo {
display: block;
}
<div class="header">
<h1 class="h1header">Lorem Ipsum</h1>
<div class="img-container">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/4b/Bonobo-Head.jpg" class="photo">
</div>
</div>
Updated : With Javascript, you can better control hover and hoverout operations. Here's an example I've prepared for you. By the way, I had to get the img tag out of the header tag. You can see the additions I've made.
let header = document.querySelector(".header");
let imageContainer = document.querySelector(".img-container");
header.onmouseover = function() {
imageContainer.classList.add("showImage");
}
header.onmouseout = function() {
imageContainer.classList.remove("showImage");
}
.header {
position: relative;
display: flex;
/* added */
justify-content: center;
align-items: center;
left: 0%;
padding: 15px;
background-color: #54e954;
text-align: center;
width: 100%;
height: 80px;
transition: 1s;
border-radius: 8px;
}
.header:hover {
transform: translateX(15%);
/* added*/
background-color: #d0f307;
}
.img-container {
position: relative;
display: none;
}
.img-container.showImage {
position: relative;
display: block;
}
.container {
display: flex;
justify-content: space-between;
}
<div class="container">
<div class="img-container">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/4b/Bonobo-Head.jpg" class="photo">
</div>
<div class="header">
<h1 class="h1header">Lorem Ipsum</h1>
</div>
</div>
This question already has answers here:
Flexbox column-reverse in Firefox, Edge and IE
(4 answers)
Closed 4 years ago.
This code is designed to show the numbers in column reverse order from 1 to 4 so I suddenly realize I did not like how display flex was setting the .numbers height and it was ignoring my height in 200px in the numbers class name so I added
flex-shrink: 0;
and it prevented display flex from setting it's own height and it suddenly showed the .numbers original height so I was happy :)
so this is how it looks in Chrome
but sadly flex-shrink: 0 gave strange results in Edge, IE and Fire fox I notice in those browsers it removed the scrollbar and it ignored the overflow-y: auto; mentioned in the #numbers-container.
How can I get it to work like the chrome browser in those other browsers that it did not work in ? :(
Code
#container{
background-color: #d6b68d;
height: 500px;
width: 500px;
border-radius: 8px;
position: relative;
}
#numbers-container{
background-color: orange;
height: 90%;
width: 90%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
overflow-y: auto;
overflow-x: hidden;
display: flex;
flex-direction: column-reverse;
}
.numbers{
background-color: forestgreen;
display: block;
height: 200px;
width: 100%;
position: relative;
border: 2px solid white;
flex-shrink: 0;
}
.numbers h1{
text-align: center;
color: white;
}
<div id='container'>
<div id='numbers-container'>
<div class='numbers'>
<h1>1</h1>
</div><!--</numbers>-->
<div class='numbers'>
<h1>2</h1>
</div><!--</numbers>-->
<div class='numbers'>
<h1>3</h1>
</div><!--</numbers>-->
<div class='numbers'>
<h1>4</h1>
</div><!--</numbers>-->
</div><!--</numbers-container>-->
</div><!--</container>-->
You could move the scrolling onto it's own container:
/* CSS used here will be applied after bootstrap.css */
#container {
background-color: #d6b68d;
height: 500px;
width: 500px;
border-radius: 8px;
position: relative;
}
#scroll {
height: 90%;
width: 90%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
overflow-y: auto;
}
#numbers-container {
background-color: orange;
overflow-x: hidden;
display: flex;
flex-direction: column-reverse;
}
.numbers {
background-color: forestgreen;
display: block;
height: 200px;
width: 100%;
position: relative;
border: 2px solid white;
flex-shrink: 0;
}
.numbers h1 {
text-align: center;
color: white;
}
<div id="container">
<div id="scroll">
<div id="numbers-container">
<div class="numbers">
<h1>1</h1>
</div>
<!--</numbers>-->
<div class="numbers">
<h1>2</h1>
</div>
<!--</numbers>-->
<div class="numbers">
<h1>3</h1>
</div>
<!--</numbers>-->
<div class="numbers">
<h1>4</h1>
</div>
<!--</numbers>-->
</div>
<!--</numbers-container>-->
</div>
<!--</scroll-container>-->
</div>
<!--</container>-->
However, if you want to start your scroll from the bottom, you would probably need to use js
I have a design that I need to replicate with CSS.
The background should be centered in the div
I tried using gradients, but they are not looking good on different browsers.
You can do it this way with Flexbox :
Codepen
section {
border: #f00 solid 2px;
display: flex;
align-items: flex-end;
height: 400px;
}
section .aligner {
border: #00f dashed 1px;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 80%;
position: relative;
}
section .aligner .background {
background: #ff0;
width: 100%;
height: 60%;
}
section .aligner .square {
position: absolute;
width: 300px;
height: 100%;
background: #008000;
}
<section>
<div class="aligner">
<div class="background"></div>
<div class="square"></div>
</div>
</section>