How to determine width on responsive scroll menu - html

I'm using this tutorial to build scrolling menu once the screen size is smaller.
I also want to add border with width element, but once I define width the scrolling: auto; element is override. My target is creating border with width and still keep the scrolling auto element working once the screen is minimized.
Codepen with width defined
Codepen with undefined width
.scrollmenu-container{
margin: 0 auto;
width: 500px;
border-bottom: 2px solid #eee;
}
div.scrollmenu {
text-align: center;
margin: 0 auto;
overflow: auto;
white-space: nowrap;
border-bottom: 2px solid #eee;
}
div.scrollmenu a {
display: inline-block;
color: grey;
text-align: center;
padding: 14px;
text-decoration: none;
}
div.scrollmenu a:hover {
color: #24d175;
}
<div class="scrollmenu-container">
<div class="scrollmenu">
<a>הכל</a>
<a>USB</a>
<a>מטענים</a>
<a>מתאמים</a>
<a>גדאג'טים למחשב'</a>
</div>
</div>
How can I define width for border without override scrolling auto element?

Give a specific width to .scrollmenu class and use overflow-X: scroll; in media query for small devices. I have added media query for mobile devices.
Hope this Helps.
.scrollmenu-container{
margin: 0 auto;
width: 500px;
border-bottom: 2px solid #eee;
}
div.scrollmenu {
text-align: center;
margin: 0 auto;
white-space: nowrap;
border-bottom: 2px solid #eee;
}
div.scrollmenu a {
display: inline-block;
color: grey;
text-align: center;
padding: 14px;
text-decoration: none;
}
div.scrollmenu a:hover {
color: #24d175;
}
#media (max-width:767px){
div.scrollmenu{max-width:300px; overflow-X: scroll;}
}
<div class="scrollmenu-container">
<div class="scrollmenu">
<a>הכל</a>
<a>USB</a>
<a>מטענים</a>
<a>מתאמים</a>
<a>גדאג'טים למחשב'</a>
</div>
</div>

.scrollmenu-container{
margin: 0 auto;
width: 500px;
border-bottom: 2px solid #eee;
}
div.scrollmenu {
text-align: center;
margin: 0 auto;
overflow: auto;
white-space: nowrap;
border-bottom: 2px solid #eee;
}
div.scrollmenu a {
display: inline-block;
color: grey;
text-align: center;
padding: 14px;
text-decoration: none;
}
div.scrollmenu a:hover {
color: #24d175;
}
.menu-wrapper{
width:100%;
overflow:auto;
}
<div class="menu-wrapper">
<div class="scrollmenu-container">
<div class="scrollmenu">
<a>הכל</a>
<a>USB</a>
<a>מטענים</a>
<a>מתאמים</a>
<a>גדאג'טים למחשב'</a>
</div>
</div>
</div>
May be those code snippets help your question. I put a wrapper around menu and set a style for it. It scrolls when page size gets smaller.

Related

Working on my portfolio/CV site, but the menu isn't hovering like I want it to

