Fix cumulative layout shift - css

Got a problem with CLS score which is being affected by this component on mobile devices.
This is how component loos like on initial load when browser's default font loads in:
This is what happens after my custom font is loading:
Here is my css:
.text__list {
display: inline-block;
list-style: none;
margin: 0;
padding: 0;
}
.text__item {
display: none;
&:nth-child(2) {
.text__icon {
display: none;
}
}
&:nth-last-child(-n+3) {
display: inline-block;
}
#media (min-width: $screen-sm) {
display: inline-block;
}
}
Here is my VUE html:
<ol class="text__list" data-cy="text-list">
<li class="text__read-more" :class="{'text__read-more--hidden': isShowingMore}">
<button class="text__read-more-button" #click="showMore" data-cy="text-read-more" title="Read more">
<Icon class="text__read-more-icon" name="dots-horizontal" />
</button>
</li>
<li v-for="(item, index) of items" :key="index" class="text__item" :class="{'text__item--visible': isShowingMore}">
<Icon class="text__icon" name="chevron-right" />
<AppLink class="text__link" :class="{'text__link--active': isCurrentPage(index)}" :to="item.href" :router-link="item.routerLink === true" :aria-current="isCurrentPage(index)" data-cy="text-link">{{ item.title }}</AppLink>
</li>
</ol>

Related

how to unhide a hidden div with bootstrap

