I made this sidebar and I cannot remove box-shadow when it collapse. I tried box-shadow: none; also box-shadow: none !important; box-shadow: transparent; even tried to change color: box-shadow: yellow; and it does not work. What should I do to remove shadow when it collapsing? It is all about React components:
<div>
<div className="sidebar-container container-flex navbar-expand-sm navbar-light">
<div className="navbar-header bg-white">
<button
className="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon"></span>
</button>
</div>
<div
className="collapse navbar-collapse bg-white .d-none .d-sm-block .d-md-none"
id="navbarSupportedContent"
>
<div className="title1">Title</div>
<div className="title2">Title 2</div>
<ul className="mr-auto mb-2 mb-lg-0">
{<SidebarElement props={props} />}
</ul>
</div>
</div>
</div>
This is Sidebar CSS:
li {
list-style-type: none;
}
.title1 {
font-family: "Roboto";
font-style: normal;
font-weight: 700;
font-size: 26px;
letter-spacing: 0.5px;
padding-top: 24px;
padding-left: 24px;
padding-bottom: 28px;
color: #336cfb;
}
.title2 {
font-family: "Roboto";
font-style: normal;
font-weight: 400;
font-size: 14px;
letter-spacing: 0.5px;
padding-top: 24px;
padding-left: 24px;
padding-bottom: 20px;
color: #52575c;
}
.active-link {
color: #336cfb;
}
.sidebar-container {
position: fixed;
width: 242px;
left: 0;
overflow-x: hidden;
overflow-y: auto;
height: 100%;
box-shadow: 5px 0 5px -5px #333; /* Normal box shadow */
}
.navbar-collapse {
background: transparent;
height: inherit;
/* box-shadow: none; */ /* override box shadow */
box-shadow: yellow;
}
.collapse {
box-shadow: none; /* override box shadow */
}
#navbarSupportedContent {
flex-direction: column;
align-items: flex-start;
}
This is SidebarElement css:
.nav-link {
display: flex;
flex-direction: row;
align-items: center;
width: 100%;
padding-top: 8px;
padding-bottom: 8px;
font-family: "Roboto";
font-style: normal;
font-weight: 700;
font-size: 14px;
letter-spacing: 0.5px;
color: #52575c;
}
.customIcon {
width: 18px;
padding-right: 10px;
color: #dbdde0;
}
li {
list-style-type: none;
padding: 14px 10px;
}
.active-link {
color: #336cfb;
}
1: You're not resetting the box shadow on the same element
2: CSS is interpreted top down - box-shadow of none is being immediately overriden.
.sidebar-container {
position: fixed;
width: 242px;
left: 0;
overflow-x: hidden;
overflow-y: auto;
height: 100%;
box-shadow: 5px 0 5px -5px #333; /* Normal box shadow */
}
.navbar-collapse {
background: transparent;
height: inherit;
box-shadow: none; /* override box shadow */
}
.collapse {
box-shadow: none; /* override box shadow */
}
#navbarSupportedContent {
flex-direction: column;
align-items: flex-start;
}
Related
There is initial space before the list. And the list is scrollable.
The space from the beginning needs to be removed while scrolling. Is it possible to do so using css?
I initially added padding before the list. But the padding is always maintaining it's space.
JSX:
<div class="pt-filter-container">
<div
v-for="(item, index) in items"
:key="index"
class="item"
>
{{ item.label }}
</div>
</div>
CSS:
.filter-container {
display: flex;
width: 30em;
overflow-x: auto;
white-space: nowrap;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
.item {
font-size: 14px;
font-weight: 500;
letter-spacing: 0;
line-height: 16px;
color: #5A6872;
margin-right: 8px;
padding: 8px 12px;
border: 1px solid #chip-grey;
border-radius: 4px;
background-color: #FAFAFA;
position: relative;
}
.active {
background-color: #red;
color: #white;
}
}
It's just i need to add margin before the 1st element instead of container that is containing it.
So the actual code will be -
.pt-filter-container {
display: flex;
width: 30em;
overflow-x: auto;
white-space: nowrap;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
.pt-item {
font-size: 14px;
font-weight: 500;
letter-spacing: 0;
line-height: 16px;
color: #5A6872;
margin-right: 8px;
padding: 8px 12px;
border: 1px solid #pt-chip-grey;
border-radius: 4px;
background-color: #FAFAFA;
position: relative;
&:first-child {
margin-left: 18px;
}
}
.active {
background-color: #pt-red;
color: #pt-white;
}
}
I don't know the exact dom and css structure of your project. But can't you use something like this?
overflow-x: hidden
or
ul > li: first-child {
padding-left: 0;
}
My drop-down content on the navbar overlaps my button and doesnt go under the button like Id wish. The drop-down content opens at the top of my button and I want it to open at the botton of the button on the navbar. Im pretty sure the problem lies with the CSS of the navbar but I haven't figured it out yet. Any help? thank you.
<ul class="nav-links">
<li><button class="btn About"><b>About</b></button>
</li>
<li><button class="btn Our Team"><b>Staff</b>
</button></li>
<li><button class="btn Apps & Games"><b>Games</b>
</button></li>
<li><button class="btn Contact"><b>Contact</b>
</button></li>
<div class="dropdown">
<li><button class="btn link" id="dropbtn"><a href="#"><b>Links</b>
</a>
<i class="fa fa-caret-down" aria-hidden="true"></i></li>
</button>
<div class="dropdown-content">
<a ref="#">Link 1</a>
<a ref="#">Link 2</a>
<a ref="#">Link 3</a>
<a ref="#">Link 4</a>
</div>
</div>
</ul>
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
li {
float: left;
font-size: 0;
}
body {
margin: 0;
padding: 0;
background-image: url(.jpg);
background-size: cover;
}
p, p {
padding: 50px;
}
h1 {
-webkit-text-stroke: 3px black;
font-size: 50px;
}
nav {
height: 10vh;
background: red;
background-image: linear-gradient(to left, #e60000, #e60000, #e60000,
#e60000, black);
border-radius: 5px;
border-style: ridge;
overflow: hidden;
}
.btn {
border-radius: -10px;
background-color: inherit;
font-family: Arial, Helvetica, sans-serif;
color: white;
padding: 23px 33px;
cursor: pointer;
transition: 0.5s;
font-weight: 500;
letter-spacing: 1px;
text-transform: uppercase;
display: block;
}
.btn:hover {
background: black;
}
.nav-links {
display: flex;
list-style: none;
width: 50%;
height: 100%;
align-items: center;
margin-left: auto;
}
.nav-links li a {
color:white;
text-decoration: none;
font-size: 20px;
}
.landing {
height: 90vh;
display: flex;
justify-content: center;
align-items: center;
}
.landing h1 {
margin: 100px;
font-size: 50px;
color: white;
}
.dropdown {
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
float: right;
}
.dropdown-content {
display: none;
list-style: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
I'm a backend developer helping someone with an Angular webapplication and I ran into an issue when adding the fonts of our company, he uses material.
The red part is a mat-sidenav block and the blue is mat-sidenav-content the yellow part is some margin that suddenly is that big when I changed the fonts.
In devtools it looks like this:
so there is somewhere an element.style setting the margin but can't seem to find it in the code. Now the strange thing is if I dragged the tab out of chrome as a seperate window the issue is resolved but I don't think users will like doing that. Any clue why the margin changes and how I can resolve this permanently?
/* VAriables */
:root {
--color-accent: black; /* Fallback */
}
.u-category-test { --color-accent: rgba(67, 119, 64, 0.5); }
.u-category-qa { --color-accent: rgba(153, 100, 19, 0.5); }
.u-category-prod { --color-accent: rgba(216, 3, 3, 0.5); }
/* Nav */
.nav-header {
position: relative;
padding: 2rem;
}
.nav-title {
text-transform: uppercase;
font-weight: 300;
line-height: 1;
margin: 0;
}
.nav-title strong {
font-weight: 600;
}
.nav-header-icon {
position: absolute;
width: 36px;
height: 36px;
top: 1.5rem; /* magic */
right: 1.75rem; /* magic */
}
.nav-item {
padding: .5em 0.5em 0.5em 0;
}
.nav-icon {
width: 16px;
height: 16px;
vertical-align: top;
margin-right: .25rem;
}
.nav-category {
margin: .2em 0;
padding-left: 2rem;
font-size: 11px;
font-weight: normal;
text-transform: uppercase;
}
.nav-button {
display: block;
width: 100%;
padding: .2rem;
padding-left: calc(2rem + 16px + .5rem); /* padding + icon + magic */
line-height: 2;
text-align: left;
font: inherit;
font-size: 13px;
color: inherit;
border: none;
background-color: transparent;
cursor: default;
outline: none;
}
.nav-button:hover,
.nav-button:focus:not(.is-selected) {
background-color: hsla(0,0%,0%,.1);
}
.nav-button.is-selected {
background-color: var(--color-accent);
}
.nav-button.is-selected,
.nav-button.is-selected em {
color: #fff;
}
.nav-button.is-selected:focus {
opacity: .8;
}
.nav-button em {
font-style: normal;
font-weight: 600;
pointer-events: none; /* makes it invisible to clicks */
}
.nav-footer {
margin-top: 1rem;
padding: 2rem;
border-top: 1px solid var(--color-border);
text-align: center;
}
.nav-footer-version {
display: block;
width: 100%;
padding: 0;
margin-bottom: .75rem;
line-height: 2;
text-align: left;
font: inherit;
font-size: 13px;
color: inherit;
border: none;
background-color: transparent;
cursor: default;
outline: none;
text-align: center;
}
#button-download {
background-color: rgba(196, 196, 196, 0.5);
}
#button-download:hover {
background-color: rgba(150, 150, 150, 0.5);
}
.client-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #eee;
}
.main {
height: 100%;
}
<header class="nav-header">
<h1 class="nav-title">Clients</h1>
</header>
<div class="nav-item">
<h5 class="nav-category">
<span class="nav-icon flag-icon flag-icon-be"></span>
Client
</h5>
<button type="button" class="u-category-test nav-button" id="button-test" routerLink="test" routerLinkActive="is-selected">Dev</button>
<button type="button" class="u-category-qa nav-button" id="button-qa" routerLink="qa" routerLinkActive="is-selected">QA</button>
<button type="button" class="u-category-prod nav-button" id="button-prod" routerLink="prod" routerLinkActive="is-selected">Production</button>
</div>
.client-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #eee;
}
.main {
height: 100%;
}
#font-face {
font-family: 'Custom';
src: url('/assets/fonts/Custom.ttf') format('truetype');
}
* {
box-sizing: border-box;
}
html {
height: 100%;
font-family: 'Custom', 'BlinkMacSystemFont', 'Lucida Grande', 'Segoe UI', Ubuntu, Cantarell, sans-serif;
font-size: 14px;
line-height: 1.5;
overflow: hidden; /* Prevents rubber-band scrolling of the whole "page" */
color: var(--color);
background-color: #fff; /* To cover OSes with no default background color */
}
body {
margin: 0;
height: 100%;
display: flex;
}
h1,
h2,
h3 {
margin-top: 0;
line-height: 1.5;
}
h1 {
font-family: 'Custom';
font-size: 48px;
font-weight: normal;
}
h2 {
font-family: 'Custom';
font-weight: normal;
letter-spacing: -1px;
font-size: 16px;
}
h3, h4 {
font-family: 'Custom';
font-weight: normal;
font-size: 16px;
text-transform: uppercase;
}
h5{
font-family: 'Custom';
font-weight: normal;
font-size: 30px;
}
table {
width: 100%;
border-spacing: 0;
border: 1px solid hsla(0,0%,0%,.08);
border-width: 0 1px 1px 0;
}
th {
background-color: hsla(0,0%,50%,.06);
}
th,
td {
text-align: center;
border: 1px solid hsla(0,0%,0%,.08);
border-width: 1px 0 0 1px;
}
div.main{
padding: 30px;
button{
font-family: 'Custom';
margin: 10px;
}
button:hover{
background-color: transparent;
color:black;
}
}
<mat-sidenav-container class="client-container">
<mat-sidenav mode="side" opened><app-side-nav></app-side-nav></mat-sidenav>
<mat-sidenav-content>
<div class="main mat-app-background">
<router-outlet></router-outlet>
</div>
</mat-sidenav-content>
</mat-sidenav-container>
What helped me was applying position: unset to mat-sidenav-container. This element by default has position: relative.
Interestingly I had this problem only with multiple sidenavs.
<mat-sidenav-container>
<mat-sidenav mode="side" position="start" opened>
<desktop-main-navigation></desktop-main-navigation>
</mat-sidenav>
<mat-sidenav-content>
<router-outlet></router-outlet>
</mat-sidenav-content>
<mat-sidenav mode="over" position="end">
Notifications
</mat-sidenav>
</mat-sidenav-container>
Your specific issue and fact it happened when adding fonts might has been explained here:
https://stackoverflow.com/a/56219106/2804285
.button {
display: block;
text-decoration: none;
color: #103d82;
background: #fff;
border: 1px solid #d2cfcd;
font-size: 1.4rem;
line-height: 1;
padding: 10px;
text-align: center;
}
div .button {
margin: 0 auto;
}
<div>
Link
</div>
<div>
<button type="button" class="button">Button</button>
</div>
My two elements have the same CSS, however button is centered and not my link.
How to do the width of the link is calculated in the same way as the button?
Is it possible without added properties to the container?
Thanks
You can add max-width/width properties and box-sizing:border-box to make them behave the same :
.button {
display: block;
text-decoration: none;
color: #103d82;
background: #fff;
border: 1px solid #d2cfcd;
font-size: 1.4rem;
line-height: 1;
padding: 10px;
text-align: center;
max-width: 200px;
width: 100%;
box-sizing: border-box;
margin: 0 auto;
}
<div>
Link
</div>
<div>
<button type="button" class="button">Button</button>
</div>
You can also try fit-content value of width. Simply pay attention to browser support: https://caniuse.com/#search=fit-content
.button {
display: block;
text-decoration: none;
color: #103d82;
background: #fff;
border: 1px solid #d2cfcd;
font-size: 1.4rem;
line-height: 1;
padding: 10px;
text-align: center;
width: fit-content;
box-sizing: border-box;
margin: 0 auto;
}
<div>
Link
</div>
<div>
<button type="button" class="button">Button</button>
</div>
Another idea is to change the display:block to display:table and both links and buttons will behave the same :
.button {
display: table;
text-decoration: none;
color: #103d82;
background: #fff;
border: 1px solid #d2cfcd;
font-size: 1.4rem;
line-height: 1;
padding: 10px;
text-align: center;
box-sizing: border-box;
margin: 0 auto;
}
<div>
Link
</div>
<div>
<button type="button" class="button">Button</button>
</div>
What you can do is to change display: block to display: inline-block instead
then add text-align: center to their parents instead of margin: 0 auto as follow:
.button {
display: inline-block;
text-decoration: none;
color: #103d82;
background: #fff;
border: 1px solid #d2cfcd;
font-size: 1.4rem;
line-height: 1;
padding: 10px;
text-align: center;
}
div {
text-align: center;
}
<div>
Link
</div>
<div>
<button type="button" class="button">Button</button>
</div>
Try This:
* {
box-sizing: border-box;
}
div {
width: 100px;
position: relative;
margin: 0 auto;
}
.button {
width: 100%;
display: block;
text-decoration: none;
color: #103d82;
background: #fff;
border: 1px solid #d2cfcd;
font-size: 1.4rem;
text-align: center;
padding: 10px;
}
<div>
Link
</div>
<div>
<button type="button" class="button">Button</button>
</div>
I'm trying to vertically align two left and right floated elements in a nav bar. (Where the 'collapsed' nav bar has had the clearfix hack applied). The height of the navbar is determined by the left floated title (h2, 2em by default). However the right floated element, a form with input and button, doesn't sit centrally even when trying the transform approach to vertically centering items?
If I uncomment the transform vertical alignment approach it just sends form further up (not down and centred).
CodePen(https://codepen.io/yunti/pen/xdvpQK)
https://codepen.io/yunti/pen/xdvpQK
.header {
background-color: darkorange;
}
.header-title {
float: left;
padding-left: 10px;
color: white;
font-weight: 400;
}
.form-header {
float: right;
padding-right: 10px;
/*position: relative;*/
/*top: 50%;*/
/*transform: translateY(-50%);*/
}
.clearfix:after {
content: "";
clear: both;
display: table;
}
input,
button {
vertical-align: middle;
}
.form-control {
margin: 10px;
height: 34px;
width: 180px;
border-radius: 4px;
border: 1px solid #ccc;
font-size: 18px;
color: #555;
}
.form-control::placeholder {
color: grey;
}
.btn {
margin-left: 10px;
height: 34px;
padding-left: 12px;
padding-right: 12px;
line-height: 1.42857143;
white-space: nowrap;
border: 1px solid transparent;
border-radius: 4px;
background-color: forestgreen;
font-size: 14px;
font-weight: 400;
color: white;
cursor: pointer;
}
<div class="header clearfix">
<h1 class="header-title">Weather App</h1>
<div class="form-header">
<form class="form-group">
<input class="form-control" type="text" placeholder="St. George, Utah" />
<button class="btn">Get Weather</button>
</form>
</div>
</div>
Flexbox makes this really easy. Just add display: flex; justify-content: space-between; align-items: center; to the parent, and that will separate the elements in the parent and align them vertically.
.header {
background-color: darkorange;
display: flex;
align-items: center;
justify-content: space-between;
}
.header-title {
padding-left: 10px;
color: white;
font-weight: 400;
}
.form-header {
padding-right: 10px;
}
.form-control {
margin: 10px;
height: 34px;
width: 180px;
border-radius: 4px;
border: 1px solid #ccc;
font-size: 18px;
color: #555;
}
.form-control::placeholder {
color: grey;
}
.btn {
margin-left: 10px;
height: 34px;
padding-left: 12px;
padding-right: 12px;
line-height: 1.42857143;
white-space: nowrap;
border: 1px solid transparent;
border-radius: 4px;
background-color: forestgreen;
font-size: 14px;
font-weight: 400;
color: white;
cursor: pointer;
}
<div class="header">
<h1 class="header-title">Weather App</h1>
<div class="form-header">
<form class="form-group">
<input class="form-control" type="text" placeholder="St. George, Utah" />
<button class="btn">Get Weather</button>
</form>
</div>
</div>
Or if you don't want to use flexbox, you can use display: table on the parent, display: table-cell on the children in combination with vertical-align: middle
.header {
background-color: darkorange;
display: table;
width: 100%;
}
.header-title {
padding-left: 10px;
color: white;
font-weight: 400;
}
.header-title, .form-header {
vertical-align: middle;
display: table-cell;
}
.form-header {
padding-right: 10px;
text-align: right;
}
.form-control {
margin: 10px;
height: 34px;
width: 180px;
border-radius: 4px;
border: 1px solid #ccc;
font-size: 18px;
color: #555;
vertical-align: middle;
}
.form-control::placeholder {
color: grey;
}
.btn {
margin-left: 10px;
height: 34px;
padding-left: 12px;
padding-right: 12px;
line-height: 1.42857143;
white-space: nowrap;
border: 1px solid transparent;
border-radius: 4px;
background-color: forestgreen;
font-size: 14px;
font-weight: 400;
color: white;
cursor: pointer;
vertical-align: middle;
}
<div class="header">
<h1 class="header-title">Weather App</h1>
<div class="form-header">
<form class="form-group">
<input class="form-control" type="text" placeholder="St. George, Utah" />
<button class="btn">Get Weather</button>
</form>
</div>
</div>
You have different amounts of margin on your H1 element ("weather app" -- 22px) and your input/button (10px). Make your margin-top the same on all of these elements.