CSS Grid Layout Strange Behavior on Window Resize - css

Chrome Version 60.0.3112.78 (Official Build) (64-bit) in Windows 7
I'm exploring CSS Grid layout and have come across an odd issue in Chrome (works fine in Firefox). I've created a simple registration form that I want to center horizontally and vertically on the page.
I use three nested grids to structure my layout.
html {
height: 100%;
}
body {
font-family: 'Rubik', sans-serif;
margin: 0;
padding: 0;
background: #aaffff;
height: 100%;
}
#root {
height: 100%;
}
button,
input,
label {
font-family: 'Rubik', sans-serif;
font-weight: 600;
}
label {
display: inline-block;
text-align: left;
}
.formGroup {
display: inline-block;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
a:link {
text-decoration: none;
color: inherit;
}
a:hover {
text-decoration: underline;
}
*:focus {
outline-width: 3px;
outline-color: rgba(66, 66, 66, 0.7);
outline-style: dashed;
outline-offset: 3px;
}
.Input {
color: #333;
border: none;
height: 2em;
padding: 5px 10px;
display: block;
/* width: 100%; */
}
.Input:focus {
outline-width: 3px;
outline-color: rgba(66, 66, 66, 0.7);
outline-style: dashed;
outline-offset: 3px;
}
.Button {
display: inline-block;
font-weight: 800;
text-align: center;
white-space: nowrap;
vertical-align: middle;
padding: 20px 40px;
border-radius: 4px;
border: none;
background: none;
position: relative;
text-transform: uppercase;
margin: 15px 30px;
}
.Button.primary {
background: #0000ff;
box-shadow: 0 9px #000088;
color: #fff;
}
.Button.primary:hover {
top: 5px;
box-shadow: 0 4px #000088;
}
.Button.primary:active {
top: 9px;
box-shadow: none;
}
.Button.primary:focus {
outline-width: 3px;
outline-color: rgba(0, 0, 255, 0.7);
outline-style: dashed;
outline-offset: 3px;
}
.RegistrationForm-container {
display: grid;
grid-template-columns: 3% auto 3%;
grid-template-rows: 100px 25% auto 25%;
}
.RegistrationForm-container .copy {
grid-column-start: 2;
grid-row-start: 2;
}
.RegistrationForm-container form {
grid-column-start: 2;
grid-column-end: 3;
grid-row-start: 3;
display: grid;
grid-template-columns: 1% auto 1%;
grid-template-rows: 25px auto 25px;
}
.RegistrationForm-container form .inner {
grid-column-start: 2;
grid-column-end: 3;
grid-row-start: 2;
grid-row-end: 3;
display: grid;
grid-template-columns: 1% auto 1%;
grid-template-rows: 50px 50px;
}
.RegistrationForm-container form .inner .emailFormGroup {
grid-column-start: 2;
grid-row-start: 1;
margin: 0 auto;
}
.RegistrationForm-container form .inner .buttonFormGroup {
grid-column-start: 2;
grid-row-start: 2;
}
.App {
text-align: center;
height: 100%;
}
<div id="root">
<div class="App">
<div class="RegistrationForm-container">
<div class="copy">
<h1>Register</h1>
<p>
By registering, you agree to our
terms of use and privacy policy.
</p>
</div>
<form>
<div class="inner">
<div class="formGroup emailFormGroup">
<input
class="Input"
type="email"
placeholder="Email"
autocorrect="false"
/>
</div>
<div class="formGroup buttonFormGroup">
<button type="submit" class="Button primary">
Submit
</button>
</div>
</div>
</form>
</div>
</div>
</div>
While, my grid layout does succeed centering, it misbehaves when the window is resized. When the window is resized larger than the original load size, and then narrowed, a scrollbar appears and the input and button get stuck off to the right.
Only after clicking somewhere in the page or tabbing between the button, input, and terms of use link will it correct itself and snap back into vertical/horizontal centeredness.
Here are demonstrations of the behavior:
https://codepen.io/jdoyle/pen/qXadXJ
https://plnkr.co/edit/rzAAAsfgPVUfxxmXlqYa?p=preview

Looks like margin:auto in a grid does start to act pretty weird.
A way to get the effect you want but avoiding the bug would be to set
text-align: center;
on the emailFormGroup and then remove the display: block on email input.
https://codepen.io/anon/pen/YxGyeG

Related

my pictures are never the same (shrinking and stretching) in CSS

I'm coding 3 boxes. There is pic and title at first column, then there is paragraph and at the bottom there is a link. So the boxes are not editable, just the content is. They should look the same no matter how long the title is. But the length of title changes size of pictures.
When the title needed more than one line, the pic shrank. So I added to my code a min-width. Now the ones previosly problematic are OK, but the third are wider than before, than the two other. Now the css code for pic looks like this. It is an icon with border (as you can see):
background-size: 40px 40px;
border: 2px solid $primary-green;
border-radius: 10px;
height: 56px;
margin-bottom: 10px;
min-width: 56px;
What should I add/change to make all 3 pics looks the same?
Structure:
<div class="box box--product">
<div class="box__content">
<div class="box__title d-flex">
<div class="box__icon" style="background-image: url(\''.($atts['icon'] ? wp_get_attachment_image_src($atts['icon'], 'full')[0] : '').'\');"></div>
<div class="box__icon box__icon--hover" style="background-image: url(\''.($atts['icon_hover'] ? wp_get_attachment_image_src($atts['icon_hover'], 'full')[0] : '').'\');"></div>
<h3 class="box__hdl">'.$atts['nadpis'].'</h3>
</div>
<div class="box__excerpt match-height">
<p>'.$content.'</p>
</div>
<div class="box__more">
<hr>
Viac informácií
</div>
</div>
</div>
Sass:
.box {
$this: &;
background: $gray-lighter;
border-bottom: 7px solid $primary-green;
color: $black;
cursor: pointer;
//margin-bottom: $grid-gutter-width;
&--not-hover {
cursor: default;
}
&__title {
align-items: center;
&--subprod {
margin-bottom: 16px;
//min-height: 75px;
}
}
&__more {
text-align: center;
}
&__icon {
background: {
position: center;
repeat: no-repeat;
size: auto 44px;
}
border: 1px solid $gray-dark;
border-radius: 5px;
height: 80px;
margin-bottom: 16px;
margin-right: 10px;
width: 80px;
&--big {
background-size: 65px auto;
border-width: 2px;
height: 112px;
margin-bottom: 40px;
margin-top: 20px;
width: 112px;
}
&--hover {
border-color: $white;
display: none;
}
}
&__excerpt {
font-size: 14px;
letter-spacing: .44px;
line-height: 21px;
margin-top: 10px;
}
&--product {
border-bottom-width: 7px;
#{$this}__hdl {
color: $primary-green;
font-size: 16px;
line-height: 20px;
margin-left: 10px;
text-transform: uppercase;
}
#{$this}__content {
padding: 15px 22px 5px;
}
#{$this}__icon {
background-size: 40px 40px;
border: 2px solid $primary-green;
border-radius: 10px;
height: 56px;
margin-bottom: 10px;
min-width: 56px;
&--hover {
border-color: $white;
}
}
#{$this}__excerpt {
// border-bottom: 1px solid $primary-green;
color: $gray-dark;
margin-bottom: 15px;
}
#{$this}__more {
.link-warning,
.link-more {
letter-spacing: .4px;
margin-bottom: 10px;
}
}
&:hover,
&:focus {
#{$this}__hdl {
color: $white;
}
#{$this}__excerpt {
border-bottom-color: $white;
}
#{$this}__more {
.link-warning {
&::before {
background-image: url('../images/icon-warning--white.svg');
}
}
}
}
}
Something like this ?
.card {
width: 200px;
height: 300px;
display: inline-block;
margin: 12px;
border: 1px solid black;
overflow: hidden;
display: flex;
flex-flow: column;
}
.card .title {
flex: 0 0 32px;
width: 100%;
line-height: 32px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.card .link {
color: blue;
text-decoration: underline;
flex: 0 0 32px;
width: 100%;
line-height: 32px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.card .image {
flex: 1 1 auto;
overflow: hidden;
}
.card .image img {
height: 100%;
width: 100%;
object-fit: cover;
}
<div class="card">
<div class="title">Some title</div>
<div class="image">
<img src="https://picsum.photos/200/300">
</div>
<div class="link">Some link</div>
</div>
<div class="card">
<div class="title">Some title that is way too long to fit in 200px</div>
<div class="image">
<img src="https://picsum.photos/1024/768">
</div>
<div class="link">Some link that is also way too long for this little box</div>
</div>
Well, it is not probably best practise. But I just add
max-width: 57px; (+1px)
and it works just fine.

React fixed navbar with flexbox

so I'm trying to create my blog using the react framework, but I'm facing an issue here.
I really have been trying to tweaks settings on the css, html or even try to switch to grid instead of flexbox but I can't figure out how to make the "fixed" navbar detected by the flexbox.
Currently, the navbar works fine I guess, but the content that is supposed to be on the right, is not taking the place it should, it's taking the entire screen instead of the rigth section next to the navbar.
Some help would be highly appreciated !
body {
overflow: hidden;
height: 100vh;
top: 0;
left: 0;
margin: 0;
}
/*left box -Navbar*/
.nav-tab-text{
font-size: 1.6em;
display: block;
padding: 00px 0px 50px 0px;
text-align: center;
list-style-type: none;
display: flex;
}
.nav-tab a {
display: block;
text-align: center;
padding: 15px 18px;
text-decoration: none;
font-size: 18px;
color: aliceblue;
}
.nav-tab {
background-color: blue;
height: 100vh;
width: 18%;
border: 3px solid red;
position: fixed;
}
/*Right box - Home content*/
.home-content-container {
width: 100%;
height: 100vh;
border: 5px solid green;
}
.home-content-title {
text-align: center;
font-size: 1.7em;
text-decoration: underline;
text-decoration-thickness: 3px;
}
.home-content-featured{
border: 3px solid purple;
width: 50%;
height: 50%;
align-self: center;
margin-top: 3%;
}
.test{
display: flex;
}
function Navbar() {
return (
<div className="flex-container">
{/*left box - Navbar*/}
<nav className="nav-tab">
Home
Articles
Archives
About
</nav>
{/*Right box - Home content*/}
<div className="home-content-container">
<div className="home-content-title">
<h3>Name</h3>
</div>
<div className="home-content-featured">
<p>1</p>
</div>
</div>
<div className="test">
<p>2</p>
</div>
</div>
);
}
export default Navbar;
import Navbar from "./components/Navbar";
function App() {
return (
<div>
<Navbar />
</div>
);
}
export default App;
body {
overflow: hidden;
top: 0;
left: 0;
margin: 0;
}
/*left box -Navbar*/
.flex-container{
display: flex;
flex-flow: row;
}
.nav-tab a {
display: block;
text-align: center;
padding: 15px 18px;
text-decoration: none;
font-size: 18px;
color: aliceblue;
}
.nav-tab {
background-color: blue;
height: 100vh;
width: 18%;
border: 3px solid red;
}
/*Right box - Home content*/
.home-content-container {
width: 100%;
height: 100vh;
border: 5px solid green;
display: flex;
flex-direction: column-reverse;
}
.home-content-title {
text-align: center;
font-size: 1.7em;
text-decoration: underline;
text-decoration-thickness: 3px;
}
.home-content-featured{
border: 3px solid purple;
width: 50%;
height: 50%;
margin-top: 3%;
align-self: center;
}

How to animate scaling of div with gridlayout smoothly

I have a which contains a gridlayout with some cells. When the div is shown or hidden it should scale gradually over time. Currently when showing, the div is initially sized to fit the contents and then scales. When hidden it is immediately hidden unless padding is set. Then it is immediately resized to the size of the padding.
Example is shown below. How to adapt the styling in such that the div resizes smoothly and text stays in place (clips and does not wrap)
function toggle() {
if (document.getElementsByClassName("ovdInfobox")[0].classList.contains("ovdInfobox--visible")) {
document.getElementsByClassName("ovdInfobox")[0].classList.remove("ovdInfobox--visible")
console.log('remove');
} else {
document.getElementsByClassName("ovdInfobox")[0].classList.add("ovdInfobox--visible")
console.log('add');
}
}
.ovdInfobox {
display: grid;
grid: 40px auto / auto auto;
z-index: 1;
position: absolute;
top: 50px;
width: 0;
height: 0;
min-width: 0;
min-height: 0;
overflow: hidden;
padding: 0;
border: 0;
background: rgba(255, 255, 255, 0.98);
border-radius: 4px;
font-family: inherit;
font-size: inherit;
line-height: inherit;
transition: all 4.2s ease-in-out;
background: green;
}
.ovdInfobox--visible {
width: unset;
height: unset;
min-width: 300px;
border: 1px solid #d1d1d1;
/* padding: 15px 15px 15px 15px;*/
}
.ovdInfobox__header {
grid-column-start: span 2;
color: #c20063;
font-size: 18px;
font-weight: normal;
}
.ovdInfobox__label {
font-weight: bold;
}
.ovdInfobox__data {}
<div>
<button onclick="toggle()">
Click Me!
</button>
<div class="ovdInfobox ovdInfobox--visible" onCLick="toggle()">
<div class="ovdInfobox__header">Details</div>
<div class="ovdInfobox__label">
label
</div>
<div class="ovdInfobox__data">
data
</div>
<div class="ovdInfobox__label">
label
</div>
<div class="ovdInfobox__data">
data
</div>
</div>
</div>
New day, fresh start, fresh mind.
Changed class .ovdInfobox and .ovdInfobox--visible by replacing width, height, min-width and min-height by max-width and max-height. Resizing now works as expected.
function toggle() {
if (document.getElementsByClassName("ovdInfobox")[0].classList.contains("ovdInfobox--visible")) {
document.getElementsByClassName("ovdInfobox")[0].classList.remove("ovdInfobox--visible")
console.log('remove');
} else {
document.getElementsByClassName("ovdInfobox")[0].classList.add("ovdInfobox--visible")
console.log('add');
}
}
.ovdInfobox {
display: grid;
grid: 40px auto / auto auto;
column-gap:10px ;
row-gap: 5px;
z-index: 1;
position: absolute;
top: 50px;
max-width: 0;
max-height: 0;
overflow: hidden;
padding: 0;
border: 0;
background: rgba(255, 255, 255, 0.98);
border-radius: 4px;
font-family: inherit;
font-size: inherit;
line-height: inherit;
transition: all 4.2s ease-in-out;
background: green;
}
.ovdInfobox--visible {
max-width: 300px;
max-height: 200px;
border: 1px solid #d1d1d1;
padding: 15px 15px 15px 15px;
}
.ovdInfobox__header {
grid-column-start: span 2;
color: #c20063;
font-size: 18px;
font-weight: normal;
}
.ovdInfobox__label {
font-weight: bold;
}
.ovdInfobox__data {}
<div>
<button onclick="toggle()">
Click Me!
</button>
<div class="ovdInfobox ovdInfobox--visible" onCLick="toggle()">
<div class="ovdInfobox__header">Details</div>
<div class="ovdInfobox__label">
label
</div>
<div class="ovdInfobox__data">
data
</div>
<div class="ovdInfobox__label">
label
</div>
<div class="ovdInfobox__data">
data
</div>
</div>
</div>

CSS Flexbox - Truncated Text in CSS Grid (Firefox only) [duplicate]

This question already has answers here:
Prevent content from expanding grid items
(3 answers)
Closed 5 years ago.
I can easily render a flexbox with some text and a button, where the text will shrink and truncate with an ellipsis if its container shrinks:
.titleBarCtr {
align-items: center;
display: flex;
}
.titleBar {
color: white;
background-color: green;
flex: 1;
height: 44px;
line-height: 44px;
margin: 0;
padding-left: 5px;
text-align: left;
}
.titleBarCtr .icon {
background-color: green;
border-left: 1px solid white;
color: white;
cursor: pointer;
font-size: 1.17em; /*Matches h3 elems*/
line-height: 44px;
height: 44px;
padding: 0 15px;
text-align: center;
text-decoration: none;
}
.truncatedText {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<link href="https://use.fontawesome.com/b911bcf9e2.css" rel="stylesheet"/>
<div class="titleBarCtr">
<h3 class="titleBar truncatedText">
Testing a long string that should be truncated
</h3>
<a class="icon" aria-current="false" role="button" href="#"><i class="fa fa-dashboard" aria-hidden="true" title="Load Estimation"></i></a>
</div>
However, if I attempt to render this same flexbox inside of a grid, the text will no longer truncate in Firefox (56.0.2 using Ubuntu 16.04), though this seems to work ok in Chrome still:
.root {
display: grid;
grid-template-columns: [left] 50px [controlBar] 200px [main] 3fr [toolbar] 100px [right];
grid-template-rows: [top] 52px [subHeader] 44px [main] 2fr [analysisPanel] 1fr [bottom];
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
position: absolute;
}
.analysisPanel {
box-shadow: 0 -2px 1px -1px rgba(0,0,0,0.2);
display: flex;
flex-flow: column;
grid-column-start: main;
grid-column-end: right;
grid-row-start: analysisPanel;
grid-row-end: bottom;
}
.titleBarCtr {
align-items: center;
display: flex;
}
.titleBar {
color: white;
background-color: green;
flex: 1;
height: 44px;
line-height: 44px;
margin: 0;
padding-left: 5px;
text-align: left;
}
.titleBarCtr .icon {
background-color: green;
border-left: 1px solid white;
color: white;
cursor: pointer;
font-size: 1.17em; /*Matches h3 elems*/
line-height: 44px;
height: 44px;
padding: 0 15px;
text-align: center;
text-decoration: none;
}
.truncatedText {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<link href="https://use.fontawesome.com/b911bcf9e2.css" rel="stylesheet"/>
<div class="root">
<div class="analysisPanel">
<div class="titleBarCtr">
<h3 class="titleBar truncatedText">
Testing a long string that should be truncated
</h3>
<a class="icon" aria-current="false" role="button" href="#"><i class="fa fa-dashboard" aria-hidden="true" title="Load Estimation"></i></a>
</div>
</div>
</div>
I've tried setting min-width: 0 on the titleBar element and playing with flex-basis with no luck.
Any suggestions?
Firefox seems to need a max-width set.
.analysisPanel {
max-width:100%;/* update */
}
.root {
display: grid;
grid-template-columns: [left] 50px [controlBar] 200px [main] 3fr [toolbar] 100px [right];
grid-template-rows: [top] 52px [subHeader] 44px [main] 2fr [analysisPanel] 1fr [bottom];
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
position: absolute;
}
.analysisPanel {
max-width:100%;/* update */
box-shadow: 0 -2px 1px -1px rgba(0, 0, 0, 0.2);
display: flex;
flex-flow: column;
grid-column-start: main;
grid-column-end: right;
grid-row-start: analysisPanel;
grid-row-end: bottom;
}
.titleBarCtr {
align-items: center;
display: flex;
}
.titleBar {
color: white;
background-color: green;
flex: 1;
height: 44px;
line-height: 44px;
margin: 0;
padding-left: 5px;
text-align: left;
}
.titleBarCtr .icon {
background-color: green;
border-left: 1px solid white;
color: white;
cursor: pointer;
font-size: 1.17em;
/*Matches h3 elems*/
line-height: 44px;
height: 44px;
padding: 0 15px;
text-align: center;
text-decoration: none;
}
.truncatedText {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<div class="root">
<div class="analysisPanel">
<div class="titleBarCtr">
<h3 class="titleBar truncatedText">
Testing a long string that should be truncated
</h3>
<a class="icon" aria-current="false" role="button" href="#"><i class="fa fa-dashboard" aria-hidden="true" title="Load Estimation"></i></a>
</div>
</div>
</div>

button is too low in Safari but ok in Chrome and firefox

I have two input with one button are supposed in one div. I already use inline-block for these three elements. However the button is too low in Safari but ok in Chrome and Firefox. Anyone has any idea how to fix it?
<div class="simple-search">
<div class="keywords search-element">
<label for="simple_search_key">Key</label><br>
<input placeholder="e.g. " type="text" name="simple_search[keywords]" id="simple_search_keywords">
</div>
<div class="location search-element">
<label for="simple_search_Location">Location</label><br>
<input placeholder="e.g. " type="text" name="simple_search[location]" id="simple_search_location">
</div>
<div class="actions search-element primary-button">
<input type="submit" name="commit" value="Search">
</div>
.primary-button {
background-color: lime;
box-sizing: border-box;
border-radius: 4px;
}
.primary-button :hover {
background-color: lime;
cursor: pointer;
}
.primary-button input {
background-color: transparent;
color: white !important;
}
.primary-button.disabled {
background: #ecf7e2;
pointer-events: none;
cursor: default;
}
.simple-search {
margin: 0 auto;
text-align: center;
width: 80%;
background-color: rgba(0, 0, 0, 0.3);
border-radius: 8px;
height: 80px;
padding: 2.2em 2.5em;
}
.search-element {
display: inline-block;
margin: 10px;
line-height: 2;
width: 30%;
margin-top: -5px;
}
.search-element label {
color: white;
float: left;
}
.search-element input {
border: none;
border-radius: 4px;
color: blue;
font-size: 1.5em;
height: 30px;
margin-top: .25em;
padding: .75em;
outline: none;
width: 96%;
}
.search-element.primary-button {
height: 60px;
}
.search-element.primary-button input {
height: 52px;
}
.results {
margin: 13px;
padding: 2.2em 10.5em;
}
.results .search-result {
margin: 10px;
margin-left: 0px;
margin-bottom: 30px;
}
.results .search-result .job-title {
font-size: 3ex;
margin-bottom: 10px;
}
.results .search-result .company-name, .results .search-result .location, .results .search-result .date {
display: inline-block;
margin-right: 10px;
}
.results .search-result .company-name {
font-family: monospace;
font-size: large;
}

Resources