I have 3 dropdown buttons, on mobile view instead of displaying horizontally they are overlapping on each other. I think .filter-check:checked+label class properties needs to be reviewed. What changes can I make in my code so that buttons are displayed horizontally?
Here is my scss code
#media (min-width: 700px) {
.filter-button {
display: none;
}
.filter-check {
display: none;
}
}
#media (max-width: 700px) {
.filter {
display: none;
}
.filter-check {
display: none;
}
}
#media screen and (max-width: 700px) {
.filter-button {
background: white;
border: 1px solid black;
border-radius: 2px;
color: dark-gray;
float: right;
font-family: font-family-nimbus-sans-bold;
font-size: 18px;
height: 48px;
text-align: left;
width: 100%;
}
}
// sass-lint:disable force-pseudo-nesting
.filter-check:checked+label { ---------------> I think this class properties needs to be checked
+.filters {
.filter {
background-color: white;
display: block;
height: 100%;
left: 0;
overflow-y: auto;
padding-bottom: 65px;
position: fixed;
top: 0;
width: 100%;
}
::ng-deep {
.overlay-drop {
height: auto;
position: relative;
}
.open {
ul {
position: relative;
top: auto;
}
}
}
}
}
.filters {
display: flex;
flex-wrap: wrap;
#media screen and (min-width: 700px) {
.filter {
background-color: white;
border: 1px solid black;
border-radius: 2px;
flex-basis: 100%;
flex-grow: 1;
flex-shrink: 1;
height: 72px;
margin-right: 10px;
max-width: 224px;
&.disabled {
border-color: silver-chalice;
color: silver-chalice;
opacity: .4;
pointer-events: none;
&:hover {
cursor: no-drop;
}
}
}
}
}
Here is my html code
<ng-container>
<label class="filter-button" for="button" (click)="xy()">Coders</label>
<div class="filters">
<div class="filter">
<overlay-drop [dropdownLabel]="i18nService"
[modelDropdown]="a">
</overlay-drop>
</div>
<div class="filter">
<overlay-drop [dropdownLabel]="i18nService"
[modelDropdown]="b">
</overlay-drop>
</div>
<div class="filter">
<overlay-drop [dropdownLabel]="i18nService"
[modelDropdown]="c">
</overlay-drop>
</div>
<div class="filter">
<overlay-drop [dropdownLabel]="i18nService"
[modelDropdown]="shareClassData"></overlay-drop>
</div>
</div>
</ng-container>
/ng-container>
Try this code for scss
#media (min-width: 700px) {
.filter-button {
display: none;
}
.filter-check {
display: none;
}
}
#media (max-width: 700px) {
.filter-check {
display: none;
}
}
.filter-button {
background: white;
border: 1px solid black;
border-radius: 2px;
color: dark-gray;
float: none;
font-family: font-family-nimbus-sans-bold;
font-size: 18px;
height: 48px;
text-align: left;
width: 100%;
}
// sass-lint:disable force-pseudo-nesting
.filter-check:checked+label {
+.filters {
.filter {
background-color: white;
display: block;
height: 100%;
left: 0;
overflow-y: auto;
padding-bottom: 65px;
position: fixed;
top: 0;
width: 100%;
}
::ng-deep {
.overlay-drop {
height: auto;
position: relative;
}
.open {
ul {
position: relative;
top: auto;
}
}
}
}
}
.filters {
display: flex;
.filter {
background-color: white;
border: 1px solid black;
border-radius: 2px;
flex-basis: 100%;
flex-grow: 1;
flex-shrink: 1;
height: 72px;
margin-right: 10px;
max-width: 224px;
&.disabled {
border-color: silver-chalice;
color: silver-chalice;
opacity: .4;
pointer-events: none;
&:hover {
cursor: no-drop;
}
}
}
}
<ng-container>
<label class="filter-button" for="button" (click)="xy()">Coders</label>
<div class="filters">
<div class="filter">
<overlay-drop [dropdownLabel]="i18nService"
[modelDropdown]="a">
</overlay-drop>
</div>
<div class="filter">
<overlay-drop [dropdownLabel]="i18nService"
[modelDropdown]="b">
</overlay-drop>
</div>
<div class="filter">
<overlay-drop [dropdownLabel]="i18nService"
[modelDropdown]="c">
</overlay-drop>
</div>
<div class="filter">
<overlay-drop [dropdownLabel]="i18nService"
[modelDropdown]="shareClassData"></overlay-drop>
</div>
</div>
</ng-container>
Related
So I have been coding a website with some friends for our robotics team and have run into a problem with our nav bar. It works well for any PC/laptop/mac books and Android devicesWorking nav bar on Android phone but on all iPhones the nav bar is stretched Screen shot of the stretched nav bar. Here is the CSS and HTML code that we have `
body {
background-color: rgb(90, 88, 88);
margin: 0;
padding: 0;
user-select: none;
}
#img {
width: 5.6%;
height: 100%;
}
#topBar {
position: fixed;
list-style-type: none;
width: 100%;
height: 10%;
display: inline-block;
overflow: hidden;
background-color: #333;
z-index: 999;
}
.topbar-section {
color: white;
text-align: center;
padding: 1.5rem .5rem;
display: inline-block;
font-family: "Helvetica ", sans-serif;
font-weight: 100;
width: 10vw;
height: 100%;
}
#h {
color: rgb(253, 253, 253);
font-family: "Helvetica ", sans-serif;
text-decoration: none;
font-weight: 100;
font-size: 100%;
}
#heo {
display: inline-block;
text-align: center;
padding: 1.6rem 0.6%;
}
.tabs {
font-size: 100%;
font-weight: 100;
}
.topbar-section:hover {
background-color: #111;
}
.Toggle {
position: absolute;
top: 2.1rem;
right: 1rem;
display: none;
flex-direction: column;
justify-content: space-between;
width: 30px;
height: 21px;
}
.Toggle .bar {
height: 3px;
width: 100%;
background-color: white;
border-radius: 10px;
}
#con {
margin-right: 10px;
float: right;
margin: 0;
padding: 0;
}
.active {
display: block;
}
#media(max-width: 1050px) {
.Toggle {
position: absolute;
top: 4vh;
right: 1rem;
}
.Toggle {
display: flex;
}
#img {
width: 8%;
}
#topbar {
height: auto;
}
.topbar-section {
display: block;
}
.topbar-section {
width: 100%;
padding: .7rem;
}
#con {
text-align: center;
width: 100%;
margin-right: 0;
}
.active {
display: none;
}
.HomeTexpandlogo {
display: block;
width: 10%;
height: 10%;
}
#h {
font-size: 80%;
}
}
#media(max-width: 450px) {
#h {
font-size: 60%;
}
}
<div id="topBar">
<img id="img" src="images/txpand_logo-removebg-preview.png">
<div id="heo">
<h1 id="h">Expanding STEM skills through robotics</h1>
</div>
<a href="#" class="Toggle" id="toggle-button">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</a>
<div id="con" class="active">
<div class="topbar-section" id="homeTab">
<span class="tabs">Home</span>
</div>
<div class="topbar-section" id="aboutUsTab">
<span class="tabs">About us</span>
</div>
<div class="topbar-section" id="outreachTab">
<span class="tabs">Outreach</span>
</div>
<div class="topbar-section" id="pastRobotsTab">
<span class="tabs">Past Robots</span>
</div>
<div class="topbar-section" id="sponsorshipsTab">
<span class="tabs">Sponsorships</span>
</div>
<div class="topbar-section" id="donationsTab" style="display:none;">
<span class="tabs">Donations</span>
</div>
</div>
</div>
Has anyone else run in to this problem and know how to fix it?
Thanks for the help in advance.
I'm trying to learn how to create burger menus for the mobile version of the site. I've managed to create a simple burger-menu with a little help of js, but I faced the problem with overflow. Burger works fine, but it has a sidescroll when it's unactive. I understand that it could be fixed with position: relative and overflow: hidden, but I can't figure out to which block I should apply those parameters. When I try to apply this parameters to the parent header block, burger menu becomes the header's hight. Can't really understand how to avoid it.
HTML:
`<header class="header">
<div class="header__container">
<a href="#"
><div class="logo__block">
<img src="img/logo.svg" alt="Logo" /></div
></a>
<nav class="header__nav nav">
<ul class="nav__list">
<div class="burger-menu__exit">X</div>
<li class="nav__item">
Home
</li>
<li class="nav__item">
Features
</li>
<li class="nav__item">
Pricing
</li>
<li class="nav__item">
Blog
</li class="nav__item nav-btn">
</ul>
</nav>
<a class="header-btn" href="#">Get Started</a>
<div class="burger-menu">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
</div>
</header>`
CSS:
`body {
font-family: "Libre Franklin", sans-serif;
}
[class$="__container"] {
max-width: 1270px;
margin: 0 auto;
padding: 0 15px;
}
.header__container {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
line-height: 60px;
padding-top: 40px;
padding-bottom: 60px;
}
.header__container:before{
position: relative;
}
.logo__block {
display: flex;
align-items: center;
}
.nav {
margin-left: auto;
}
.nav__list {
display: flex;
flex-direction: row;
justify-content: flex-end;
}
.nat__item {
}
.nav-btn {
display: none;
}
.nav__list > li:not(.nav__item:last-child) {
margin-right: 100px;
}
.nav__item:last-child {
margin-right: 79px;
}
.nav__link {
font-style: normal;
font-weight: 400;
font-size: 20px;
}
.nav__link:hover {
border-bottom: 2px solid black;
}
.btn__block {
max-width: 286px;
}
.header-btn {
width: 211px;
text-align: center;
border-radius: 10px;
font-style: normal;
font-weight: 500;
font-size: 20px;
color: white;
background-color: #ff7143;
transition: 0.3s;
}
.header-btn:hover {
background-color: #d1542b;
}
.burger-menu {
display: none;
margin-left: 10px;
cursor: pointer;
}
.burger-menu__exit {
display: none;
}
.line {
width: 35px;
height: 2px;
background-color: black;
margin-top: 10px;
}
.line1 {
margin-top: 0;
}
#media (max-width: 1309px) {
[class$="__container"] {
max-width: 1103px;
}
}
#media (max-width: 1129px) {
[class$="__container"] {
max-width: 1000px;
}
.nav__list > li:not(.nav__item:last-child) {
margin-right: 50px;
}
.nav__item:last-child {
margin-right: 79px;
}
}
#media (max-width: 988.98px) {
[class$="__container"] {
max-width: none;
}
.burger-menu {
display: block;
}
.header__nav {
background-color: #5454d4;
z-index: 9999;
}
.nav {
position: absolute;
top: 0;
left: 100%;
right: -100%;
z-index: 999;
min-width: 375px;
height: 100vh;
padding-top: 30px;
color: #ff7143;
transition: 1s;
}
.nav__list {
position: relative;
flex-direction: column;
align-items: center;
justify-content: center;
}
.nav__list a {
color: #ff7143;
}
.nav__list a:hover {
border-bottom: 2px solid #ff7143;
}
.nav__list > li:not(.nav__item:last-child) {
margin-right: 0;
}
.nav__item:last-child {
margin-right: 0;
}
.header-btn {
margin-left: auto;
}
.burger-menu__exit {
display: block;
cursor: pointer;
position: absolute;
top: 0;
right: 18px;
font-size: 40px;
}
}
#media (max-width: 512.98px) {
.header-btn {
display: none;
}
}
#media (max-width: 369.98px) {
.nav {
min-width: 100%;
}
}`
JS:
const mobileNav = document.querySelector(".nav");
const headerButton = document.querySelector(".header-btn");
const headerContainer = document.querySelector(".header__container");
document.querySelector(".burger-menu").addEventListener("click", () => {
mobileNav.style.right = 0;
});
document.querySelector(".burger-menu__exit").addEventListener("click", () => {
mobileNav.style.right = -100 + "%";
});
Thanks for the help!
Issue was fixed by adding the different navigation for burger outside the header block and adding the position: relative; overflow: hidden; to the html and body.
I have a custom dropdown and I've set up focus states on the dropdown and the items in it. But, when I select an item from the first menu, the focus goes to the nav and not the next dropdown. Is there a way to target the second dropdown after the first one?
Here's a Codepen if you'd prefer.
for (const dropdown of document.querySelectorAll(".custom__select-wrapper:not(.clearFilter)")) {
dropdown.addEventListener("click", function () {
this.querySelector(".custom__select").classList.toggle("open");
});
}
for (const option of document.querySelectorAll(".custom__option")) {
option.addEventListener("click", function () {
if (!this.classList.contains("selected")) {
this.parentNode
.querySelector(".custom__option.selected")
.classList.remove("selected");
this.classList.add("selected");
this.closest(".custom__select").querySelector(
".custom__select-trigger h6"
).textContent = this.textContent;
if (this.getAttribute("data-type")) {
current_story = this.dataset["type"];
}
}
});
}
window.addEventListener("click", function (e) {
for (const select of document.querySelectorAll(".custom__select")) {
if (!select.contains(e.target)) {
select.classList.remove("open");
}
}
});
#charset "UTF-8";
nav ul {
list-style-type: none;
display: flex;
flex-direction: row;
width: 100%;
justify-content: space-evenly;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
}
button.clear {
border: 0;
background: #fff;
}
#selectedFilter {
color: #005fec;
}
ul {
padding-left: 0;
margin: 0;
}
.filter {
padding-right: 15px;
padding-left: 15px;
margin-bottom: 2rem;
display: flex;
flex-direction: column;
}
#media (min-width: 768px) {
.filter__settings {
display: flex;
flex-direction: row;
border-top: 1px solid #E0E5EC;
border-bottom: 1px solid #E0E5EC;
}
}
.custom__select {
position: relative;
display: flex;
flex-direction: column;
}
#media (min-width: 768px) {
.custom::before, .custom__options {
transition: all 0.2s ease-in;
}
}
.custom__select-wrapper {
position: relative;
user-select: none;
padding: 0;
border-bottom: 1px solid #E0E5EC;
}
.custom__select-wrapper:last-child {
border: 0;
}
.custom__select-wrapper.clearFilter {
display: flex;
flex-direction: column;
justify-content: center;
}
.custom__select-wrapper .selected-clearFilter {
position: relative;
user-select: none;
padding: 1rem 0 !important;
}
#media (min-width: 768px) {
.custom__select-wrapper {
padding: 0 2em;
border: 0;
display: flex;
justify-content: center;
align-items: center;
}
.custom__select-wrapper:first-child, .custom__select-wrapper:last-child {
padding: 0;
}
}
.custom__select-wrapper h6 {
padding: 20px 3px;
color: #62668C;
font-weight: 300;
}
.custom__select-trigger {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
}
#media (min-width: 768px) {
.custom__select-trigger {
justify-content: space-evenly;
margin-right: auto;
}
}
.custom__select-wrapper h6, .custom__select-trigger h6 {
font-size: 0.75rem;
line-height: 0.75rem;
letter-spacing: 1px;
text-transform: uppercase;
padding: 20px 0;
}
.custom__select-trigger h6 {
color: #005fec;
font-weight: 900;
}
.custom__select-wrapper #selectedFilter {
font-size: 12px;
line-height: 12px;
letter-spacing: 1px;
text-transform: uppercase;
color: #005fec;
font-weight: 800;
padding: 0;
}
.custom__options {
display: none;
top: 100%;
left: 0;
right: 0;
border-top: 0;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 2;
color: #E0E5EC;
}
#media (min-width: 768px) {
.custom__options {
display: unset;
position: absolute;
background-color: #005fec;
max-height: 320px;
overflow-y: scroll;
}
.custom__options#storyFilter {
overflow: hidden;
}
}
.custom__options.active {
display: block;
visibility: visible;
opacity: 1;
z-index: 10;
}
.custom__select-trigger, .custom__option {
letter-spacing: 1px;
font-weight: 800;
color: #005fec;
border: 0;
background: transparent;
}
#media (min-width: 768px) {
.custom__select.open::before {
content: "";
position: absolute;
bottom: 0;
left: 11px;
border-left: 11px solid transparent;
border-right: 11px solid transparent;
border-bottom: 11px solid #005fec;
}
}
.custom__select .custom__options {
min-width: 15rem;
}
.custom__select.open .custom__options {
display: block;
opacity: 1;
visibility: visible;
pointer-events: all;
color: #fff;
min-width: 15rem;
}
#media (min-width: 768px) {
.custom__select.open .custom__options {
display: unset;
box-shadow: 0px 12px 30px rgba(0, 0, 0, 0.12);
}
}
.custom__option {
position: relative;
display: block;
padding: 0 22px 0 12px;
font-weight: 400;
color: #62668C;
cursor: pointer;
font-size: 1rem;
line-height: 1rem;
margin: 1.5rem 0;
}
#media (min-width: 768px) {
.custom__option {
font-size: 1.25rem;
line-height: 1.25rem;
color: white;
font-weight: 300;
padding: 0 22px 0 20px;
}
.custom__option a {
color: white !important;
text-decoration: none;
}
}
.custom__option:hover {
cursor: pointer;
}
.custom__option.selected {
color: #005fec;
}
#media (min-width: 768px) {
.custom__option.selected {
color: #ffffff;
}
}
.custom__option.selected::before {
content: "•";
margin-left: -12px;
padding-right: 8px;
}
.empty-state {
width: 100%;
display: flex;
background: #005fec;
padding: 1rem;
border-radius: 4px;
align-items: center;
margin: 2rem 0.5rem;
}
.empty-state h4 {
color: white;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 300;
margin-left: 0.5rem;
}
.empty-state h4 span {
color: white;
text-decoration: underline;
cursor: pointer;
}
.arrow {
position: relative;
height: 5px;
width: 3px;
margin-left: 0.5rem;
margin-bottom: 0.1rem;
}
.arrow::before, .arrow::after {
content: "";
position: absolute;
bottom: 0px;
width: 0.1rem;
height: 100%;
transition: all 0.45s;
}
.arrow::before {
left: 0px;
transform: rotate(45deg);
background-color: #005fec;
}
#media (min-width: 768px) {
.arrow::before {
left: 7px;
}
}
.arrow::after {
left: -2.5px;
transform: rotate(-45deg);
background-color: #005fec;
}
#media (min-width: 768px) {
.arrow::after {
left: 4.5px;
}
}
.open .arrow::before {
left: 0px;
transform: rotate(-45deg);
}
#media (min-width: 768px) {
.open .arrow::before {
left: 7px;
}
}
.open .arrow::after {
left: -2.5px;
transform: rotate(45deg);
}
#media (min-width: 768px) {
.open .arrow::after {
left: 4.5px;
}
}
<div class="container">
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Products</li>
<li>Sales</li>
<li>Contact</li>
</ul>
</nav>
<section class="content">
<h2 class="title">Hello World</h2>
<h6 class="subtitle">Lorem ipsum dolor sit amet.</h6>
</section>
<section class="filter">
<div class="filter__settings">
<div class="custom__select-wrapper">
<h6>filter by</h6>
</div>
<div class="custom__select-wrapper">
<div class="custom__select story-sel selector" role="menubar">
<button class="custom__select-trigger" aria-haspopup="true" aria-expanded="false" id="storySelector">
<h6>Story Type</h6>
<div class="arrow"></div>
</button>
<ul class="custom__options dropdown story-selector" id="storyFilter" aria-label="submenu" role="menu" aria-labelledby="custom-dropdown">
<li role="menuitem" class="custom__option selected" data-type="all" id="storyItem_all">All
</li>
<li role="menuitem" class="custom__option" data-type="news" id="storyItem_nm"><a href="#">News and
media</a></li>
<li role="menuitem" class="custom__option" data-type="analysis" id="storyItem_analysis">Analysis</li>
<li role="menuitem" class="custom__option" data-type="press" id="storyItem_pr"><a href="#">Press
releases</a></li>
</ul>
</div>
</div>
<div class="custom__select-wrapper">
<div class="custom__select year-sel selector">
<button type="button" class="custom__select-trigger" id="yearSelector">
<h6>Year</h6>
<div class=" arrow"></div>
</button>
<ul class="custom__options dropdown year-selector" id="yearSelection" aria-label="submenu" role="menu" aria-labelledby="custom-dropdown">
<li role="menuitem" class="custom__option selected" data-year="all">All</li>
<li role="menuitem" class="custom__option" data-year="2021">2021</li>
<li role="menuitem" class="custom__option" data-year="2020">2020</li>
<li role="menuitem" class="custom__option" data-year="2019">2019</li>
</ul>
</div>
</div>
</div>
</section>
</div>
The problem lies in your anchor tags. Specifically, setting the href attribute to # will cause the page to jump to the top.
From MDN:
You can use href="#top" or the empty fragment (href="#") to link to the top of the current page, as defined in the HTML specification.
In your case, simply remove the href attribute. If you want to preserve navigation with the keyboard, set it to "javascript:void(0)"
for (const dropdown of document.querySelectorAll(".custom__select-wrapper:not(.clearFilter)")) {
dropdown.addEventListener("click", function () {
this.querySelector(".custom__select").classList.toggle("open");
});
}
for (const option of document.querySelectorAll(".custom__option")) {
option.addEventListener("click", function () {
if (!this.classList.contains("selected")) {
this.parentNode
.querySelector(".custom__option.selected")
.classList.remove("selected");
this.classList.add("selected");
this.closest(".custom__select").querySelector(
".custom__select-trigger h6"
).textContent = this.textContent;
if (this.getAttribute("data-type")) {
current_story = this.dataset["type"];
}
}
});
}
window.addEventListener("click", function (e) {
for (const select of document.querySelectorAll(".custom__select")) {
if (!select.contains(e.target)) {
select.classList.remove("open");
}
}
});
#charset "UTF-8";
nav ul {
list-style-type: none;
display: flex;
flex-direction: row;
width: 100%;
justify-content: space-evenly;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
}
button.clear {
border: 0;
background: #fff;
}
#selectedFilter {
color: #005fec;
}
ul {
padding-left: 0;
margin: 0;
}
.filter {
padding-right: 15px;
padding-left: 15px;
margin-bottom: 2rem;
display: flex;
flex-direction: column;
}
#media (min-width: 768px) {
.filter__settings {
display: flex;
flex-direction: row;
border-top: 1px solid #E0E5EC;
border-bottom: 1px solid #E0E5EC;
}
}
.custom__select {
position: relative;
display: flex;
flex-direction: column;
}
#media (min-width: 768px) {
.custom::before, .custom__options {
transition: all 0.2s ease-in;
}
}
.custom__select-wrapper {
position: relative;
user-select: none;
padding: 0;
border-bottom: 1px solid #E0E5EC;
}
.custom__select-wrapper:last-child {
border: 0;
}
.custom__select-wrapper.clearFilter {
display: flex;
flex-direction: column;
justify-content: center;
}
.custom__select-wrapper .selected-clearFilter {
position: relative;
user-select: none;
padding: 1rem 0 !important;
}
#media (min-width: 768px) {
.custom__select-wrapper {
padding: 0 2em;
border: 0;
display: flex;
justify-content: center;
align-items: center;
}
.custom__select-wrapper:first-child, .custom__select-wrapper:last-child {
padding: 0;
}
}
.custom__select-wrapper h6 {
padding: 20px 3px;
color: #62668C;
font-weight: 300;
}
.custom__select-trigger {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
}
#media (min-width: 768px) {
.custom__select-trigger {
justify-content: space-evenly;
margin-right: auto;
}
}
.custom__select-wrapper h6, .custom__select-trigger h6 {
font-size: 0.75rem;
line-height: 0.75rem;
letter-spacing: 1px;
text-transform: uppercase;
padding: 20px 0;
}
.custom__select-trigger h6 {
color: #005fec;
font-weight: 900;
}
.custom__select-wrapper #selectedFilter {
font-size: 12px;
line-height: 12px;
letter-spacing: 1px;
text-transform: uppercase;
color: #005fec;
font-weight: 800;
padding: 0;
}
.custom__options {
display: none;
top: 100%;
left: 0;
right: 0;
border-top: 0;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 2;
color: #E0E5EC;
}
#media (min-width: 768px) {
.custom__options {
display: unset;
position: absolute;
background-color: #005fec;
max-height: 320px;
overflow-y: scroll;
}
.custom__options#storyFilter {
overflow: hidden;
}
}
.custom__options.active {
display: block;
visibility: visible;
opacity: 1;
z-index: 10;
}
.custom__select-trigger, .custom__option {
letter-spacing: 1px;
font-weight: 800;
color: #005fec;
border: 0;
background: transparent;
}
#media (min-width: 768px) {
.custom__select.open::before {
content: "";
position: absolute;
bottom: 0;
left: 11px;
border-left: 11px solid transparent;
border-right: 11px solid transparent;
border-bottom: 11px solid #005fec;
}
}
.custom__select .custom__options {
min-width: 15rem;
}
.custom__select.open .custom__options {
display: block;
opacity: 1;
visibility: visible;
pointer-events: all;
color: #fff;
min-width: 15rem;
}
#media (min-width: 768px) {
.custom__select.open .custom__options {
display: unset;
box-shadow: 0px 12px 30px rgba(0, 0, 0, 0.12);
}
}
.custom__option {
position: relative;
display: block;
padding: 0 22px 0 12px;
font-weight: 400;
color: #62668C;
cursor: pointer;
font-size: 1rem;
line-height: 1rem;
margin: 1.5rem 0;
}
#media (min-width: 768px) {
.custom__option {
font-size: 1.25rem;
line-height: 1.25rem;
color: white;
font-weight: 300;
padding: 0 22px 0 20px;
}
.custom__option a {
color: white !important;
text-decoration: none;
}
}
.custom__option:hover {
cursor: pointer;
}
.custom__option.selected {
color: #005fec;
}
#media (min-width: 768px) {
.custom__option.selected {
color: #ffffff;
}
}
.custom__option.selected::before {
content: "•";
margin-left: -12px;
padding-right: 8px;
}
.empty-state {
width: 100%;
display: flex;
background: #005fec;
padding: 1rem;
border-radius: 4px;
align-items: center;
margin: 2rem 0.5rem;
}
.empty-state h4 {
color: white;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 300;
margin-left: 0.5rem;
}
.empty-state h4 span {
color: white;
text-decoration: underline;
cursor: pointer;
}
.arrow {
position: relative;
height: 5px;
width: 3px;
margin-left: 0.5rem;
margin-bottom: 0.1rem;
}
.arrow::before, .arrow::after {
content: "";
position: absolute;
bottom: 0px;
width: 0.1rem;
height: 100%;
transition: all 0.45s;
}
.arrow::before {
left: 0px;
transform: rotate(45deg);
background-color: #005fec;
}
#media (min-width: 768px) {
.arrow::before {
left: 7px;
}
}
.arrow::after {
left: -2.5px;
transform: rotate(-45deg);
background-color: #005fec;
}
#media (min-width: 768px) {
.arrow::after {
left: 4.5px;
}
}
.open .arrow::before {
left: 0px;
transform: rotate(-45deg);
}
#media (min-width: 768px) {
.open .arrow::before {
left: 7px;
}
}
.open .arrow::after {
left: -2.5px;
transform: rotate(45deg);
}
#media (min-width: 768px) {
.open .arrow::after {
left: 4.5px;
}
}
<div class="container">
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Products</li>
<li>Sales</li>
<li>Contact</li>
</ul>
</nav>
<section class="content">
<h2 class="title">Hello World</h2>
<h6 class="subtitle">Lorem ipsum dolor sit amet.</h6>
</section>
<section class="filter">
<div class="filter__settings">
<div class="custom__select-wrapper">
<h6>filter by</h6>
</div>
<div class="custom__select-wrapper">
<div class="custom__select story-sel selector" role="menubar">
<button class="custom__select-trigger" aria-haspopup="true" aria-expanded="false" id="storySelector">
<h6>Story Type</h6>
<div class="arrow"></div>
</button>
<ul class="custom__options dropdown story-selector" id="storyFilter" aria-label="submenu" role="menu" aria-labelledby="custom-dropdown">
<li role="menuitem" class="custom__option selected" data-type="all" id="storyItem_all">All
</li>
<li role="menuitem" class="custom__option" data-type="news" id="storyItem_nm"><a href="javascript:void(0);">News and
media</a></li>
<li role="menuitem" class="custom__option" data-type="analysis" id="storyItem_analysis">Analysis</li>
<li role="menuitem" class="custom__option" data-type="press" id="storyItem_pr"><a href="javascript:void(0);">Press
releases</a></li>
</ul>
</div>
</div>
<div class="custom__select-wrapper">
<div class="custom__select year-sel selector">
<button type="button" class="custom__select-trigger" id="yearSelector">
<h6>Year</h6>
<div class=" arrow"></div>
</button>
<ul class="custom__options dropdown year-selector" id="yearSelection" aria-label="submenu" role="menu" aria-labelledby="custom-dropdown">
<li role="menuitem" class="custom__option selected" data-year="all">All</li>
<li role="menuitem" class="custom__option" data-year="2021">2021</li>
<li role="menuitem" class="custom__option" data-year="2020">2020</li>
<li role="menuitem" class="custom__option" data-year="2019">2019</li>
</ul>
</div>
</div>
</div>
</section>
</div>
I have two divs sort of like a 50 50 divided screen, and so it looks good in computer size screen and in phone screen but right between these two, the right div just dissappears and I cant figure it out.
originally the code is echoed in php and the information is from a database so I put here some dummy info.
* {
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
font-family: 'Heebo', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
body {
margin: 0;
padding: 72px 0 0 0;
overflow: hidden;
}
/*style for the slider container*/
.slidercon {
width: 50vw;
height: 100vh;
overflow: hidden;
float: left;
display: table;
}
.maincon {
width: 100%;
display: table-cell;
vertical-align: middle;
}
.imgslider {
margin: auto;
max-width: 560px;
max-height: 315px;
overflow: hidden;
position: relative;
}
.imgslider>ul {
margin: 0;
padding: 0;
display: flex;
position: relative;
top: 0;
left: 0;
transition: 0.2s;
width: 100%;
}
.imgslider>ul>li {
list-style-type: none;
min-width: 560px;
overflow: hidden;
}
.imgdiv {
width: 100%;
height: 315px;
justify-content: center;
text-align: center;
}
.imgdiv>img {
width: auto;
max-height: 315px;
}
.youtubevid {
display: flex;
display: -webkit-flex;
display: -ms-flex;
}
/*style for the dots*/
.dotsContainer {
text-align: center;
}
.dots {
cursor: pointer;
height: 20px;
width: 20px;
margin: 5px 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.dots:first-child {
background: white;
border: 1px solid grey;
;
}
/*content style*/
.content {
float: right;
width: 50vw;
height: 100vh;
overflow: hidden;
display: table;
text-align: right;
}
.innercont {
/* padding: 15px; */
direction: rtl;
display: table-cell;
vertical-align: middle;
}
.innercont>span:first-child {
font-size: 40px;
padding: 25px;
display: block;
}
.innercont>span:nth-child(2) {
padding: 25px;
font-size: 20px;
display: block;
word-wrap: break-word;
}
.price {
padding: 10px;
font-size: 22px;
}
.price>span {
margin: 0 15px;
}
.price>span:nth-child(2) {
float: left;
}
/*style for the phone number input*/
.PhoneN-section {
position: relative;
height: 50px;
margin: 15px;
}
.PhoneN-section input {
width: 100%;
height: 100%;
border-radius: 10px;
outline: none;
border: 1px solid rgb(230, 230, 230);
font-size: 20px;
padding: 10px 10px 0 10px;
text-align: left;
direction: ltr;
}
input:focus~.PhoneN-label .label-content,
input:valid~.PhoneN-label .label-content {
transform: translateY(-120%);
}
label:not([for="checkbox"]) {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.label-content {
font-size: 20px;
position: absolute;
bottom: 10px;
right: 10px;
transition: all 0.3s ease;
background: white;
}
input:focus {
border: 2px solid rgb(76, 240, 0);
transition-delay: 0.2s;
}
/*style for the submit button*/
.phone-submit {
height: 50px;
margin: 15px 0;
}
.phone-submit button {
width: 100%;
height: 100%;
outline: none;
border: none;
border-radius: 10px;
color: white;
background: rgb(76, 240, 0);
cursor: pointer;
font-size: 20px;
}
/*style for the exclamation message*/
.mark {
float: right;
margin: 0 5px;
font-size: 14px;
font-weight: 600;
padding: 2px 7px;
border-radius: 50%;
border: 1px solid grey;
}
.messaget {
color: grey;
}
#media screen and (max-width: 850px) {
body {
overflow-y: auto;
}
.slidercon {
width: unset;
height: unset;
float: unset;
display: block;
}
.maincon {
display: block;
}
.content {
float: none;
width: unset;
height: 100vh;
display: block;
}
.innercont {
display: block;
}
}
#media screen and (max-width: 550px) {
.imgdiv {
justify-content: unset;
text-align: unset;
}
.imgdiv>img {
margin: 0 20%;
}
}
#media only screen and (max-width: 550px) {
.imgdiv>img {
margin: 0 10%;
}
}
#media only screen and (max-width: 420px) {
.imgdiv>img {
margin: 0 7%;
}
}
#media only screen and (max-width: 400px) {
.imgdiv>img {
margin: 0 5%;
}
}
<div class="slidercon">
<div class="maincon">
<div class="imgslider">
<ul>
<li>
<div class="imgdiv">
<img src="img" alt="item">
</div>
</li>
<li>
<div class="youtubevid">
<iframe style="position:absolute;width:100%;height:100%;" src="link" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</li>';
</ul>
</div>
<div class="dotsContainer">
<span class="dots"></span>
<span class="dots"></span>
</div>
</div>
</div>
<div class="content">
<div class="innercont">
<span>'Type'</span>
<span>'Description'</span>
<div class="price">
<span>Price</span>
<span>'1,111' ₪</span>
</div>
<form action="includes/sendPhone.php" method="POST">
<div class="PhoneN-section">
<input type="text" name="PhoneN" autocomplete="off" required />
<input type="hidden" name="itemid" value="id" />
<input type="hidden" name="itemtype" value="TYPE" />
<input type="hidden" name="price" value="1,111" />
<label for="PhoneN" class="PhoneN-label">
<span class="label-content">Phone Number</span>
</label>
<div class="phone-submit">
<button type="submit" name="phone-submit">SEND</button>
</div>
<span>
<span class="mark">!</span>
<span class="messaget">BLa lbla bla bla bla bla bla bla bla blab la</span>
</span>
</div>
</form>
</div>
</div>
In accordance to my understanding,your issue is that it is not responsive to some devices.
So i tried it out using flex box approach.
I added a container wrapper to all other divs and have it display its children in a flex manner.
Then added two inner containers each width 50vw containing your slider con and content respectively.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
* {
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
font-family: 'Heebo', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
body {
margin: 0;
padding: 72px 0 0 0;
overflow: hidden;
}
.container{
display: flex;
}
.innercontainer{
width: 50vw;
}
/*style for the slider container*/
.slidercon {
width: 50vw;
height: 100vh;
overflow: hidden;
float: left;
display: table;
}
.maincon {
width: 100%;
display: table-cell;
vertical-align: middle;
}
.imgslider {
margin: auto;
max-width: 560px;
max-height: 315px;
overflow: hidden;
position: relative;
}
.imgslider>ul {
margin: 0;
padding: 0;
display: flex;
position: relative;
top: 0;
left: 0;
transition: 0.2s;
width: 100%;
}
.imgslider>ul>li {
list-style-type: none;
min-width: 560px;
overflow: hidden;
}
.imgdiv {
width: 100%;
height: 315px;
justify-content: center;
text-align: center;
}
.imgdiv>img {
width: auto;
max-height: 315px;
}
.youtubevid {
display: flex;
display: -webkit-flex;
display: -ms-flex;
}
/*style for the dots*/
.dotsContainer {
text-align: center;
}
.dots {
cursor: pointer;
height: 20px;
width: 20px;
margin: 5px 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.dots:first-child {
background: white;
border: 1px solid grey;
;
}
/*content style*/
.content {
float: right;
width: 50vw;
height: 100vh;
overflow: hidden;
display: table;
text-align: right;
}
.innercont {
/* padding: 15px; */
direction: rtl;
display: table-cell;
vertical-align: middle;
}
.innercont>span:first-child {
font-size: 40px;
padding: 25px;
display: block;
}
.innercont>span:nth-child(2) {
padding: 25px;
font-size: 20px;
display: block;
word-wrap: break-word;
}
.price {
padding: 10px;
font-size: 22px;
}
.price>span {
margin: 0 15px;
}
.price>span:nth-child(2) {
float: left;
}
/*style for the phone number input*/
.PhoneN-section {
position: relative;
height: 50px;
margin: 15px;
}
.PhoneN-section input {
width: 100%;
height: 100%;
border-radius: 10px;
outline: none;
border: 1px solid rgb(230, 230, 230);
font-size: 20px;
padding: 10px 10px 0 10px;
text-align: left;
direction: ltr;
}
input:focus~.PhoneN-label .label-content,
input:valid~.PhoneN-label .label-content {
transform: translateY(-120%);
}
label:not([for="checkbox"]) {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.label-content {
font-size: 20px;
position: absolute;
bottom: 10px;
right: 10px;
transition: all 0.3s ease;
background: white;
}
input:focus {
border: 2px solid rgb(76, 240, 0);
transition-delay: 0.2s;
}
/*style for the submit button*/
.phone-submit {
height: 50px;
margin: 15px 0;
}
.phone-submit button {
width: 100%;
height: 100%;
outline: none;
border: none;
border-radius: 10px;
color: white;
background: rgb(76, 240, 0);
cursor: pointer;
font-size: 20px;
}
/*style for the exclamation message*/
.mark {
float: right;
margin: 0 5px;
font-size: 14px;
font-weight: 600;
padding: 2px 7px;
border-radius: 50%;
border: 1px solid grey;
}
.messaget {
color: grey;
}
#media screen and (max-width: 850px) {
body {
overflow-y: auto;
}
.slidercon {
width: unset;
height: unset;
float: unset;
display: block;
}
.maincon {
display: block;
}
.content {
float: none;
width: unset;
height: 100vh;
display: block;
}
.innercont {
display: block;
}
}
#media screen and (max-width: 550px) {
.imgdiv {
justify-content: unset;
text-align: unset;
}
.imgdiv>img {
margin: 0 20%;
}
}
#media only screen and (max-width: 550px) {
.imgdiv>img {
margin: 0 10%;
}
}
#media only screen and (max-width: 420px) {
.imgdiv>img {
margin: 0 7%;
}
}
#media only screen and (max-width: 400px) {
.imgdiv>img {
margin: 0 5%;
}
}
</style>
<body>
<div class="container">
<div class="innercontainer">
<div class="slidercon">
<div class="maincon">
<div class="imgslider">
<ul>
<li>
<div class="imgdiv">
<img src="https://ewscripps.brightspotcdn.com/dims4/default/55e59a6/2147483647/strip/true/crop/1280x720+0+0/resize/1280x720!/quality/90/?url=https%3A%2F%2Fewscripps.brightspotcdn.com%2F9b%2F1c%2Fd6365aa54b5687a3cb1386a180db%2Fupdate-coronavirus-colorado-live-blog-covid19.png" alt="item">
</div>
</li>
<li>
<div class="youtubevid">
<iframe style="position:absolute;width:100%;height:100%;" src="link" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</li>';
</ul>
</div>
<div class="dotsContainer">
<span class="dots"></span>
<span class="dots"></span>
</div>
</div>
</div>
</div>
<div class="innercontainer">
<div class="content">
<div class="innercont">
<span>'Type'</span>
<span>'Description'</span>
<div class="price">
<span>Price</span>
<span>'1,111' ₪</span>
</div>
<form action="includes/sendPhone.php" method="POST">
<div class="PhoneN-section">
<input type="text" name="PhoneN" autocomplete="off" required />
<input type="hidden" name="itemid" value="id" />
<input type="hidden" name="itemtype" value="TYPE" />
<input type="hidden" name="price" value="1,111" />
<label for="PhoneN" class="PhoneN-label">
<span class="label-content">Phone Number</span>
</label>
<div class="phone-submit">
<button type="submit" name="phone-submit">SEND</button>
</div>
<span>
<span class="mark">!</span>
<span class="messaget">BLa lbla bla bla bla bla bla bla bla blab la</span>
</span>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
Else you can use various bootstrap frameworks to simplify your styling
The reason is max-width: 560px; in .imgslider class. I have added 50vw then it is working fine.
.imgslider {
margin: auto;
max-width: 50vh; /* updated */
max-height: 315px;
overflow: hidden;
position: relative;
}
Try below, It is working...
* {
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
font-family: 'Heebo', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
body {
margin: 0;
padding: 72px 0 0 0;
overflow: hidden;
}
/*style for the slider container*/
.slidercon {
width: 50vw;
height: 100vh;
overflow: hidden;
float: left;
display: table;
}
.maincon {
width: 100%;
display: table-cell;
vertical-align: middle;
}
.imgslider {
margin: auto;
max-width: 50vh; /* updated line */
max-height: 315px;
overflow: hidden;
position: relative;
}
.imgslider > ul {
margin: 0;
padding: 0;
display: flex;
position: relative;
top: 0;
left: 0;
transition: 0.2s;
width: 100%;
}
.imgslider > ul > li {
list-style-type: none;
min-width: 560px;
overflow: hidden;
}
.imgdiv {
width: 100%;
height: 315px;
justify-content: center;
text-align: center;
}
.imgdiv > img {
width: auto;
max-height: 315px;
}
.youtubevid {
display: flex;
display: -webkit-flex;
display: -ms-flex;
}
/*style for the dots*/
.dotsContainer {
text-align: center;
}
.dots {
cursor: pointer;
height: 20px;
width: 20px;
margin: 5px 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.dots:first-child {
background: white;
border: 1px solid grey;;
}
/*content style*/
.content {
float: right;
width: 50vw;
height: 100vh;
overflow: hidden;
display: table;
text-align: right;
}
.innercont {
/* padding: 15px; */
direction: rtl;
display: table-cell;
vertical-align: middle;
}
.innercont > span:first-child {
font-size: 40px;
padding: 25px;
display: block;
}
.innercont > span:nth-child(2) {
padding: 25px;
font-size: 20px;
display: block;
word-wrap: break-word;
}
.price {
padding: 10px;
font-size: 22px;
}
.price > span {
margin: 0 15px;
}
.price > span:nth-child(2) {
float: left;
}
/*style for the phone number input*/
.PhoneN-section {
position: relative;
height: 50px;
margin: 15px;
}
.PhoneN-section input {
width: 100%;
height: 100%;
border-radius: 10px;
outline: none;
border: 1px solid rgb(230, 230, 230);
font-size: 20px;
padding: 10px 10px 0 10px;
text-align: left;
direction: ltr;
}
input:focus ~ .PhoneN-label .label-content,
input:valid ~ .PhoneN-label .label-content {
transform: translateY(-120%);
}
label:not([for="checkbox"]) {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.label-content {
font-size: 20px;
position: absolute;
bottom: 10px;
right: 10px;
transition: all 0.3s ease;
background: white;
}
input:focus {
border: 2px solid rgb(76, 240, 0);
transition-delay: 0.2s;
}
/*style for the submit button*/
.phone-submit {
height: 50px;
margin: 15px 0;
}
.phone-submit button {
width: 100%;
height: 100%;
outline: none;
border: none;
border-radius: 10px;
color: white;
background: rgb(76, 240, 0);
cursor: pointer;
font-size: 20px;
}
/*style for the exclamation message*/
.mark {
float: right;
margin: 0 5px;
font-size: 14px;
font-weight: 600;
padding: 2px 7px;
border-radius: 50%;
border: 1px solid grey;
}
.messaget {
color: grey;
}
#media screen and (max-width: 850px) {
body {
overflow-y: auto;
}
.slidercon {
width: unset;
height: unset;
float: unset;
display: block;
}
.maincon {
display: block;
}
.content {
float: none;
width: unset;
height: 100vh;
display: block;
}
.innercont {
display: block;
}
}
#media screen and (max-width: 550px) {
.imgdiv {
justify-content: unset;
text-align: unset;
}
.imgdiv > img {
margin: 0 20%;
}
}
#media only screen and (max-width: 550px) {
.imgdiv > img {
margin: 0 10%;
}
}
#media only screen and (max-width: 420px) {
.imgdiv > img {
margin: 0 7%;
}
}
#media only screen and (max-width: 400px) {
.imgdiv > img {
margin: 0 5%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Stack Overflow</title>
<link rel="stylesheet" href="./styles.css">
</head>
<html>
<body>
<div class="slidercon">
<div class="maincon">
<div class="imgslider">
<ul>
<li>
<div class="imgdiv">
<img src="img" alt="item">
</div>
</li>
<li>
<div class="youtubevid">
<iframe style="position:absolute;width:100%;height:100%;" src="link" frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
</div>
</li>
</ul>
</div>
<div class="dotsContainer">
<span class="dots"></span>
<span class="dots"></span>
</div>
</div>
</div>
<div class="content">
<div class="innercont">
<span>'Type'</span>
<span>'Description'</span>
<div class="price">
<span>Price</span>
<span>'1,111' ₪</span>
</div>
<form action="includes/sendPhone.php" method="POST">
<div class="PhoneN-section">
<input type="text" name="PhoneN" autocomplete="off" required/>
<input type="hidden" name="itemid" value="id"/>
<input type="hidden" name="itemtype" value="TYPE"/>
<input type="hidden" name="price" value="1,111"/>
<label class="PhoneN-label">
<span class="label-content">Phone Number</span>
</label>
<div class="phone-submit">
<button type="submit" name="phone-submit">SEND</button>
</div>
<span>
<span class="mark">!</span>
<span class="messaget">BLa lbla bla bla bla bla bla bla bla blab la</span>
</span>
</div>
</form>
</div>
</div>
</body>
</html>
</html>
I want to create a header bar and center my title / logo but it's not centered perfectly.
body {
margin: 0;
background: black;
}
.link {
text-decoration: none;
}
#header {
height: 80px;
display: flex;
align-items: center;
background-color: #000000;
}
#headerTitleContainer {
margin: 0 auto;
}
#headerTitle {
color: #97d700;
}
#menuBtnContainer {
display: inline-block;
cursor: pointer;
margin-right: 10px;
}
#media (min-width: 300px) {
#menuBtnContainer {
margin-left: 20px;
}
}
#media (max-width: 299px) {
#menuBtnContainer {
margin-left: 5px;
}
}
.menuIconBar {
width: 35px;
height: 5px;
margin: 6px 0 6px 0;
transition: 0.4s;
background-color: #97d700;
}
<div id="header">
<div id="menuBtnContainer">
<div class="menuIconBar" id="menuIconBar1"></div>
<div class="menuIconBar" id="menuIconBar2"></div>
<div class="menuIconBar" id="menuIconBar3"></div>
</div>
<div id="headerTitleContainer">
<h1><a class="link" id="headerTitle" href="/">MyTitle</a></h1>
</div>
</div>
As you can see MyTitle is not centered correctly. How can I do this? I achieve it when taking out my menu button but obviously I need this button. I just want it to be always in the center of the bar. But it should not overlap the menu button.
That's why I added a margin-right: 10px; to my menu button.
One solution it to make width of button 0 and have overflow:visible on it:
body {
margin: 0;
background: black;
}
.link {
text-decoration: none;
}
#header {
height: 80px;
display: flex;
align-items: center;
background-color: #000000;
}
#headerTitleContainer {
margin: 0 auto;
}
#headerTitle {
color: #97d700;
}
#menuBtnContainer {
display: inline-block;
cursor: pointer;
width: 0;
overflow: visible;
}
#media (min-width: 300px) {
#menuBtnContainer {
margin-left: 20px;
margin-right:-20px;
}
}
#media (max-width: 299px) {
#menuBtnContainer {
margin-left: 5px;
}
}
.menuIconBar {
width: 35px;
height: 5px;
margin: 6px 0 6px 0;
transition: 0.4s;
background-color: #97d700;
}
<div id="header">
<div id="menuBtnContainer">
<div class="menuIconBar" id="menuIconBar1"></div>
<div class="menuIconBar" id="menuIconBar2"></div>
<div class="menuIconBar" id="menuIconBar3"></div>
</div>
<div id="headerTitleContainer">
<h1><a class="link" id="headerTitle" href="/">MyTitle</a></h1>
</div>
</div>
Or simply make the button absolute position without chaging any other property and don't forget to make the parent position:relative (I prefer this one):
body {
margin: 0;
background: black;
}
.link {
text-decoration: none;
}
#header {
height: 80px;
display: flex;
align-items: center;
background-color: #000000;
position:relative;
}
#headerTitleContainer {
margin: 0 auto;
}
#headerTitle {
color: #97d700;
}
#menuBtnContainer {
display: inline-block;
cursor: pointer;
margin-right: 10px;
position: absolute;
}
#media (min-width: 300px) {
#menuBtnContainer {
margin-left: 20px;
margin-right:-20px;
}
}
#media (max-width: 299px) {
#menuBtnContainer {
margin-left: 5px;
}
}
.menuIconBar {
width: 35px;
height: 5px;
margin: 6px 0 6px 0;
transition: 0.4s;
background-color: #97d700;
}
<div id="header">
<div id="menuBtnContainer">
<div class="menuIconBar" id="menuIconBar1"></div>
<div class="menuIconBar" id="menuIconBar2"></div>
<div class="menuIconBar" id="menuIconBar3"></div>
</div>
<div id="headerTitleContainer">
<h1><a class="link" id="headerTitle" href="/">MyTitle</a></h1>
</div>
</div>
Another solution is to add a third hidden element using :after taking the same width as the button so the title get centered :
body {
margin: 0;
background: black;
}
.link {
text-decoration: none;
}
#header {
height: 80px;
display: flex;
align-items: center;
background-color: #000000;
}
#header:after {
content: "";
width: 35px;
margin-left: 10px;
}
#headerTitleContainer {
margin: 0 auto;
}
#headerTitle {
color: #97d700;
}
#menuBtnContainer {
display: inline-block;
cursor: pointer;
margin-right: 10px;
}
#media (min-width: 300px) {
#menuBtnContainer {
margin-left: 20px;
}
#header:after {
margin-right: 20px;
}
}
#media (max-width: 299px) {
#menuBtnContainer {
margin-left: 5px;
}
}
.menuIconBar {
width: 35px;
height: 5px;
margin: 6px 0 6px 0;
transition: 0.4s;
background-color: #97d700;
}
<div id="header">
<div id="menuBtnContainer">
<div class="menuIconBar" id="menuIconBar1"></div>
<div class="menuIconBar" id="menuIconBar2"></div>
<div class="menuIconBar" id="menuIconBar3"></div>
</div>
<div id="headerTitleContainer">
<h1><a class="link" id="headerTitle" href="/">MyTitle</a></h1>
</div>
</div>