I'm fairly new to coding and new to this website c:
I've been following the SheCodes courses and I'm currently doing the Responsive one because I want to move my coding career in that direction.
Anyways, I'm working on my own website to display my Illustration works and whatnot https://mariafloscher.netlify.app/ but the menu isn't hovering the way I want it, I want the whole section to look white and not only the area surrounding the words.
Here's the GitHub repository https://github.com/mariafloscher/cv-and-portfolio
Here's the HTML portion of the menu:
<div id="menu">
<div>homepage</div>
<div>about</div>
<div>work experience</div>
<div>works</div>
<div>commissions' & hiring info</div>
<div>contact</div>
</div>
And here's the CSS
#menu {
display: flex;
justify-content:space-evenly;
color: #f8f8f8;
background-color: #202020;
padding: 5px 0px 5px 0px;
height: fit-content;
}
.menu-item {
color: #f8f8f8;
background-color: #202020;
text-align: center;
display: inline-block;
text-decoration: none;
width: -moz-fit-content;
}
.menu-item:hover {
background-color: #f8f8f8;
color: #202020;
}
.menu-link {
color: #f8f8f8;
background-color: #202020;
text-align: center;
text-decoration: none;
}
.menu-link:hover {
background-color: #f8f8f8;
color: #202020;
text-decoration: none;
max-width: max-content;
}
Thanks in advance <3 Have a great day and a good start of the week :D!!
Move menu-item from a to div and in css
On menu item add flex: 1. That will make sure that all items are stretched to max available space
Add .menu-item a and .menu-item:hover a to handle menu items properly
Side note:
You can add column-gap: 10px to #menu or padding: 0 5px on .menu-item in order add more space between elements. Use both and you will see the difference.
Here is full example
#menu {
display: flex;
justify-content: space-evenly;
color: #f8f8f8;
background-color: #202020;
height: fit-content;
}
.menu-item {
flex: 1;
background-color: #202020;
padding: 5px;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.menu-item a {
color: #f8f8f8;
display: inline-block;
text-decoration: none;
}
.menu-item:hover {
background-color: #f8f8f8;
}
.menu-item:hover a {
color: #202020;
}
<div id="menu">
<div class="menu-item">homepage</div>
<div class="menu-item">about</div>
<div class="menu-item">work experience</div>
<div class="menu-item">works</div>
<div class="menu-item">commissions' & hiring info</div>
<div class="menu-item">contact</div>
</div>
First of all I think you don't need the <div> tag around your <a> tags.
<div id="menu">
homepage
about
work experience
works
commissions' & hiring info
contact
</div>
If you want to see hover animation over the whole menu-item, you have to remove padding form #menu and add it instead to .menu-item. Also use flex: 1 1 auto; if you using display: flex; for #menu if you.
#menu {
display: flex;
justify-content:space-evenly;
color: #f8f8f8;
background-color: #202020;
height: fit-content;
}
.menu-item {
flex: 1 1 auto;
padding: 5px 0;
color: #f8f8f8;
background-color: #202020;
text-align: center;
display: inline-block;
text-decoration: none;
width: -moz-fit-content;
}
.menu-item:hover {
background-color: #f8f8f8;
color: #202020;
}
.menu-link {
color: #f8f8f8;
background-color: #202020;
text-align: center;
text-decoration: none;
}
.menu-link:hover {
background-color: #f8f8f8;
color: #202020;
text-decoration: none;
max-width: max-content;
}

How to make sure that elements in div shouldn't cross the div horizontally?

