I am trying to create a dropdown for my navigation in my mobile view. I am having an issue with the anchors overlapping. I attempted to stack them on top of one another by setting the display to block and adding a margin-bottom.
This has not worked as you can see.
html
<div id="brand">
<h1>brand</h1>
<nav>
<div class="fa fa-plus"></div>
<div class="fa fa-cog">
Edit Profile
Dashboard
</div>
<div class="fa fa-sign-out"></div>
<input type="search" id="main-q" name="q" placeholder="Search" data-value="" value="">
</nav>
</div>
css
nav .fa a {
display: none;
}
nav .fa:hover a {
display: block;
position: absolute;
top: 75px;
color: black;
margin-bottom: 1em;
}
#brand {
border-bottom: 1px solid #B2B2B2;
background: white;
color: darkgrey;
padding: 1em;
}
#brand h1 {
margin-bottom: .5em;
float: left;
}
jsfiddle demonstration
What is the solution?
Everything is fine. The main problem was to setting the position: absolute fora. Simply wrap those anchors a in UL li and then set the position for UL.
CSS:
nav .fa .child { /*modified CSS*/
display: none;
border:1px solid red;
}
nav .fa:hover .child { /*modified CSS*/
display: block;
position: absolute;
top: 75px;
color: black;
margin-bottom: 1em;
}
HTML
<div class="fa fa-cog">
<ul class="child"> <!--class child for dropdown-->
<li>Edit Profile</li>
<li>Dashboard</li>
</ul>
</div>
JSFIDDLE
Related
Hello so recently I've been building my personal website and been having troubles with my mobile view of my website.
The Problem : On a mobile device there is Unwanted White Space On Top Of Page (In nav Area). It basically covers the navbar.
Solutions : I've tried manipulating code, and seeing what could be causing this but no solution. Also used DevTools on google and it seems as if it won't show the top white space but only on the phone?
Nav HTML Code :
<!-- NAVIGATION -->
<nav>
<div class="logo"><img src="src/assets/TWINLOGO.png" style="width: 100px;height: 100px;"></div>
<div class="openMenu"><i class="fa fa-bars" style="color:black;"></i></div>
<ul class="mainMenu">
<!-- Center-aligned links -->
<div class="nav-center">
<div class="navLogo"><img src="src/assets/TWINLOGO.png" style="width: 100px;height: 100px;"></div>
</div>
<!-- Left-aligned links -->
<li>Contact</li>
<li>About</li>
<li>Store</li>
<div class="closeMenu"><i class="fa fa-times"></i></div>
<!-- Right-aligned links -->
<div class="nav-right">
<span class="icons">
<i class="fab fa-youtube"></i>
<i class="fab fa-instagram"></i>
<i class="fab fa-twitter"></i>
<i class="fab fa-discord"></i>
</span>
</div>
</ul>
</nav>
Nav CSS Code :
/* Nav BAR */
nav {
position: relative;
background: rgb(255, 255, 255);
color: #fff;
display: flex;
justify-content: space-between;
height:fit-content;
overflow: hidden;
width:100%;
}
/* Nav Main Menu */
nav .mainMenu {
display:flex;
list-style: none;
}
/* Centered section inside the top navigation */
.nav-center{
float: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/* Right-aligned section inside the top navigation */
.nav-right {
position:absolute;
float: right;
right:-100px;
top:50%;
transform: translate(-50%, -50%);
}
nav .mainMenu li a {
display: inline-block;
padding: 30px;
margin:10px;
text-decoration: none;
color: rgb(0, 0, 0);
font-size: 1.5rem;
font-family:'Courier New', Courier, monospace;
}
nav .mainMenu li a:hover {
color: rgb(0, 110, 255);
}
nav .openMenu {
font-size: 2rem;
margin: 20px;
display: none;
cursor: pointer;
}
nav .mainMenu .closeMenu , .icons i {
font-size: 2rem;
display: none;
cursor: pointer;
}
nav .logo {
margin: 6px;
font-size: 25px;
cursor: pointer;
display:none;
}
.icons i {
display: inline-block;
padding: 12px;
color:black;
}
Website - https://github.com/ConstantineLinardakis/TwinPlayzOfficial https://constantinelinardakis.github.io/TwinPlayzOfficial/index.html
Any idea why this is happening? Could It be because of the Nav?
I don't think it has to do with your body margin because the margin is set to 0 when I am inspecting your website. With that being said, perhaps your problem is due to using height: fit-content; I would suggest using a fixed height.
nav {
position: relative;
background: rgb(255, 255, 255);
color: #fff;
display: flex;
justify-content: space-between;
height: 33.5vh; /* Change applied */
overflow: hidden;
width: 100%;
}
The brower's style sheet setting a margin to your <body> element by default is the culprit.
CSS fix removing browser styles default <body> margin (e.g.: 8px in Firefox):
body {
margin: 0;
}
This question already has answers here:
Any way to declare a size/partial border to a box?
(6 answers)
Closed 4 years ago.
Looks like now
Want it to look like
I have provided a picture of what I currently have and what I need need it to look like (ignore the images that aren't present in first image. Is there anyway I can make the border-right only be say 75% of height? I also was thinking about making a container inside the main container and then putting the border on the smaller inner container.
Thanks in advance for all the help/advice on this very frustrating issue!!!
<div class="col-sm-6 col-md-6 col-lg-6 header-right-menu-wrapper">
<ul class="list-inline top-element pull-right header-right-menu-list">
<li class="header-right-menu-list-item">
<a href="#" id="popuptest" class="header-right-list-text">
<span class="img-icon">
<span class="svg-icon svg-header svg-icon-Account-icon-white"></span>
</span> 'SIGN IN/UP'
</a>
<div class="container authenticated-user-profile head">
<sly data-sly-include="profile.html"></sly>
</div>
</li>
<li class="header-right-menu-list-item">
<a href="#" class="header-right-list-text">
<span class="img-icon">
<span class="svg-icon svg-icon-list-header-16px"></span>
</span> 'LIST'
</a>
</li>
<li class="header-right-menu-list-item">
<a href="#" class="header-right-list-text">
<span class="img-icon">
<span class="svg-icon svg-icon-Cart"></span>
</span>'ITEMS'
</a>
</li>
</ul>
</div>
.parent {
padding: 0 10px;
display: inline-block;
background-color: #f80000;
color: #fff;
}
li {
padding: 8px 0;
list-style: none;
display: inline-block;
}
li+li a {
border-left: 1px solid #fff;
}
a {
text-decoration: none;
display: block;
padding: 8px 16px;
}
i {
font-size:16px;
margin-right: 5px;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<ul class="parent">
<li><a><i class="fa fa-user"></i>SIGN IN/UP</a></li>
<li><a><i class="fa fa-list"></i>LIST</a></li>
<li><a><i class="fa fa-shopping-cart"></i>ITEMS</a></li>
</ul>
You can add the border with :after pseudo selector. Try this code.
.header-right-menu-list-item a {
display: block;
position: relative;
}
.header-right-menu-list-item a:after {
content: '';
position: absolute;
right: 0;
height: 75%;
top: 12.5%;
width: 1px;
background-color: #fff;
}
you can use pseudo elements for this
.outer{
display: inline-flex;
background-color: maroon;
}
.item{
color: white;
padding: 10px 30px;
position: relative;
}
.item:not(:last-child):after{
content: '';
position: absolute;
height: 60%;
width: 2px;
background-color: white;
top: 20%;
right: 2px;
}
<div class="outer">
<div class="item">item01</div>
<div class="item">item02</div>
<div class="item">item03</div>
</div>
You can define css for <ul class="list-inline top-element pull-right header-right-menu-list"> something like this :
header-right-menu-list {
background-color: red;
color: white;
padding: 3px;
}
and than for <li class="header-right-menu-list-item">
header-right-menu-list-item {
border-right: 1px solid black;
}
You just want to add the border on the <a> and give the lia bit of padding.
This way the border is the size of the inside element
ul {
background-color: red;
color: white;
display: inline-block;
padding: 0 10px;
}
li {
list-style: none;
display: inline-block;
padding: 10px 0;
}
a{
display: block;
padding: 10px 15px;
}
li + li a {
border-left: 1px solid white;
}
<ul>
<li><a>FREED</a></li>
<li><a>FROM</a></li>
<li><a>DESIRE</a></li>
</ul>
I have facing some problems with my div container. I want to set standard height on my container. If content inside of the div is large scroll bar should show on the side. Here is example of my CODE:
//In this section I have Navigation bar and HTML included.
<section class="settingsBox">
<nav class="xNavigationSetting">
Menu |
</nav>
<div id="htmlSetting">
<cfinclude template="Includes/hmSettings.html">
</div>
</section>
<div id="settingMain" class="settingsBox">
<div id="settingTesting">
<fieldset>
<legend>Testing</legend>
<ul>
<li>
<span id="location">Test Location</span>
</li>
<li>
<span id="reason">Reason</span>
</li>
<li>
<span id="results">Results</span>
</li>
</ul>
</fieldset>
</div>
<div id="settingEquipment">
<fieldset>
<legend>Equipment</legend>
<ul>
<li>
<span id="type">Type</span>
</li>
</ul>
</fieldset>
</div>
</div>
<div id="settingTbl">
<div id="containerMaster"></div>
</div>
Here is my CSS:
div.settingsBox {
height: 400px;
overflow-y: scroll;
}
div.settingsBox fieldset {
font-weight: bold;
border: 2px solid #000099;
margin: 10px;
}
div.settingsBox ul li span:hover {
text-decoration: underline;
color: red;
cursor: pointer;
}
div.settingsBox ul {
list-style-image: url('../Images/edit.png');
}
nav.xNavigationSetting {
width: 100%;
margin-left: 0;
margin-right: 0;
padding-top: 2px;
margin-bottom: 5px;
background-color: #c8e2db;
float: left;
border-bottom: 2px solid #000099;
height: 18px;
}
nav.xNavigationSetting a {
color: black;
text-decoration: none;
cursor: pointer;
font-weight: bold;
padding-left: 5px;
padding-right: 5px;
}
My settingsBox has height of 400px and overflow-y set to scroll. For some reason all content disappears when I apply this CSS. If anyone knows why or what is wrong in my code structure please let me know. Thank you.
You need to clear float on div.settingsBox. It's currently floated outside of the viewport.
div.settingsBox {
...
clear: both;
}
i would like you to help me get this working:
html code:
<div class="mainMenu">
<ul>
<li>Home</li>
<li>Reviews <i class="fa fa-sort-desc"></i></li>
<li>News</li>
<li>Videos <i class="fa fa-sort-desc"></i></li>
<li>Forums</li>
</ul>
</div>
css code:
.mainMenu {
overflow: hidden;
float: right;
}
.mainMenu ul {
overflow: hidden;
list-style: none;
padding: 0;
margin: 0;
}
.mainMenu li {
float: left;
}
.mainMenu li a {
line-height: 65px;
padding: 0 10px;
margin-left: 10px;
}
here's a link to a jsfiddle:
http://jsfiddle.net/shock/r5rd3v86/
If you set the vertical alignment of the icon, you can apply a minus margin to it:
.fa {
vertical-align: middle;
margin-top: -10px;
}
You can also just tweak the positioning using a transform.
For example, with the following HTML:
<span class="fa fa-sort-asc"></span>
<span class="fa fa-sort-desc"></span>
Add the following to your stylesheet:
.fa-sort-asc {
transform: translateY(3px);
}
.fa-sort-desc {
transform: translateY(-2px);
}
You can get precise control of the positioning by setting position: relative to the i element that contains the font-awesome icon. Adjust the position using the top offset with a positive or negative value.
.mainMenu {
overflow: hidden;
float: left;
}
.mainMenu ul {
overflow: hidden;
list-style: none;
padding: 0;
margin: 0;
border: 1px dotted gray;
}
.mainMenu li {
float: left;
border: 1px dotted gray;
}
.mainMenu li a {
line-height: 65px;
padding: 0 10px;
margin-left: 10px;
text-decoration: none;
border: 1px dashed gray;
}
.mainMenu li a i {
position: relative;
top: -2px;
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="mainMenu">
<ul>
<li>Home</li>
<li>Reviews <i class="fa fa-sort-desc"></i></li>
<li>News</li>
<li>Videos <i class="fa fa-sort-desc"></i></li>
<li>Forums</li>
</ul>
</div>
I cant comment so:
Why you using line-height: 65px;? In jsfidle its like margin-top. try to use line-height equal to font-size and use vertical-align:middle
How do I highlight my active tab in navigation? I have been trying it different ways for hours but none is working right. I know there are some ways to do it like using active, selected and etc but I just can't get it right. Please help.
Here's the code in my css file, with some settings on the tabs control.
/* Tab Control */
#tabs ul
{
padding: 0px;
margin: 0px;
margin-bottom: 10px;
margin-left: 270px;
list-style-type: none;
}
#tabs ul li
{
display: outline-block;
clear: none;
float: left;
height: 24px;
}
#tabs ul li a {
position: relative;
margin-top: 16px;
display: block;
width: 130px;
color: #6d6e71;
text-decoration: none;
}
#tabs ul li a:hover {
text-decoration: underline;
color: #eb8c00;
}
#tabs #Content_Area
{
margin-left: 270px;
padding: 0 15px;
clear:both;
overflow:hidden;
line-height:19px;
position: relative;
top: 20px;
z-index: 5;
height: 150px;
overflow: hidden;
}
And my html code:
<div id="tabs">
<ul>
<li id="li_tab1" onclick="tab('tab1')"><a>Tab 1</a></li>
<li id="li_tab2" onclick="tab('tab2')"><a>Tab 2</a></li>
</ul>
<div id="Content_Area">
<div id="tab1">
<p>This is the text for tab 1.</p>
</div>
<div id="tab2" style="display: none;">
<p>This is the text for tab 2.</p>
</div>
</div>
</div>
if you are not refreshing page on anchors click then you could highlight tabs using jquery
here is code:
$('ul li').click(function(e){
e.preventDefault();
$(this).children().css('color','red');
$(this).siblings().children().css('color','black');
});
and jsFiddle example: http://jsfiddle.net/338qH/