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
Related
I have created a dropdown menu. The basic process has been:
I put the dropdown link and submenus inside a div.
Using flexbox I put all the links inline and the submenus in a column.
With the visibility property I make the submenus appear.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.main_container {
width: 500px;
margin: 20px auto;
border: solid 2px green;
display: flex;
height: 400px;
}
div {
width: 110px;
display: flex;
flex-direction: column;
height: 40px;
}
a {
text-decoration: none;
color: white;
width: 90px;
text-align: center;
padding: 10px;
height: 40px;
background-color: red;
}
a {
flex-grow: 1;
}
div a {
width: 110px;
flex-grow: 0;
}
a:hover {
font-weight: bold;
background: blue;
}
.hidden {
visibility: hidden;
}
div:hover .hidden {
visibility: visible;
}
<nav class="main_container">
Enlace1
Enlace2
<div>
Enlace 3
Enlace 3.1
Enlace 3.2
Enlace 3.3
</div>
Enlace 4
</nav>
The key is to reduce the height of the div to 40px, because if you don't, hovering under "Link 3" will still cause the submenu to appear in a weird effect.
Well, when the div is reduced, in height, a value less than the height of the "Link 3" and submenus, curiously the height of these is reduced by 2px as you can see at the bottom of "Link 3".
Can this be avoided?
EDIT:
Changing your .hidden class to use the display property instead of visiblity is also a good idea here. visibility still allows the element to render and take up space on the page, which is why it can still be hovered why not visible. However, using display: none; makes it so the element does not render and cannot take up space on the page or be hovered.
Typically if you want to show/hide elements on a page you should use display: none;. visibility can have its uses, typically if you want there to an empty space/void where an element should be. Most of the time you actually want to use display instead.
Additionally, I added a :hover action to the div CSS so that it sets the height property to auto only when hovered. This avoids any unusual hover effects from the <div> taking up more space.
*{
margin: 0;
padding: 0;
box-sizing:border-box;
}
.main_container{
width:500px;
margin:20px auto;
border:solid 2px green;
display:flex;
height:400px;
}
div{
width:110px;
display:flex;
flex-direction:column;
height: 40px;
}
a{text-decoration:none;
color:white;
width:90px;
text-align:center;
padding:10px;
height:40px;
background-color:red;
}
a{flex-grow:1;}
div a{
width:110px;
flex-grow:0;
}
a:hover{
font-weight: bold;
background:blue;
}
.hidden{
display: none;
}
div:hover .hidden{
display: inline;
}
div:hover { height: auto; }
<nav class="main_container">
Enlace1
Enlace2
<div>
Enlace 3
Enlace 3.1
Enlace 3.2
Enlace 3.3
</div>
Enlace 4
</nav>
inside your css do this to your a element:
a {
text-decoration: none;
color: white;
width: 90px;
text-align: center;
padding: 10px;
background-color: red;
min-height: 40px;
max-height: 40px;
}
add a min-height and max-height and set it to 40px
You can try this. You need to use div {height:100%;}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.main_container {
width: 500px;
margin: 20px auto;
border: solid 2px green;
display: flex;
height: 400px;
}
div {
width: 110px;
display: flex;
flex-direction: column;
height: 100%;
}
a {
text-decoration: none;
color: white;
width: 90px;
text-align: center;
padding: 10px;
height: 40px;
background-color: red;
}
a {
flex-grow: 1;
}
div a {
width: 110px;
flex-grow: 0;
}
a:hover {
font-weight: bold;
background: blue;
}
.hidden {
visibility: hidden;
}
div:hover .hidden {
visibility: visible;
}
<nav class="main_container">
Enlace1
Enlace2
<div>
Enlace 3
Enlace 3.1
Enlace 3.2
Enlace 3.3
</div>
Enlace 4
</nav>
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;
}
I am having trouble with my HTML and CSS.
I have two containers that are directly over top of one another.
I am trying to make it so when the user hovers the top most container, it hides the top one to reveal the one behind it. This is all done through changing the viability on :hover.
However, I am finding that while it works, it often just results in rapid flickering between the two states.
I have no idea why this is happening and can't seem to figure it out. I tried changing the z-index and
position as suggested by other similar posts and couldn't get anything to work.
Code on codepen: https://codepen.io/michaelnicol/pen/jOqYbGo
HTML:
<html>
<head>
</head>
<body>
<main>
<div class="image_container">
<div class="text_div">
<h1>Mona Lisa</h1>
<p>Lorem lipsum dolor sit amat</p>
</div>
</div>
</main>
</body>
</html>
CSS:
/* Formatting Code */
main {
width: 90%;
height: 90%;
min-height: 900px;
border: 1px solid black;
background-color: #efefef;
margin: 5%;
border-radius: 20px;
box-shadow: 2px 2px 5px black;
display: flex;
justify-content: center;
align-items: center;
}
body {
display: flex;
justify-content: center;
background-color: rgb(147, 165, 207);
}
.text_div > h1, .text_div > p {
color: white;
text-shadow: 2px 2px 5px black;
}
/* image hover code */
.image_container {
height: 300px;
width: 400px;
border: 1px solid black;
background-color: rgb(156, 48, 48);
background-image: url("https://i.pinimg.com/474x/c6/90/48/c69048072a6d77dfb0a317db98ef145d.jpg")
}
.text_div {
visibility: visible;
opacity: 0.85;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100%;
width: 100%;
transition: 0.5s ease-in-out;
}
.text_div:hover {
visibility: hidden;
}
Try to replace this:
.text_div:hover {
visibility: hidden;
}
With this:
.image_container:hover .text_div {
opacity: 0;
pointer-events: none;
}
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.
I have a small problem. I am trying to change the width and height of a button but for some reason, it will not let me. The button automatically stays the same width and height as the contained text.
CSS
.flexcontainer {
display: flex;
align-items: center;
overflow: hidden;
}
img[width="500"] {
border: 3px solid #5F5F5F;
border-radius:3px;
float: left;
}
#leftRetail {
display: block;
height:354px;
width: 1308px;
float:right;
text-align: center;
vertical-align: middle;
line-height: 354px;
}
.button {
width: 250px;
height: 200px;
background: #ed2626;
border-radius: 2px;
color: white;
font-weight: bold;
text-decoration:none;
}
HTML
<div class="flexcontainer">
<div>
<img src="anyImage.jpg" width="500" height="350"/>
</div>
<div id="leftRetail">
Retail Menu
</div>
</div>
You need to change your .button to use display: block or inline-block:
.button {
display: block;
width: 250px;
height: 200px;
background: #ed2626;
border-radius: 2px;
color: white;
font-weight: bold;
text-decoration:none;
}
CHANGED ANSWER after copying the original code into a snippet:
I just realized that the whole thing is inside a flex container, which makes all child elements flex items automatically. (BTW: The float parameters have no effect in this case)
So, one method to add width and height to your .button is to give it some padding, as shown below:
.flexcontainer {
display: flex;
align-items: center;
overflow: hidden;
}
img[width="500"] {
border: 3px solid #5F5F5F;
border-radius: 3px;
}
#leftRetail {
height: 354px;
width: 1308px;
text-align: center;
vertical-align: middle;
line-height: 354px;
}
.button {
background: #ed2626;
border-radius: 2px;
color: white;
font-weight: bold;
text-decoration: none;
padding: 8px 12px;
}
<div class="flexcontainer">
<div>
<img src="anyImage.jpg" width="500" height="350" />
</div>
<div id="leftRetail">
Retail Menu
</div>
</div>
You cannot modify the width and height of inline elements, manually.
Add display: block; (or inline-block) to your .button block, and you can observe that the height and width changes are you define it.
Only block elements may have their width and height set specifically.
Your button should now look like:
.button {
width: 250px;
height: 200px;
background: #ed2626;
border-radius: 2px;
color: white;
font-weight: bold;
text-decoration:none;
display: block;
}
Just make it block-level element by adding display:bock to its style. Then you can apply whatever style you want!