Newb here. I am building a site, and on this site I am displaying overlapping images. Therefore, I am using the z-index on hover so that the behind image comes forward when hovered over. However, I am also using bootstrap and the img-responsive tag and when I hover, the image flickers and then disappears. How can I fix this? Is it possible to handle this in only HTML/CSS, no Java?
#container1 {
position: absolute;
top: 25%;
left: 35%;
}
#container1 img:hover {
z-index: 3;
position: absolute;
}
#container2 {
position: absolute;
top: 30%;
left: 25%;
}
#container2 img:hover {
z-index: 2;
position: absolute;
}
#container3 {
position: absolute;
top: 45%;
left: 40%;
}
#container3 img:hover {
z-index: 1;
position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Lato:100,100italic,300,300italic,500,500italic,700,700italic, 800">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Philesq</a>
</div>
<div class="collapse navbar-collapse" id="main-navbar">
<ul class="nav navbar-nav navbar-right">
<li>works
</li>
<li>about
</li>
<li>contact
</li>
</ul>
</div>
</div>
</nav>
<div id="container">
<div id="container1">
<img src="http://placehold.it/300x300?text=1" class="img-responsive">
</div>
<div id="container2">
<img src="http://placehold.it/300x300?text=2" class="img-responsive">
</div>
<div id="container3">
<img src="http://placehold.it/300x300?text=3" class="img-responsive">
</div>
<div>
I there.
The reason why the images flickers is because you are setting the images to be position absolute on hover and it has a static position by default.
If you set alle the images to be position relative from the beginning, and also removes the position attribute on hover, it will work. You do not need position absolute on the images because you have it on the parent container. (unless you are trying to do more I don't know of)
Hope this helps :)
Se working example here
#container1 img, #container2 img, #container3 img{
position: relative; /* Added this */
border: 1px solid red;
}
#container1 {
position: absolute;
top: 25%;
left: 35%;
}
#container1 img:hover {
z-index: 3;
/* Removed: position: absolute; */
}
#container2 {
position: absolute;
top: 30%;
left: 25%;
}
#container2 img:hover {
z-index: 2;
}
#container3 {
position: absolute;
top: 45%;
left: 40%;
}
#container3 img:hover {
z-index: 1;
}
Related
I'm developing a website in Blazor with Bootstrap version 5.1. So I set an image within that navbar. Now I want to align the other items of the navbar just before and after the image in the center. I tried using the Bootstrap 5.0 ms-auto and me-auto to a div and put the nav items in it, but it only aligned the items to the right or left corner of the navbar.
Here is the code of the website:
#page "/"
<style>
.navbar {
position: relative;
padding-top: 0;
opacity: 80%
}
.navbar-brand {
position: absolute;
left: 50%;
transform: translateX(-50%);
display: block;
}
.img-responsive {
height: auto;
width: auto;
max-height: 156px;
max-width: 250px;
top: 109px;
}
.circle
{
width: 249px;
height: 285px;
border-radius:250px;
font-size:50px;
line-height:500px;
text-align:center;
background:#000
}
body {
background: url(assets/hack2.jpg) no-repeat center center fixed;
background-size: cover;
}
</style>
<div class=bodyContainer>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<div class="circle bg-light navbar-brand">
<a href="#" class="navbar-brand">
<img class="img-responsive navbar-brand" src="assets/logo.png" alt="logo">
</a>
</div>
<button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<div class="navbar-nav">
Home
Über uns
Aktuelles
Genossenschaft
Nochagfrogt
Kontakt
</div>
<div class="navbar-nav ms-auto">
Login
</div>
</div>
</div>
</nav>
</div>
If it helps (because I created a container class for the body):
.bodyContainer {
height: calc(100vh - 60px);
}
I made your .navbar-nav a font-color black just so I could see it better, and added white-space: nowrap; on your navbar-nav class so your words don't break when resizing. I am not sure if I properly understood what you wanted your end result to be, but I think I got the gist of it.
For this to work with the ease of customization in the future, I suggest splitting each side into two separate divs, as I did below. .left containing the left side nav components, and .right containing the right components. I put a flex-display on your two new divs dividing the components, and spaced them out using gap. Then I nested them in a parent nav element which I called same-line for demonstration purposes.
First, add a flex-display then you can add justify-content: space-around; on your parent nav that allows for the two sides to space evenly to both the left and right sides respectfully. If your logo is truly the size of the .circle class, I added a sample media-query so the font-size of the nav components gets smaller and doesn't overlap the logo.
.navbar {
position: relative;
padding-top: 0;
opacity: 80%;
}
.navbar-brand {
position: absolute;
left: 50%;
transform: translateX(-50%);
display: block;
}
.img-responsive {
height: auto;
width: auto;
max-height: 156px;
max-width: 250px;
top: 109px;
}
.circle {
width: 249px;
height: 285px;
border-radius:250px;
font-size:50px;
line-height:500px;
text-align:center;
background: black;
}
.navbar-nav a {
color: black;
white-space: nowrap;
}
/* additions */
.left {
display: flex;
gap: 20px;
}
.right {
display: flex;
gap: 20px;
}
nav.same-line {
display: flex;
justify-content: space-between;
}
#media only screen and (max-width: 800px) {
.same-line {
font-size: smaller;
}
.left, .right {
display: flex;
gap: 5px;
}
}
/* additions END */
body {
background: url(assets/hack2.jpg) no-repeat center center fixed;
background-size: cover;
}
<div class="bodyContainer">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<div class="circle bg-light navbar-brand">
<a href="#" class="navbar-brand">
<img class="img-responsive navbar-brand" src="assets/logo.png" alt="logo">
</a>
</div>
<button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<nav class="same-line"> <!-- puts both .left & .right one same line -->
<div class="navbar-nav left">
Home
Über uns
Aktuelles
</div>
<!-- left contains leftside nav components, right = opposite -->
<div class="navbar-nav right">
Genossenschaft
Nochagfrogt
Kontakt
</div>
</nav>
<div class="navbar-nav ms-auto">
Login
</div>
</div>
</div>
</nav>
</div>
Click full-page when testing the snippet, and resize your browser to watch the font-size change just before it overlaps. I would target this same media-query to change your logo size when resizing also.
I'd like to create the main page, with a navtop, a nav left side and content in middle. The menu and the navtop should be fixed on the screen. Only the content should be scrollable.
When the menu is expanded, the content is pushed to the right, without element reordering inside, just pushed as it is on the right, so a part of the content on the right will be hidden out-out the screen while a menu is expanded.
Here are images to illustrate:
Collapsed menu
Expanded menu
(Sorry I can't embed images because of my low reputation)
So when I hover the menu, it expands and pushes the content to the right. When a mouse is out the menu, it collapses and only shows icons.
I nearly managed to do this, but I can't give you the code, it's professional.
I'm the beginner in CSS, it's hard for me I tried a lot but no way to managed to build this page.
I put the menu and the content on float: left, but when I load a new page, the content is on the menu, so I can't click on menu icons anymore.
You can try this demo,
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft= "0";
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
.sidenav a:hover, .offcanvas a:focus{
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
#main {
transition: margin-left .5s;
padding: 16px;
}
<div id="mySidenav" class="sidenav">
×
About
Services
Clients
Contact
</div>
<div id="main">
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
</div>
I made this that should work how you want if I understood your post correctly. It uses a few lines of Jquery for the animation when you hover over the side navigation menu. The icons and text are just placeholders
$(document).ready(function(){
$(".sidenav").hover(function(){
$(".hidetext").stop(true).toggle("fast");
});
});
html, body{
height: 100%;
min-height: 100%;
}
.navbar {
margin-bottom: 0 !important;
}
.sidenav-wrapper {
margin-top: 51px;
}
.sidenav {
background-color: aquamarine;
height: 100%;
display: inline-block;
float: left;
z-index: 1;
position: fixed;
}
.sidenav span {
font-size: 45px;
padding: 20px;
}
.sidenav span .hidetext {
font-size: 18px;
margin-left: 30px;
margin-top: 12px;
float: right;
display: none; /* Changes to inline-block on hover */
}
.main-content {
margin-top: 51px;
margin-left: 89px;
z-index: -1;
position: absolute;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta charset=utf-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#topnav">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="topnav">
<ul class="nav navbar-nav">
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
</nav>
<div class="sidenav">
<div class="sidenav-wrapper">
<span class="glyphicon glyphicon-home home" aria-hidden="true"><p class="hidetext">Home</p></span>
<br>
<span class="glyphicon glyphicon-cog" aria-hidden="true"><p class="hidetext">Options</p></span></div>
</div>
<div class="main-content">
<p>Stuff on the right of side navigation bar</p>
<div class="test"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="script.js"></script>
</body>
</html>
My goal is to make a navbar with Bootstrap 3.3.6 with buttons placed inside it. These buttons are suppose to allow for navigation to different parts of the page, which was implemented with anchor elements.
However, when I positioned the buttons inside the navbar, the buttons don't work, which is confusing since the buttons allow for navigation when positioned outside the navbar.
Here is the complete code:
#bg-colr-div {
background-color: black;
color: white;
}
body h2 {
color: #1a1aff;
}
.container {
position: absolute;
left: 70%;
font-size: 1.5em
}
#abtme-btn {
position: relative;
top: 50%;
}
#portf-btn {
position: relative;
left: 10%;
bottom: 50%;
}
#contact {
position: relative;
left: 20%;
}
span {
size: 2em;
}
#center {
margin-left: 15%;
margin-right: 15%;
}
#aboutme {
border: solid white;
}
#name-title {
margin-top: 5%;
position: relative;
left: 25%;
font-family: gotham rounded;
}
p {
float: left;
position: relative;
left: 25%;
}
img {
border-radius: 100%;
position: relative;
left: 25%
}
#portfolio {
border: solid;
}
#portfolio h2 {
position: relative;
left: 45%;
}
#portfolio img {
position: relative;
left: 37%;
}
<head>
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" />
<link type="text/css" rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="/home/salpal/Desktop/WebDev/FreeCodeCamp/Portfolio/Portfolio.css" />
<script src="jquery-1.12.2.min.js"></script>
</head>
<body>
<div id="bg-colr-div">
<div id="nav" class="navbar navbar-default navbar-fixed-top">
<ul class="container">
<li id="abtme-btn"><a class="btn btn-default navbar-btn" href="#aboutme">About Me</a></li>
<li id="portf-btn"><a class="btn btn-default navbar-btn" href="#portfolio">Portfolio</a></li>
</ul>
<!--Contact buttons-->
<div id="contact">
<a href="https://github.com/srpalomino" class="btn btn-social-icon btn-github">
<span class="fa fa-github fa-2x"></span>
</a>
<a href="https://www.facebook.com/salvatore.palomino" class="btn btn-social-icon btn-facebook">
<span class="fa fa-facebook fa-2x"></span>
</a>
<a href="https://www.linkedin.com/in/salvatore-palomino-105227103?trk=hp-identity-photo" class="btn btn-social-icon btn-linkedin">
<span class="fa fa-linkedin fa-2x"></span>
</a>
</div>
</div>
<div id="center">
<div id="aboutme">
<h2 id="name-title">Salvatore Palomino - Web Developer in Training</h2>
<p>My name is Salvatore Palomino, and this is my first portfolio!<br></p>
<aside><img src="https://lh3.googleusercontent.com/-nTCcGhM4rEk/Ujn7oi5IFlI/AAAAAAAAABM/NjPoBSeOpBI/w426-h427/13797_510377245660711_1806374138_n.jpg" /></aside>
</div>
<div id="portfolio">
<h2>Portfolio</h2>
<img src=# alt="Placeholder">
<img src=# alt="Placeholder">
<img src=# alt="Placeholder">
<img src=# alt="Placeholder">
</div>
</div>
</div>
</body>
The problem is that the #contact div that is containing your social media buttons is covering the navigation buttons. Just change that div to display:inline-block;
#contact {
position: relative;
left: 20%;
display: inline-block;
}
I think you are missing target="_blank" inside the .
Add display inline-block to #contact.
#contact {
display: inline-block;
}
How do you add an arrow using css to the navbar brand (see image example)
The arrow should not be visible when in mobile view.
The following doesn't work - clearly I'm not the best at css.
.navbar-default {
.navbar-brand {
position: relative;
float: left;
margin-right:30px;
color: #navbar-default-brand-color;
&:hover,
&:focus {
color: #navbar-default-brand-hover-color;
background-color: #navbar-default-brand-hover-bg;
}
&:after {
content: " ";
display: block;
width: 0;
height: 0;
border-top: 19px solid transparent;
border-bottom: 19px solid transparent;
border-left: 12px solid #brand-secondary;
position: absolute;
top: 50%;
margin-top: -19px;
left: 100%;
z-index: 3;
}
&:before {
content: " ";
display: block;
width: 0;
height: 0;
border-top: 19px solid transparent;
border-bottom: 19px solid transparent;
border-left: 12px solid white;
position: absolute;
top: 50%;
margin-top: -19px;
margin-left: 1px;
left: 100%;
z-index: 3;
}
#media (max-width: #grid-float-breakpoint) {
}
}
}
the html is as follows
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button class="navbar-toggle collapsed" aria-controls="navbar" aria-expanded="false" data-target="#navbar" data-toggle="collapse" type="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Bootstrap</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">
Getting started
</li>
<li>
CSS
</li>
<li>
Components
</li>
<li>
Javascript
</li>
<li>
Customize
</li>
</div>
</div>
</nav>
Update: I've managed to get it working using the before and after css. How do I overide this css with the media query i.e whats the css that goes inside the media query to remove it on a mobile device?
have created a small fiddle with example code of how to do this for list items. It can be edited slightly and re-applied to your code to achieve the desired affect.
It's all about the :before and :after selectors.
http://jsfiddle.net/dgc6ajbL/
I've been digging into how to create a wedge shaped menu and came across the following stackoverflow post: Diagonal Wedge Shaped CSS - Edge to Edge Centered in Browser
I've re-purposed the example image Varazi drew up to better explain my own situation (please excuse the old writing on it). I've added 2 menu items, home and contact, to show what I'm trying.
The code I have been playing around with (found from the above link).
HTML
<div class="shape">
<div class="top"></div>
<div class="bottom"></div>
</div>
CSS
.shape {
width:400px;
margin:0 auto;
}
.top {
height:0;
border-width:0 0 150px 400px;
border-style:solid;
border-color:transparent #d71f55 #d71f55 transparent;
}
.bottom {
height: 50px;
background-color:#d71f55;
}
/* Support transparent border colors in IE6. */
* html .top {
filter:chroma(color=#123456);
border-top-color:#123456;
border-left-color:#123456;
}
Update: After playing quite a lot with it, really fun challenge I must say, I have finally gotten it exactly the way I needed it to be with the helpful tip by Talkingrock (thanks man!). My remaining challenge would be showing the .sub-menu inside an overflow: hidden element (#masthead), but it's not overly important as I can have the links plastered on the homepage in the relevant content sections.
Hope the below code helps a poor soul out, such as myself, who needed help. Enjoy! :)
HTML (I'm using WordPress/Bootstrap)
<header id="masthead" class="site-header" role="banner">
<nav id="site-navigation" class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://demo.dev/" title="demo" rel="home">
<img width="159" height="134" src="http://demo.dev/wp-content/uploads/2014/10/logo.png" class="img-responsive" alt="logo">
</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul id="menu-main-menu" class="nav navbar-nav pull-right">
<li>Home</li>
<li>About Us</li>
<li>Services
<ul class="sub-menu">
<li>Industrial Electrical</li>
<li>Commercial Electrical</li>
<li>Domestic Electrical</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</header>
CSS (using Less)
/* --- header */
#masthead {
overflow: hidden;
position: relative;
bottom: 50px; height: 200px;
background: red;
transform: skew(0deg, -3deg);
}
/* --- main navigation */
#site-navigation {
position: relative;
bottom: -50px;
height: 100%;
margin-bottom: 0;
border-radius: 0;
background: none;
border: none;
transform: skew(0deg, 3deg);
.container,
.navbar-collapse {
height: 100% !important;
}
.nav {
height: 100%;
&>li {
height: 100%;
&>a {
height: 100%;
padding: 80px 15px 0;
color: #fff;
}
&.current-menu-item,
&:hover {
&>a {
background-color: #tree-poppy;
}
}
}
}
}
Update2: Just wanted to quickly mention you can also attach the wedge part to an existing element easily without using any additional elements as well!
CSS
#masthead:after {
content: "";
position: absolute;
top: -45px; left: 0;
z-index: -1;
width: 100%; height: 80px;
background-color: red;
transform: skew(0deg, -3deg);
}
Here's what I came up with:
The HTML:
<header>
<nav>
Home
Contact
About
</nav>
</header>
The CSS:
header {
overflow: hidden;
margin-top: -550px;
height: 850px;
margin-bottom: -50px;
}
nav {
width: 120%;
margin: 0 -10%;
transform: rotate(-12deg);
background: red;
padding: 0 10%;
overflow: hidden;
}
nav a {
color: #fff;
text-decoration: none;
display: block;
float: left;
transform: rotate(12deg);
background: purple;
padding-top: 500px;
padding-bottom: 1000px;
margin-bottom: -900px;
text-align: center;
width: 80px;
position: relative;
}
.link-1 {
top: -36px;
}
.link-2 {
top: -18px;
}
Here's a working example: http://codepen.io/btpoe/pen/GavLk
Please note that this would not work in IE8 or less and would need some sort of fallback.