We are trying to create a chatbot application. The input where user enters the text and 'send' button are inside a div. The div width is 100%. This is working good in the laptop and on all the mobiles except Iphone14 where the send button is getting cutoff. Below is the code.
.chat-container {
background: #fff;
height: 100%;
overflow: hidden;
padding: 0;
border-right: 1px solid #d8dada;
border-left: 1px solid #d8dada;
}
.chat-container>div:last-of-type {
position: absolute;
bottom: 0;
width: 100%;
display: flex;
align-items: center;
padding-right: 10px;
}
body>div>div>div:nth-child(2)>span {
background: #dadada;
padding: 10px;
font-size: 21px;
border-radius: 50%;
}
body>div>div>div.message-data-right.macro {
margin: auto;
margin-left: 1%;
}
.chat-header {
background-color: #ffffff;
height: 3.5rem;
line-height: 3.5rem;
color: #000000;
border-bottom: 1px solid #000000;
position: relative;
}
.chat-header-content {
align-content: center;
padding-top: 10px;
padding-bottom: 10px;
}
.header-img {
height: 24px;
width: 106px;
transform: scale(0.85);
vertical-align: middle;
content: url('./../images/vz_logo.svg');
}
.gray-button {
background-color: #5b5b5b;
border: none;
color: white;
padding: 10px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 15px;
font-family: Roboto-Medium;
border-radius: 4px;
}
.chat-ul {
width: 100%;
list-style-type: none;
padding: 18px 18px 3px 18px;
position: absolute;
bottom: 62px;
display: flex;
flex-direction: column;
top: 3.5rem;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #909296 #dee0e2;
background-color: #f6f6f6;
margin-bottom: 0%;
border-bottom: 1px solid #c1c1c1;
}
.entered-text {
border-width: 1px;
border-radius: 5px;
padding: 10px;
background: #f6f6f6;
width: 100%;
border-color: #c1c1c1;
}
.text {
width: 100%;
display: flex;
flex-direction: column;
}
.text>p:first-of-type {
width: 100%;
margin-top: 0;
margin-bottom: auto;
line-height: 13px;
font-size: 13px;
}
.text>p {
width: 100%;
margin-top: 0;
margin-bottom: auto;
line-height: 13px;
font-size: 13px;
}
.text>p:last-of-type {
width: 100%;
text-align: right;
margin-bottom: -2px;
margin-top: auto;
}
.text-right {
float: right;
font-family: Arial;
position: relative;
}
.send-message {
width: 100%;
border-radius: 0px;
padding: 10px;
display: flex;
}
input:focus {
outline: none;
}
button,
button:focus,
button:active {
outline: none;
}
<div class="chat-container">
<header class="chat-header">
<img class="header-img" />
<button type="button" class="icon-close" onClick="closeChatWindow()"></button>
</header>
<ul class="chat-ul"></ul>
<div>
<div class="send-message">
<div class="text text-right">
<input class="entered-text" />
</div>
</div>
<button id="send" class="gray-button" type="button" onClick="onMessageSend()"> Send </button>
</div>
</div>
Our testing team raised a bug saying that send button gets cutoff on IPhone14. I am not sure how to reproduce the issue as I don't have Iphone14. I have Android phone on which code is working fine. On Pc also, I tested on different browsers all are working fine. I used toggle device toolbar under developer tools to check how it looks like for different devices and used responsive to change width and height. I am not able to reproduce the issue. Below is the image where it got reproduced on Iphone14.
At the end of the image 'Send' grey color button is cutoff. Can any one please let me know how to resolve the issue.
You don't need an iPhone to see this. It's apparent in Chrome for me. Use the emulator in the dev tools if you like.
Remove the float (.text-right) from the layout
Take the 100% width off the input and .send-message
Move the flex class up a level to contain both the input and the button
I've also added some left margin to the button.
I've fixed a great many such situations in my career, and more often than not the solution involves removing unnecessary styling to simplify. You might work though your entire layout and do so.
.gray-button {
background-color: #5b5b5b;
border: none;
color: white;
padding: 10px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 15px;
font-family: Roboto-Medium;
border-radius: 4px;
margin-left: 10px;
}
.entered-text {
border-width: 1px;
border-radius: 5px;
padding: 10px;
background: #f6f6f6;
border-color: #c1c1c1;
}
.text {
width: 100%;
display: flex;
flex-direction: column;
}
.send-message {
border-radius: 0px;
padding: 10px;
display: flex;
}
input:focus {
outline: none;
}
button,
button:focus,
button:active {
outline: none;
}
<div class="chat-container">
<div class="send-message">
<div class="text">
<input class="entered-text" />
</div>
<button id="send" class="gray-button" type="button" onClick="onMessageSend()"> Send </button>
</div>
</div>
The most straightforward way to solve this is to is use the CSS calc() function to give input.entered-text a flexible width which will always accommodate the width of the <button>:
e.g. If you give button#send a fixed width (width: 100px), then you can give input.entered-text a width that can accommodate that fixed width (width: calc(100% - 100px))
Example:
#send {
display: inline-block;
width: 100px;
margin-left: 12px;
box-sizing: border-box;
}
.entered-text {
display: inline-block;
width: calc(100% - 12px - 100px);
box-sizing: border-box;
}
Im no expert but should you put a <br> in the div
edit:
line breaks are usually unnecessary so I would say only use this temporary until you find the solution

Active tab border bottom under the div instead in the div

