Locating 5 row of grid at the center (with picture) - html

I am using Next.js and SCSS and trying to locate 5 & 3 rows of images at the center of the page with responsive grid system.
I just need to slightly adjust images location to the right side but contents do not move at all.
here is the code :
Next.js
// So basically ui.container wraps up li.item which are images.
<ul className="container">
{stores.map(store => (
<li onClick={this.open} key={store.id} className="item">
<img
src={store.thumb}
onClick={() => this.storeDetail(store.id)}
/>
</li>
))}
</ul>
SCSS
section {
background: pink;
}
.store-list-title {
text-align: center;
padding-top: 2rem;
font-size: 3rem;
}
.container {
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(5, 200px);
}

Add justify-content:center for aligining center
.container {
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(5, 50px);
justify-content: center;
}

So the solution I found on youtube is using mixin function in SCSS.
It needs calculation so I am still looking at it to understand how it works.
I would be appreciated if someone explains how it works
item element and mixin
#mixin grid($cols, $mgn) {
float: left;
margin-right: $mgn;
margin-bottom: $mgn;
width: ((100% - (($cols - 1) * $mgn)) / $cols);
&:nth-child(#{$cols}n) {
margin-right: 0;
}
}
.item {
#include grid(5, 2%);
img {
width: 100%;
}
}
li tags
{stores.map(store => (
<li onClick={this.open} key={store.id} className="item">
<img
src={store.thumb}
onClick={() => this.storeDetail(store.id)}
alt={`${store.name} image`}
/>
</li>
))}

Related

How to change a svg image along with text with hover in CSS

I tried to change my svg image and text on hover and it doesn't work how I want it. I want the moment my mouse crosses over any of these 2 (svg or text) to change both.
Maybe I made a mistake in the html structure or maybe in css.
Please if you can help me, thanks in advance.
.logout-image {
mask: url("../../../assets/images/log-out.svg");
background-color: #62799D;
width: 20px;
height: 20px;
margin-right: 20px;
margin-left: 20px;
}
.logout-container {
display: flex;
flex-direction: row;
align-items: center;
padding: 8px 0px 8px 24px;
width: 100%;
height: 60px;
position: static;
left: 0px;
top: 280px;
color: #62799d;
margin-top: 35vh;
}
.logout-container:hover {
background: #0c2e6e;
color: white;
}
.logout-image:hover{
background: white;
}
<ul className="SidebarList">
{sidebarData.map((value, key) => {
return (
<li
className="row"
key={key}
onClick={() => {
window.location.pathname = value.link;
}}
>
{" "}
<div className="icon">{value.icon}</div>{" "}
<div className="title">{value.title}</div>
</li>
);
})}
{" "}
{" "}
//here is the problem
<li className='logout-container'>
<div className="logout-image"></div>
<div className="title" >Logo Out</div>
</li>
//until here
</ul>
This is how I wanted to change with hover:
target result
And this is how it is working right now:
current result
The background changes only if I cross over my svg image:
example here
Add this:
.logout-container:hover > .logout-image{
background: white;
}
It turns the image and words white when logout-container is hovered.

CSS unecessary space in main when in mobile mode