I'm working on a site built on bootstrap and have a column down the right side that contains a search module and some other things. it gets hidden on smaller screens. I'm hoping to restore just the search module (and hide everything else but the footer) when pressing a button that gets displayed in the menu.
It sounded simple, but I can't seem to figure out how to override it being hidden. The visibility is set in the style sheet but I also tried setting the visibility on the div itself with d-none d-lg-block - no go.
With below code, when hitting the button, the main container hides (though sometimes only when pressing it twice) but it doesn't restore the sidebar. Which, based on the different things I've tried appears to be as intended, just not what I'm trying to do with it..
I'm sure it's something simple, but I've been staring at this for far too long and I'm not doing well with googling. Thanks in advance for any help/suggestions.
Update: The comment confirming it was out of the realm of bootstrap helped a lot. Updated code below to use javascript to handle activating the search module and hiding the main content. a simple function only goes one way, so I am also hiding the search button itself on click and displaying a close button that reverses the actions. The next step was to reset everything if the page width changes (as this function is only intended to be for smaller screens/mobile, and if you action any of the buttons and then increase page width things stay hidden that shouldn't) so I added a third function that listens for page width changes and resets the visibility of the impacted divs when the size becomes large enough to properly display. it's working in testing, but I'm open to feedback, tips, etc. to make it better.
My sincere thanks to all who have helped me get here!
```
/* Set gray background color and 100% height */
.sidebar {
padding-bottom: 10px;
background-color: #f1f1f1;
text-align: center;
justify-content: center;
}
/* this adds padding to bottom of main container in order to account for footer image */
.pb-6 {
padding-bottom: 5rem !important;
}
/* hides this div on small size */
#media screen and (max-width: 768px) {
div.sidebar {
display: none;
}
div.footerimage {
display: none;
}
}
#media (min-width: 768px) {
/* hides hamburger on bigger screens */
.navbar-brand{
display: none;
}
.navbar-search{
display: none;
}
.navbar-pressed{
display: none;
}
}
/* Set black background color, white text and some padding */
footer {
background-color: #000;
color: #fff;
padding: 15px;
margin:0;
}
body {
margin: 0px;
}
html {
font-family: "Lucida Sans", sans-serif;
}
/* images scales */
img {
max-width: 100%;
height: auto;
}
h1, h2, h3, h4, h5, h6 {
padding: 0px;
margin: 0px;
}
.header {
background-image: url();
background-size: cover;
background-color: #ffffff;
color: #000000;
padding:0;
margin:0;
text-align: center;
width: auto;
height: 100%;
line-height:0;
}
.navbar-pressed {
display: none;
}
.footerimage {
position: relative;
}
.footerpic {
background-image: url();
background-size: contain;
content: '';
height: 200px;
pointer-events: none;
position: absolute;
left: 50%;
top: 0;
transform: translate(-50%, -50%);
width: 200px;
}
/* change the background color */
.navbar-custom {
background-color: #1e73be;
margin-bottom: 0;
border-radius: 0;
padding: 0;
}
/* change the brand and text color */
.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
color: #ffffff;
}
/* change the link color */
.navbar-custom .navbar-nav .nav-link {
color: #ffffff;
}
/* change the color of navbar title when collapsed */
.navbar-toggler {
color: #ffffff;
}
/* change the color of active or hovered links */
.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:focus .nav-link,
.navbar-custom .nav-item:hover .nav-link {
color: #ffffff;
background-color: #035a9e;
}
/* for dropdowns only */
.navbar-custom .navbar-nav .dropdown-menu {
background-color: #1e73be;
}
/* dropdown item text color */
.navbar-custom .navbar-nav .dropdown-item {
color: #ffffff;
}
/* dropdown item hover or focus */
.navbar-custom .navbar-nav .dropdown-item:hover,
.navbar-custom .navbar-nav .dropdown-item:focus {
color: #ffffff;
background-color: #035a9e;
}
.navbar-brand img {
height: 30px;
float: left;
margin-left: 20px;
padding: 0;
}
```
```
<!DOCTYPE html><html lang='en'><head><title>menu test</title><meta charset='utf-8'><meta name='viewport' content='width=device-width, initial-scale=1'><META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1'>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css'><link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css'><link rel='preconnect' href='https://fonts.gstatic.com'><link href='https://fonts.googleapis.com/css2?family=Atma:wght#600&display=swap' rel='stylesheet'><script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js'></script><script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js'></script>
<script>
function myFunction() {
document.getElementById("maincontainer").style.display = 'none';
document.getElementById("sidebar").style.display = 'block';
document.getElementById("sidecontentdiv").style.display = 'none';
document.getElementById("navbar-search").style.display = 'none';
document.getElementById("navbar-pressed").style.display = 'block';
}
</script>
<script>
function myCloseFunction() {
document.getElementById("maincontainer").style.display = 'block';
document.getElementById("sidebar").style.display = 'none';
document.getElementById("sidecontentdiv").style.display = 'block';
document.getElementById("navbar-search").style.display = 'block';
document.getElementById("navbar-pressed").style.display = 'none';
}
</script>
<script>
function doSomething(matches) {
if (matches) {
// media query matches
} else {
// media query does not match
document.getElementById("maincontainer").style.display = "";
document.getElementById("sidebar").style.display = "";
document.getElementById("sidecontentdiv").style.display = "";
document.getElementById("navbar-search").style.display = "";
document.getElementById("navbar-pressed").style.display = "";
}
}
const query = window.matchMedia("(max-width: 767px)");
query.addEventListener("change", ({ matches }) => doSomething(matches));
doSomething(query.matches);
</script>
</head>
<body>
<div class='header'></div>
<nav class='navbar navbar-expand-md navbar-custom sticky-top'><div class='navbar-brand'><a href='https://www.url.com'><img src='/images/menu.png' alt='Logo'></a></div><div id='navbar-pressed' class='navbar-pressed ml-auto'><button class='navbar-toggler' type='button' onclick="myCloseFunction()"><i class='fa fa-circle-xmark fa-flip-horizontal' style='color:#ffffff'></i></button></div><div id='navbar-search' class='navbar-search ml-auto'><button class='navbar-toggler' type='button' onclick="myFunction()"><i class='fa-solid fa-magnifying-glass fa-flip-horizontal' style='color:#ffffff'></i></button></div><button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarCollapse'><span class='ml-auto' role='button'><i class='fa fa-bars' style='color:#ffffff'></i> Menu</span></button><div class='collapse navbar-collapse justify-content-between' id='navbarCollapse'><div class='navbar-nav'>
<div class='nav-item'><a href='index.php' class='nav-link'>Home</a></div>
<div class='nav-item'><a href='index.php' class='nav-link'>Home</a></div>
<div class='nav-item'><a href='index.php' class='nav-link'>Home</a></div></div>
</div></nav>
<div class='container-fluid text-center'>
<div class='row content'>
<div class='col-md-9 text-left pb-6' id='maincontainer'>
main body of page
</div>
<div id='sidebar' class='col-md-3 sidebar'>
<div id='searchdiv'>
<div class='sidebarheader rounded'><h4>Search:</h4></div>
<div class='searchbox rounded'>search module</div>
</div>
<div id='sidecontentdiv'>
<div class='sidebarheader rounded'><h4></h4></div>
<div class='searchbox rounded'>unimportant module</div>
</div></div>
<footer class='container-fluid text-center'>
<div class='row'>footer text</div>
</footer>
</div></div>
</body></html>
```
If it's simply hide/show div, why not use JavaScript / jQuery? Like,
<button onclick="myFunction()">src</button>
<div id="attid"></div>
<script>
function myFunction() {
document.getElementById("attid").style.display = 'none';
// or to show
// document.getElementById("attid").style.display = 'block';
}
</script>
Couldn't comment because lack of reputation :)
I think this will help you! Joe
const opener = document.getElementById('opener');
const sidebar = document.getElementById('sidebar');
const closer = document.getElementById('closer');
opener.onclick = function(){
sidebar.style.marginRight = 0
}
closer.onclick = function(){
sidebar.style.marginRight = 'calc(var(--length) * -1)'
}
body{
overflow:hidden;
}
#sidebar{
--length:280px;
margin-right:calc(var(--length) * -1);
width:var(--length);
transition:all .2s linear;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<button class="btn btn-primary" id='opener'>opener</button>
<div id = 'sidebar' class="d-flex d-md-none float-end flex-column flex-shrink-0 p-3 bg-light">
<div class="d-flex">
<button class="btn btn-primary" id='closer'>x</button>
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-dark text-decoration-none">
<svg class="bi pe-none me-2" width="40" height="32"><use xlink:href="#bootstrap"></use></svg>
<span class="fs-4">Sidebar</span>
</a>
</div>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<a href="#" class="nav-link active" aria-current="page">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#home"></use></svg>
Home
</a>
</li>
<li>
<a href="#" class="nav-link link-dark">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#speedometer2"></use></svg>
Dashboard
</a>
</li>
<li>
<a href="#" class="nav-link link-dark">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#table"></use></svg>
Orders
</a>
</li>
<li>
<a href="#" class="nav-link link-dark">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#grid"></use></svg>
Products
</a>
</li>
<li>
<a href="#" class="nav-link link-dark">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#people-circle"></use></svg>
Customers
</a>
</li>
</ul>
<hr>
<div class="dropdown">
<a href="#" class="d-flex align-items-center link-dark text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<img src="https://github.com/mdo.png" alt="" width="32" height="32" class="rounded-circle me-2">
<strong>mdo</strong>
</a>
<ul class="dropdown-menu text-small shadow">
<li><a class="dropdown-item" href="#">New project...</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Profile</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Sign out</a></li>
</ul>
</div>
</div>

Not hidden slided items of array during animation in MDB Angular

During animations six of items come out from div as image below.
How to hide slided elements during animations.
Using carousel from mdb for angular
Internet's fail me or I can't find answers for my questions.
HTML:
<mdb-carousel class="carousel-multi-item multi-animation" [animation]="'slide'">
<ng-template #thenBlock >
<mdb-carousel-item *ngFor="let cards of slides; let i = index">
<li class="search-car__display-link" *ngFor="let car of cards ; let i index" >
<a [routerLink]="['/car-detail', car.id]">
<car-card [car]="i"></car-card>
</a>
</li>
</mdb-carousel-item>
</ng-template>
</mdb-carousel>
SCSS:
.search-car {
&__display-results {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-top: 20px;
}
&__display-link {
text-decoration: none;
list-style: none;
& > a {
text-decoration: none;
}
}
}
.carousel-item {
overflow: hidden;
z-index: -100;
&.active, &.carousel-item-right, &.carousel-item-next {
display: flex !important;
flex-wrap: wrap;
z-index: 2;
}
}
FIX!
Edit some HTML structure, deleting ng-templates with ng-container not added in issue. It's work on this code.
<mdb-carousel #displayFilteredCars [isControls]="true" class="carousel-multi-item multi-animation" [animation]="'slide'">
<mdb-slide *ngFor="let cards of slides; let i = index">
<li class="search-car__display-link" *ngFor="let car of cards ; let i index" >
<a [routerLink]="['/car-detail', car.id]">
<car-card [car]="i"></car-card>
</a>
</li>
</mdb-slide>
</mdb-carousel>

css styling in react component

I'd like to show the buttons row direction.
I've given disply:flex but it still shows column.
It should be the button has a first character of the name which is underneath the button
and these buttons should be next to each other.
Not like button on the left and the name on the right.
Would be appreciated if I could get help.
RoomList.js
import React from 'react';
import './RoomList.css';
import PropTypes from 'prop-types';
const RoomList = ({ roomList }) => {
return (
<div>
{roomList.map((room) => {
const firstToChar = room.split('');
const firstChar = firstToChar[0];
return (
<div>
<li className="list">
<div className="room-list">
<button type="submit">{firstChar}</button>
<div>{room}</div>
</div>
</li>
</div>
);
})}
</div>
);
};
RoomList.propTypes = {
roomList: PropTypes.func.isRequired,
};
export default RoomList;
RoomList.css
button {
height: 40px;
min-width: 40px;
display: block;
border-radius: 50%;
margin-bottom: 5px;
}
.room-list {
}
.list {
list-style-type: none;
display: flex;
}
The problem is with the HTML you produce. You produce one list by room. Which is not what you want, you want one list, and one item by room in your list.
button {
height: 40px;
min-width: 40px;
display: block;
border-radius: 50%;
margin-bottom: 5px;
}
.room-list {
}
.list {
list-style-type: none;
display: flex;
}
<div>
<div>
<li class="list">
<div class="room-list">
<button type="submit">K</button>
<div>Kitchen</div>
</div>
</li>
</div>
<div>
<li class="list">
<div class="room-list">
<button type="submit">B</button>
<div>Bathroom</div>
</div>
</li>
</div>
</div>
What you want is:
button {
height: 40px;
min-width: 40px;
display: block;
border-radius: 50%;
margin-bottom: 5px;
}
.room-list {
}
.list {
list-style-type: none;
display: flex;
}
<div>
<div>
<li class="list">
<div class="room-list">
<button type="submit">K</button>
<div>Kitchen</div>
</div>
<div class="room-list">
<button type="submit">B</button>
<div>Bathroom</div>
</div>
</li>
</div>
</div>
So you actually want:
const RoomList = ({ roomList }) => {
return (
<div>
<div>
<li className="list">
{roomList.map((room) => {
const firstToChar = room.split('');
const firstChar = firstToChar[0];
return (
<div className="room-list">
<button type="submit">{firstChar}</button>
<div>{room}</div>
</div>
);
})}
</li>
</div>
</div>
);
};
The flex should be on the room list instead

React page is automatically starting scrolled down for some reason

I'm creating a react app (w/o react-router) with UIKit for a portfolio, and as of yesterday when I finished my projects section, the page is now automatically scrolling down to that id, even when hosted on Netlify. The navbar has anchors to each id, but this definitely isn't causing the problem (since the whole page worked as intended before I implemented the projects section yesterday).
/#projects is not being appended to the web address, and I am not using any window functions.
I tried using the useEffect() hook with window.scrollTo(0,0) inside, but the page still starts at the projects section and then scrolls to the top with looks odd.
This is the hosted version if you want to see exactly what I'm talking about.
Here's the projects component:
const Projects = () => {
const [selected, setSelected] = useState(proj[0]);
return (
<Fragment>
<div className="projects" id="projects">
<div className="about-head-wrapper">
<h2 className="about-head heading">Projects</h2>
</div>
<MediaQuery minDeviceWidth={1001}>
<div className="projects-container">
<div className="projects-container-buttons">
<button
href="#!"
onClick={() => {
setSelected(proj[0]);
}}
className="project-button"
key={proj[0].title}
autoFocus>
<img src={proj[0].logo} alt="" />
</button>
<button
href="#!"
onClick={() => {
setSelected(proj[1]);
}}
className="project-button"
key={proj[1].title}>
<img src={proj[1].logo} alt="" />
</button>
<button
href="#!"
onClick={() => {
setSelected(proj[2]);
}}
className="project-button"
key={proj[2].title}>
<img src={proj[2].logo} alt="" />
</button>
</div>
<div className="projects-container-splitter" />
<div className="projects-container-info">
<ProjectInfo
title={selected.title}
sc={selected.sc}
desc={selected.desc}
link={selected.link}
/>
</div>
</div>
</MediaQuery>
<MediaQuery maxDeviceWidth={1000}>
<div className="project-accordion-container">
<ul uk-accordion="collapsible: true; animation: false; multiple: true;">
{proj.map((p) => {
return (
<ProjectAccordion
title={p.title}
sc={p.sc}
desc={p.desc}
link={p.link}
logo={p.logo}
key={p.title}
/>
);
})}
</ul>
</div>
</MediaQuery>
</div>
</Fragment>
);
};
And here's my scss code for the component container:
.projects {
height: 100rem;
background-color: #3a4750;
padding-top: 8rem;
#media (max-width: 1000px) {
height: 100%;
padding-bottom: 5rem;
}
&-container {
display: flex;
justify-content: space-between;
align-items: center;
margin: 5rem 0;
height: 70rem;
&-buttons {
flex: 0 0 32%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
&-splitter {
flex: 0 0 1px;
height: 60rem;
background-color: white;
transform: rotate(0) scaleY(1);
}
&-info {
flex: 0 0 65%;
}
}
}
Update, I just found an autofocus that accidentally slipped past me. It was in .projects-container-buttons in the first button element that I was using in an old version of the projects component.

How do i go to homepage with a click event in angularjs?

I have 3 tabs which are created using li...when I click cancel in addform tab I must redirected to home page..But the add form tab is highlighted even it is redirected to homepage.I want to redirect to home page and home tab must be redirected.I am unable how to do it on click event..
My code is mentioned below :
//when cancel button is clicked
$scope.cancelbtn=function(){
$window.location.href="#Home"
ngDialog.closeAll();
};
//html
<div id="header">
<div id="header_name" style="padding-top:25px"><center><h1 class="hh"><a>Dynamic Creation of Forms</a></h1></center></div>
<div id="nav-masthead" role="navigation">
<ul style="padding-top: 38px;padding-left:113px">
<li >
<span class="glyphicon glyphicon-home">Home</span>
</li>
<li>
<span class=" glyphicon glyphicon-plus-sign ">Add Form</span>
</li>
<li>
View Form
</li>
</ul>
</div>
</div>
<div style="color:#0d7dc1;padding: 51px;padding-left: 120px;"><ng-view></ng-view></div>
//css
#header {
background-image: url(//www.drupal.org/sites/all/themes/bluecheese/images/sprites-horizontal.png);
background-color: #56b3e6;
height:141px;
background-position: 0 -1088px;
}
.hh{
margin-top:0;
}
#nav-header {
overflow:hidden;
font-size:0.923076em;
min-height:1.5em;
}
#header_name a{
background-position: 0 -467px;
background-repeat: no-repeat;
color:white;
text-decoration:none;
height: 63px;
overflow: hidden;
text-indent: -999em;
width: 181px;
}
#nav-masthead{
width:100%;
float:right;
margin-right: 0;
display: inline;
position: relative;
z-index: 1;
min-height: 0.69231em;
}
ul{
list-style: none;
font: inherit;
font-size: 100%;
}
#nav-masthead ul li{
list-style: none;
float: left;
font-size: 0.923076em;
margin-right: 0.615384em;
}
#nav-masthead ul li a {
background-color: #0d7dc1;
border-radius: 10px 10px 0 0;
color: white;
float: left;
padding: 0.416666em .75em 0.416666em 0.615384em;
text-decoration: none;
}
#nav-masthead ul li:hover a {
background-color: white;
color:black;
}
#nav-masthead li a.col {
color: black;
background-color: white;
}
//script
$(document).ready(function() {
$('#nav-masthead li a').click(function() {
$('#nav-masthead li a').removeClass("col");
$(this).addClass("col");
});
});
Can anyone solve this.When I redirected to home page I need to get home highlighted instead of add form.
reference: How to set bootstrap navbar active class with Angular JS?
essentially if you have a MainCtrl that encapsulates everything you'll be able to keep track of which active state is currently being active.
angular.module('app').controller('MainCtrl', ['$scope', '$location', function($scope, $location) {
$scope.isActive = function('viewLocation') { //pass in the current location
return viewLocation === $location.path(); //class becomes active if the pathing is corret
}
}]);
and then have your html include the ng-class calling that function
<li ng-class="{ active: isActive('/home')}">
<span class="glyphicon glyphicon-home">Home</span>
</li>
<li ng-class="{ active: isActive('/add')}">
<span class=" glyphicon glyphicon-plus-sign ">Add Form</span>
</li>
<li ng-class="{ active: isActive('/view')}">
View Form
</li>
unless I'm miss understanding your question, hope it helps.
I have got the answer ..Just to redirect to home page when click eventi have just used the below code.
$scope.cancelbtn=function(){
$('#home').trigger('click');
ngDialog.closeAll();
};
By using above code i have solved it.i am posting my answer because it may helpful to others.
Thank You.

Resources