I have made a tab wrapper with 2 tabs. Under the tabs I have a div with content.
This is my code:
.tab-wrapper {
width: auto;
padding-left: 17px;
background-color: aqua;
white-space: nowrap;
display: table-cell;
}
.content {
background-color: aqua;
}
.role-tab {
cursor: pointer;
display: inline-block;
height: 50px;
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
vertical-align: middle;
margin-right: 19px;
}
.role-tab>p {
display: table-cell;
height: 50px;
overflow: visible;
vertical-align: middle;
width: 100%;
}
.role-tab-active {
border-bottom: 3px #108DE7 solid;
font-weight: bold;
}
<div class="tab-wrapper">
<div class="role-tab role-tab-active">
<p>Role tab 1</p>
</div>
<div class="role-tab">
<p>Role tab 2</p>
</div>
</div>
<div class="content">
<p>Content</p>
</div>
The styling and everything are working good. Now I want to add some padding-top so the border-bottom will go under the div. This is a screenshot what I want:
I want that the border-bottom goes under the div instead of in the div.
I have tried margin-top, padding-top and top, but it didn't work
How can I achieve when the tab is active that the border-bottom goes under the div instead inside it?
just set the margin-bttom: -3px; for the active class and its done :
.role-tab-active {
margin-bottom:-3px;
border-bottom: 3px #108DE7 solid;
font-weight: bold;
}
see below snippet :
.tab-wrapper {
width: auto;
padding-left: 17px;
background-color: aqua;
white-space: nowrap;
display: table-cell;
}
.content{
background-color: aqua;
}
.role-tab {
cursor: pointer;
display: inline-block;
height: 50px;
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
vertical-align: middle;
margin-right: 19px;
margin-bottom:-3px;
}
.role-tab > p {
display: table-cell;
height: 50px;
overflow: visible;
vertical-align: middle;
width: 100%;
}
.role-tab-active {
margin-bottom:-3px;
border-bottom: 3px #108DE7 solid;
font-weight: bold;
}
<div class="tab-wrapper">
<div class="role-tab role-tab-active">
<p>Role tab 1</p>
</div>
<div class="role-tab">
<p>Role tab 2</p>
</div>
</div>
<div class="content">
<p>Content</p>
</div>
You can't move borders via padding and margin. It's not an element but part of the element.
Give the .tab-wrapper a static height instead of default auto. Whatever the size of your border, the containing div will adjust to it instead, so we give it a static height to allow overflow. And then make it display:flex.
.tab-wrapper {
width: auto;
padding-left: 17px;
background-color: aqua;
white-space: nowrap;
display: flex;
height: 50px;
}
You can see that both the parent and tab items are of 50px height, but that's not really the case when rendered. box-sizing: content-box being the default css property, your official active role tab height is 53px, thus, overflowing the div by 3px and giving the border an "under the div" effect
Fiddle: https://jsfiddle.net/c5u3wzv2/5/

CSS - overflow: hidden to not cover dropdown