This is what the site is like when in desktop mode:
Now in mobile mode:
You can see that there is now extra space on the bottom. I make sure to erase margins everywhere but the space still remained there.
Pertinent css code:
.grid-container{
display: grid;
grid-template-areas:
"header"
"main"
"footer";
grid-template-columns: 1fr;
grid-template-rows: 5rem 1fr 3rem;
height: 100%;
}
.main {
grid-area: main;
background-image: url("res/background_min.jpg");
overflow: hidden
}
/*Home Screen*/
.home{
display: flex;
}
.menu-list{
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
height: 100%;
}
.menu-list a {
padding: 0rem;
flex: 0 1 50rem;
margin: 1.5rem;
height: 100%;
width: 100%;
display: flex;
text-decoration: none;
color: white;
}
.menu-list li
{
display: flex;
list-style-type: none;
text-decoration: none;
align-items: center;
justify-content: center;
width: 100%;
height: 10%;
}
.menu-list p {
font-size: 2vw;
}
.section a {
color: #ffffff;
font-weight: bold;
font-size: 2vw;
text-decoration: none;
}
.about {
background-image: linear-gradient(to right, cyan, magenta);
}
.contacts {
background-image: linear-gradient(to right, fuchsia, turquoise);
}
.projects{
background-image: linear-gradient(to right, turquoise, fuchsia);
}
.question-box {
background-image: linear-gradient(to right, magenta, aqua);
}
.home-main-image{
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
max-width: 45%;
}
.home-main-image img{
max-width: 99%;
}
.fade-in {
animation: fadeIn ease 2s;
}
.button{
background-image: linear-gradient(to right, cyan, magenta);
border: none;
text-align: center;
color: white;
text-decoration: none;
font-size: 1vw;
padding: .5rem;
}
Menu list is the vertical column of buttons that should occupy most of the screen on the left, and home-main-image is the giant terminal logo plastered on the right.
Note that the issue happens with a real mobile device too.
Edit: For clarification, this is the extra space:
Edit: added react html:
App.js
function App() {
const [lang, setLang] = useLanguage();
const handleLanguageChange = () => {
if (lang.lang === 'eng'){
setLang('fr')
} else {
setLang('en')
}
}
return (
<BrowserRouter>
<div className="grid-container">
<header className="header">
<div className="brand">
<Link to="/" >
Eduardo Breton
</Link>
</div>
<div className="header-side">
{lang.subtitle}
</div>
<div className="header-right">
<button className="button" onClick={() => handleLanguageChange()}>{lang.traduction} </button>
</div>
<div>
</div>
</header>
<main className="main">
<div className="content">
<Route path="/" exact={true} component={HomeScreen} />
<Route path="/about" component={AboutScreen}/>
<Route path="/contact" component={ContactScreen}/>
<Route path="/project" component={ProjectScreen}/>
<Route path="/question" component={QuestionScreen}/>
</div>
</main>
<footer className="footer">
© 2020 Eduardo Breton
</footer>
</div>
</BrowserRouter>
);
}
HomeScreen.js:
const { Link } = require("react-router-dom");
function HomeScreen() {
const [lang, setLang] = useLanguage();
return <div className="home">
<ul className="menu-list">
<Link to="/about">
<li className="fade-in section about" >
{lang.about}
</li>
</Link>
<Link to="/contact">
<li className="fade-in section about" >
{lang.contact}
</li>
</Link>
<Link to="/project">
<li className="fade-in section about" >
{lang.projects}
</li>
</Link>
<Link to="/question">
<li className="fade-in section about" >
{lang.question}
</li>
</Link>
</ul>
<div className="home-main-image fade-in">
<img src={terminalImage} />
</div>
</div>
}
export default HomeScreen;
Checked answer with the discussion has fixed the issue, changing flex-direction to column on a media screen on main has allowed me to center correctly the contents:
the first thing you need to do is add a meta description for mobile view in the head. These in particular
<meta content="width=device-width, initial-scale=1" name="viewport" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
Next you need to make your site responsive by adding media queries so that the home main image and your buttons become responsive. You should increase the size of the menu buttons and set them to
#media screen and (max-width:650px) {
.menu-list li {
flex-direction:column;
}
}
That way your buttons will be bigger, aligned in the center, AND in a column (this will look better on mobile). You should also change the flex direction of the main image. Also, try adding some padding between the buttons in mobile view, this should also help in taking up the space.

How to fix mat-list-item not taking full space of row

Hello guys I rendering an article.component.html inside my article-list-component.html in a list when I do it in plain HTML it renders just fine (see picture 1):
Title - author - Date
Here is my article-list.component.html
<ul>
<li *ngFor="let article of data_array">
<a [href]="article.url" class="undecorateda" target="_blank">
<app-article [data]='article'></app-article>
</a>
</li>
</ul>
but when I try to use angular-material list the component renders all to the left like this (see picture 2):
Title-author-Date
Here is my article-list.component html:
<mat-list>
<mat-list-item *ngFor="let article of data_array">
<a [href]="test">
<app-article [data]='article' (click)="printURL(article.url)"></app-article>
</a>
</mat-list-item>
</mat-list>
when I use the plain HTML in the article-list.component.html it renders as I want it to do, but if I use the material code inside article-list.component.html it doesn't render properly
this is the article.component.html
<div class='article-container'>
<div class='title-container'>
{{data.title}}
<div class='author-container'>
-{{data.author}}-
</div>
</div>
<div class='date-container'>
{{formatDay(data.created_at)}}
</div>
<div class="actions-container" id="deletebtn">
<button mat-icon-button color="warn" (click)="deleteArticle(data._id)">
<mat-icon>delete_forever</mat-icon>
</button>
</div>
</div>
this is the article.component.css file:
.article-container {
display: grid;
grid-auto-flow: column;
grid-template-columns: 10fr 2fr 1fr;
height: 50px;
background-color: #fff;
border-bottom: 1px solid #ccc;
align-items: center;
padding: 0 15px;
}
.article-container>* {
grid-row: 1/2;
}
.article-container #deletebtn {
display: none;
}
.article-container:hover {
background-color: #fafafa;
}
.article-container:hover #deletebtn {
display: block;
}
.title-container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
color: #333;
font-size: 13pt;
}
.author-container {
color: #999;
font-size: 10pt;
margin-top: 3px;
}
.date-container {
color: #333;
font-size: 13pt;
}
.title-container div {
padding: 0 15px;
}
Basically what I want is to use material-angular list inside the article-list.component.html and that it render good like in picture 1
==========================================
If you add a width of 100% to the article component itself it should ensure the component takes the whole width and the list will the whole width as well.
:host {
width: 100%;
}
Take a look at this example here to see the list taking 100% of the width.

Trying to use css-grid but not all of the elements seem to be going in the right spot

I have the grid area template with correct formating, but for some reason, when I add an element and assign it's grid-area, it goes into the next available space in the column. eg: supposed to be middle column bottom row, but instead showed up on the middle column a space away from the privious element. (example shown in code) Also, the spacing is not working eg: 3fr is the same size as a 1fr. (This is in code pen)
fixed this problem in comments
New problem: the numbers are surrounding everything, why?
body {
background-color: rgb(90, 250, 190);
text-align: center;
font-family: 'Alegreya', serif;
min-width: 320px;
}
.container {
min-height: 500px;
width: 98%;
margin: 10px;
display: grid;
background: rgb(255, 255, 255);
grid-template-columns: 30px 3fr 2fr;
grid-template-rows: 0.5fr 1fr 1fr 1fr 3fr 3fr 1fr 3fr 2fr;
grid-template-areas: "description description description" "1 name nameinput"
"2 email emailinput"
"3 age ageinput"
"4 redblueoryellow redblueoryellowinput"
"5 mixedwith mixedwithinput"
"6 lighterordarkerdropdown lighterordarkerdropdowninput"
"7 radiobuttons radiobuttonsinput"
"8 questionsorcomments questionsorcommentsinput"
}
.description {
grid-area: description;
font-size: 30px;
}
.\31 {
grid-area: \31;
}
.\32 {
grid-area: \32;
}
.\33 {
grid-area: \33;
}
.\34 {
grid-area: \34;
}
.\35 {
grid-area: \35;
}
.\36 {
grid-area: \36;
}
.\37 {
grid-area: \37;
}
.\38 {
grid-area: \38;
}
.name {
grid-area: name;
}
.email {
grid-area: email;
}
.questionsorcomments {
grid-area: questionsorcomments;
}
<div class="container">
<p id="description" class="description">
What is your favorite color?
</p>
<p class="1">1.</p>
<p class="2">2.</p>
<p class="3">3.</p>
<p class="4">4.</p>
<p class="5">5.</p>
<p class="6">6.</p>
<p class="7">7.</p>
<p class="8">8.</p>
<p class="name">What is your name?</p>
<p class="email">What is your email?</p>
<p class="questionsorcomments"> Any questions or comments?</p>
</div>
The numbers are supposed to be running down the side. If you want a link to the full codepen then here it is: https://codepen.io/Homburg_Molly/pen/arbzeN

Strive to align item-boxes' borders vertically?

Is it possible to make flex children align vertically?
Example
In this case, the left "softwaredevelopment" box should increase a little so that the above "react" align with the "react" underneath. The same goes with "web", "software" and so on..? Obviously, the slight misalignment of the boxes in the picture beneath is slightly annoying...
Does a property for flexbox exist that does what I described?
The solution should be dynamic
Flexbox is great for horizontal layout control, but was not designed to handle vertical layout. Consider CSS Grid with a touch of JavaScript for layouts like this. Once we decide on a number of columns (7, in this case), we can add a bit of JavaScript that decides on the span of columns based on text length. This is a simple prototype, but could be further developed to deal with edge-case rules.
let listItems = document.querySelectorAll(".grid li");
listItems.forEach(item => {
const len = item.innerText.length;
if (len > 15 && len < 20) {
item.classList.add('span-2');
} else if (len >= 20) {
item.classList.add('span-3');
} // etc.
});
.grid {
display: grid;
grid-template-columns: repeat(7, 1fr);
grid-auto-rows: 1fr;
margin: 0;
padding: 0;
list-style: none;
}
.grid li {
text-align: center;
border: .5px solid;
display: flex;
align-items: center;
justify-content: center;
font-size: 100%;
padding: .35em;
}
.span-2 {
grid-column: span 2;
}
.full-width {
grid-column: 1 / -1;
}
<ul class="grid">
<li class="full-width">Show all</li>
<li>Python</li>
<li>NodeJS</li>
<li>React</li>
<li>Web</li>
<li>Software</li>
<li>React</li>
<li>Webdev</li>
<li>Sofware Development</li>
<li>React</li>
<li>Crazy Developers</li>
<li>Web</li>
<li>React</li>
<li class="full-width">Sofware Development</li>
</ul>
jsFiddle