I have the following CSS and HTML:
body { background-color: #c0c0c0; }
.title-bar, { background-color: #999; color: white; float: left; overflow: hidden; }
.title-bar {
border-bottom: 1px solid white;
height: 128px;
width: 100%;
}
.logo, .user-info { box-sizing: content-box; height: 100%; width: 128px; }
.logo{
align-items: center;
background-color: #369;
border-right: 1px solid white;
display: flex;
float: left;
font-size: 2em;
font-kerning: none;
justify-content: center;
}
.user-info {
align-items: center;
border-left: 1px solid white;
display: flex;
float: right;
justify-content: space-between;
flex-flow: column nowrap;
}
.user-info .circle {
border: 2px solid #369;
border-radius: 50%;
display: inline-block;
flex: 0 0 auto;
height: 32px;
margin: 8px 8px;
overflow: hidden;
transition: border 0.15s ease-out;
width: 32px;
}
.user-info .circle:hover { border-width: 4px; }
.user-info .container {
border-top: 1px solid white;
display: flex;
justify-content: center;
margin-top: 6px;width: 100%;
}
.hor-nav { background-color: #404040; }
.option { display: inline-block; position: relative; }
.hor-nav .option:hover {background-color: #369; }
.option a {
color: white;
display: inline-block;
font-size: 1em;
padding: 14px;
text-align: center;
transition: background-color 0.15s ease-out;
}
.option .dropdown { display: none; position: absolute; }
.option:hover .dropdown{ display: block; }
.dropdown a {
display: block;
text-align: left;
width: 100%;
}
<div class="title-bar">
<a class="logo" href="#">
</a>
<div class="user-info">
<span>User name</span>
<div class="container">
</div>
</div>
<div class="hor-nav">
<div class="option">
OPTION 1
<div class="dropdown">
ITEM 1
</div>
</div>
</div>
</div>
as you can see, the hor-nav bar's color spills onto the user-info area.
I have researched this and found that if I set overflow-x: hidden; it will not do this (see this article).
I have tried that and it is true - the nav bar does not spill into the user-info but, when you hover over one of the nav bar options, the dropdown does not come down but instead the vert-nav gives you a scroll bar (see this jsfiddle).
Additionally, if you do overflow-y: hidden; there is no scroll bar at all.
I am trying to get it so that the background-color of the hor-nav does not spill into other div's, but also allows the dropdown to be activated and work
thank you.
The easiest way to to this with least code change is to just give the user-info area a background color. Since the hor-nav section is lower on the z-index this will give the visual affect you want although the bar will still be under the user-info section it won't appear to be and the drop down will funtion as it does now.
Per your inquiry, you could do this another way by using percentage based widths for all 3 elements so they don't overlap eachother. Please see this fiddle for code change (note I change the markup order slightly, widths, and added box sizing css property)
The way I see it, you have 3 options
You can try adding margin-left/right to the hor-nav.
.hor-nav {
margin: auto 128px;
}
Another option is to set a certain width to the .hor-nav. Or practically cut the width of it.
.hor-nav {
width: calc(100% - 128px);
}
And third, is to add a background color to the .user-info

How can I make these buttons stack on top of each other centered after a window-width change?

I have a container that usually has a width of 400px. When the screen gets smaller, its width is reduced to 300px. These two values are static and don't change.
I have 3 buttons within this container. At the wider width, I'd like to have 2 side by side and the 3rd one on the line below. All of them are centered.
When the container is compressed, I'd like to have all the buttons stack on top of each other centered.
I can get it at the wide width but can't get it at the narrow width.
HTML:
<div id="varied-width">
<div class="pg-sp2 prompt-gate">Did you find what you were looking for?
<div class="pg-3-buttons">
<button class="prompt-gate-button" onclick="PromptGate_sp2(1)">Yes</button>
<button class="prompt-gate-button" onclick="PromptGate_sp2(0)">No, you suck</button>
</div>
<button class="prompt-gate-button" onclick="PromptGate_sp2(2)">No, I need help.</button>
</div>
</div>
CSS:
body {
width: 400px;
}
.prompt-gate {
margin-top: 25px;
margin-bottom: 15px;
background-color: #fefab1;
border: 1px solid #ffd532;
padding: 10px;
text-align: center;
}
.prompt-gate-button {
background-color: #0E80B4;
color: white;
font-size: 12px;
height: 30px;
width: 72px;
border: none;
margin: 15px 25px;
outline: none;
font-style: normal;
cursor: pointer;
}
.pg-3-buttons {
display: inline-block;
margin-top: 10px;
}
.pg-3-buttons .prompt-gate-button {
float: left;
}
.pg-sp2 button {
margin: 5px 15px;
width: 120px;
padding: 10px 0px;
}
.pg-sp2 > button {
}
.small-width {
width: 300px;
}
Fiddle: http://jsfiddle.net/je821vz9/10/
Used flex layout instead: http://jsfiddle.net/je821vz9/7/
Added this to .prompt-gate style and then cleaned up some of the conflicting HTML and CSS.
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
You could use a media query and have the viewport size decided on how to display the elements.
I added the following css to your body:
body {
max-width:400px;
min-width:300px;
}
We can then add a media query to adjust how the items are laid out:
#media (max-width: 300px) {
div.pg-3-buttons .prompt-gate-button {
display:block;
float:none;
}
}
See an updated version of your example and scale down the width of your browser to see the items pop in to place at 300px.
Somehow figured it out... removed floats and moved around the button HTML so that they were all in the same container.
http://jsfiddle.net/je821vz9/19/
<div id="varied-width">
<div class="pg-sp2 prompt-gate">Did you find what you were looking for?
<div class="pg-3-buttons">
<button class="prompt-gate-button" onclick="PromptGate_sp2(1)">Yes</button>
<button class="prompt-gate-button" onclick="PromptGate_sp2(0)">No, you suck</button>
<button class="prompt-gate-button" onclick="PromptGate_sp2(2)">No, I need help.</button>
</div>
</div>
</div>
<style>
body {
width: 400px;
}
.prompt-gate {
margin-top: 25px;
margin-bottom: 15px;
background-color: #fefab1;
border: 1px solid #ffd532;
padding: 10px;
text-align: center;
}
.prompt-gate-button {
background-color: #0E80B4;
color: white;
font-size: 12px;
height: 30px;
width: 72px;
border: none;
margin: 15px 25px;
outline: none;
font-style: normal;
cursor: pointer;
}
.pg-3-buttons {
margin-top: 10px;
}
.pg-sp2 button {
margin: 5px 15px;
width: 120px;
padding: 10px 0px;
}
</style>