I have created a navbar using HTML and CSS. It works perfectly on IE, Opera, and Chrome.
However, on Safari the logo seems to be cut off. All I did was to add the position fixed to the logo to make the logo stick to the top of the page when the user scrolls down the page.
My HTML:
<div id="nav">
<div id="top-bar">
<div class="container">
<div class="left-right-nav">
<div class="left-nav-2">
<div>
<span></span>
<span><i class="fab fa-facebook"></i> <i class="fab fa-twitter"></i> <i class="fab fa-instagram"></i></span>
<span style="visibility: hidden;">ffff</span>
</div>
</div>
<div class="right-nav">
<div>
<span>01283 575 671</span>
<span>Join Now</span>
</div>
</div>
</div>
<div class="center-container">
<span style="padding:0;"><img src="https://via.placeholder.com/250x115" alt="" width="100%"></span>
</div>
</div>
</div>
<div class="nav-bg">
<div class="container">
<div class="left-right-nav">
<div class="left-nav">
<div>
<span>Facilties</span>
<span>Timetable</span>
<span>Blog</span>
</div>
</div>
<div class="right-nav">
<div>
<span>The Team</span>
<span>Events</span>
<span>Contact Us</span>
</div>
</div>
</div>
<div class="center-nav">
</div>
</div>
</div>
</div>
My CSS:
body{
margin:0;
}
#nav {
z-index: 999;
}
.left-container,
.center-container,
.right-container {
position: absolute;
display: inline-block;
margin: 0;
padding: 0;
width: calc(50% - 125px);
}
.left-container {
left: 0;
height: 50px;
overflow: hidden;
}
.left-container span {
margin: auto;
left: 0;
right: 0;
position: absolute;
}
.center-container {
width: 250px;
height: 115px;
z-index: 2;
left: 0;
right: 0;
margin: auto;
}
.right-container {
right: 0;
height: 50px;
overflow: hidden;
}
.right-container span:last-child {
background: #081F2D;
width: 40%;
float: right;
}
.right-container span:last-child a {
color: #FFDE00;
}
.left-right-container {
background: #FFDE00;
height: inherit;
}
.left-container span,
.right-container span {
padding: 15px 15px;
font-weight: 500;
text-transform: uppercase;
width: 59%;
display: inline-block;
}
.left-container span a,
.right-container span a {
display: block;
color: #081F2D;
text-decoration: none;
text-align: center;
font-size: 17px;
}
#top-bar {
float: left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 0px;
overflow: hidden;
width: 100%;
min-width: 650px;
min-height: 50px;
position: fixed;
z-index: 999;
}
.nav-bg {
width: 100%;
position: absolute;
top: 50px;
height: 50px;
z-index: 2;
margin-top: -1px;
}
.left-right-nav {
background-color: #EEEEEE;
height: inherit;
}
.left-nav,
.left-nav-2,
.center-nav,
.right-nav {
position: fixed;
display: inline-block;
width: calc(50% - 125px);
}
.left-nav,
.left-nav-2{
left: 0;
}
.center-nav {
width: 250px;
height: 50px;
z-index: 1;
left: 0;
right: 0;
margin: auto;
}
.right-nav {
right: 0;
}
/*.left-nav:after, .right-nav:after {
content: '';
display: inline-block;
width: 100%;
}*/
.left-nav div,
.left-nav-2 div,
.left-nav-2 div,
.right-nav div {
margin: auto;
left: 0;
right: 0;
position: absolute;
background-color: #EEEEEE;
text-align: right;
margin-left: -20px;
}
.left-nav-2 div{
background-color: #FFDE00;
}
.left-nav div span {}
.right-nav div span {
float: left;
}
.left-nav div span,
.left-nav-2 div span,
.right-nav div span {
display: inline-block;
}
.left-nav span a,
.left-nav-2 span a,
.right-nav span a {
padding: 15px 40px;
display: block;
font-size: 1rem;
text-align: center;
color: #081F2D;
text-transform: uppercase;
font-weight: 600;
text-decoration: none;
background-color: #EEEEEE;
}
}
The codepen to my problem is https://codepen.io/anon/pen/xymdmP
Try adding position: fixed; and -webkit-transform: translate3d(0, 0, 0); instead of on image tag style.
https://codepen.io/anon/pen/MPZPPy
Thanks
Related
I'm trying to create a horizontal/scrollable nav with gradient fades on each end. Setting the parent to overflow: auto almost solves my problem but hides my active link border, which I position absolute as a :before pseudo above its parent link. I was wondering if there was a way for me to keep the overflow while having my pseudo border break out of it? For the sake of this question, the gradient really doesn't matter per se but this structure needs to remain in tact.
ul {
margin: 0;
}
li {
display: inline-block;
}
.vertical-title {
height: 55px;
margin-bottom: 13px;
border-bottom: 3px solid #dceaec;
font-size: 22px;
line-height: 57px;
color: #111;
text-align: center;
text-transform: uppercase;
}
.vertical-title-wrapper {
padding: 0;
z-index: 0;
position: relative;
}
.hub-nav {
display: block;
padding: 0 15px;
width: 100%;
z-index: 1;
white-space: nowrap;
overflow: auto;
}
.hub-nav-link {
position: relative;
}
.hub-nav-link.active-path:before {
content: "";
display: block;
height: 3px;
width: 100%;
left: 0;
position: absolute;
top: -16px;
background-color: #007eff;
}
<div class="hub-wrapper">
<div class="vertical-title">
Page Title
</div>
<nav class="hub-nav">
<ul class="hub-nav-list">
<li class="hub-nav-list-item">
<a class="hub-nav-link active-path" href="">
There's supposed to be a border above me!
</a>
</li>
</ul>
</nav>
</div>
<div>
Content Below
</div>
Negative margins will do the trick:
ul {
margin: 0;
}
li {
display: inline-block;
}
.vertical-title {
height: 55px;
margin-bottom: 13px;
border-bottom: 3px solid #dceaec;
font-size: 22px;
line-height: 57px;
color: #111;
text-align: center;
text-transform: uppercase;
}
.vertical-title-wrapper {
padding: 0;
z-index: 0;
position: relative;
}
.hub-nav {
display: block;
padding: 0 15px;
width: 100%;
z-index: 1;
white-space: nowrap;
overflow: auto;
padding-top: 16px;
margin-top: -16px;
}
.hub-nav-link {
position: relative;
}
.hub-nav-link.active-path:before {
content: "";
display: block;
height: 3px;
width: 100%;
left: 0;
position: absolute;
top: -16px;
background-color: #007eff;
}
<div class="hub-wrapper">
<div class="vertical-title">
Page Title
</div>
<nav class="hub-nav">
<ul class="hub-nav-list">
<li class="hub-nav-list-item">
<a class="hub-nav-link active-path" href="">
There's supposed to be a border above me!
</a>
</li>
</ul>
</nav>
</div>
<div>
Content Below
</div>
So that you don't have to look for too long - I added these two lines into your snippet:
.hub-nav {
padding-top: 16px;
margin-top: -16px;
}
I tried to add margin-left : 25%; to class .four but not work. how can i do ?
.one{
width: 100%;
}
.two{
margin: 0;
padding: 0;
border: 0;
background: transparent;
float: left;
position: relative;
width: 100%;
margin-bottom: 15px;
}
.three{
float: left;
list-style: none;
color: #333;
font-size: 19px;
width: 100%;
background: #fff;
border: 1px solid #ccc;
padding: 10px 0px;
}
.four{
margin-left: 10px;
width: 246px;
height: 138px;
margin-right: 16px;
display: inline-block;
position: relative;
float: left;
}
.five{
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
height: 100%;
margin-left: auto;
margin-right: auto;
overflow: hidden;
display: block;
cursor: pointer;
}
.six{
transform: translateY(-50%);
top: 50%;
left: 0;
background-color: transparent;
display: block;
position: absolute;
}
.seven{
width: 246px;
display: block;
margin-left: auto;
margin-right: auto;
max-width: unset;
}
<div class="one">
<ul class="two">
<li class="three">
<div class="four">
<a class="five" href="">
<div class="six">
<img class="seven" src="http://kawamono.com/img/cms/Hobby/Coin%20Bank/x100828-sanrio-hellokitty-mini-bank-ylw-SET.jpg.pagespeed.ic.iSCJA9hZBG.jpg">
</div>
</a>
</div>
</li>
</ul>
</div>
Change the css of .four to this:
.four {
width: 246px;
height: 138px;
margin: 0 auto;
position: relative;
}
.one {
width: 100%;
}
.two {
margin: 0;
padding: 0;
border: 0;
background: transparent;
float: left;
position: relative;
width: 100%;
margin-bottom: 15px;
}
.three {
float: left;
list-style: none;
color: #333;
font-size: 19px;
width: 100%;
background: #fff;
border: 1px solid #ccc;
padding: 10px 0px;
}
.four {
width: 246px;
height: 138px;
margin: 0 auto;
position: relative;
}
.five {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
height: 100%;
margin-left: auto;
margin-right: auto;
overflow: hidden;
display: block;
cursor: pointer;
}
.six {
transform: translateY(-50%);
top: 50%;
left: 0;
background-color: transparent;
display: block;
position: absolute;
}
.seven {
width: 246px;
display: block;
margin: 0 auto;
max-width: unset;
}
<div class="one">
<ul class="two">
<li class="three">
<div class="four">
<a class="five" href="">
<div class="six">
<img class="seven" src="http://kawamono.com/img/cms/Hobby/Coin%20Bank/x100828-sanrio-hellokitty-mini-bank-ylw-SET.jpg.pagespeed.ic.iSCJA9hZBG.jpg">
</div>
</a>
</div>
</li>
</ul>
</div>
I noticed that you want to center the image yet you are using float:left to .four, it is conflicting to the result you are expecting. And I changed your margins to margin:0 auto; to properly center it horizontally
You can add:
width: 100%;
To style for .four and .six, This will center the image sideways. Those divs does not have a with, so the the image will not center.
Hope this helps 😄
Oel Kristian Ek Hornnes
i would like to have my logo centred to the four images. How do i do this? i would like the four images to fill the window and the logo to centre to them. I also don't want to stretch the images but would consider resizing them if needs be
.header {
background-color: black;
border-bottom: 1px solid #466995;
overflow-y: auto;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 10;
}
ul {
margin: 30px auto;
text-align: center;
}
li {
color: #FFF;
display: inline-block;
font-family: 'Oswald', sans-serif;
font-size: 16px;
text-align: left;
font-weight: 300;
text-transform: uppercase;
padding: 0 100px;
}
li:hover {
color: #DBE9EE;
}
body {
margin: 0;
}
img {
max-width: 100%;
height: auto;
}
#container {
max-width: 100%;
z-index: -100;
margin: 0;
padding: 0;
}
.containermenu {
}
.containermenu img{
width: 50%;
height: 50%;
float: left;
}
#logo {
width: 20%;
margin: 0 auto;
position: absolute;
z-index: 20;
left: 40%;
right: 40%;
}
#process img {
width: 100%;
}
#process {
width: 100%;
}
<div id="container">
<div id="logo"><img src="http://oi68.tinypic.com/2njh9id.jpg"></div>
<div class="containermenu"><img src="http://oi67.tinypic.com/vgmv80.jpg"></div>
<div class="containermenu"><img src="http://oi67.tinypic.com/vgmv80.jpg"></div>
<div class="containermenu"><img src="http://oi67.tinypic.com/vgmv80.jpg"></div>
<div class="containermenu"><img src="http://oi67.tinypic.com/vgmv80.jpg"></div>
</div>
Codepen link
To center an item perfectly in the page use the following CSS
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
EDIT: Updated Codepen
Use transform to center in css More infor here
.header {
background-color: black;
border-bottom: 1px solid #466995;
overflow-y: auto;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 10;
}
ul {
margin: 30px auto;
text-align: center;
}
li {
color: #FFF;
display: inline-block;
font-family: 'Oswald', sans-serif;
font-size: 16px;
text-align: left;
font-weight: 300;
text-transform: uppercase;
padding: 0 100px;
}
li:hover {
color: #DBE9EE;
}
body {
margin: 0;
}
img {
max-width: 100%;
height: auto;
}
#container {
max-width: 100%;
z-index: -100;
margin: 0;
padding: 0;
}
.containermenu {} .containermenu img {
width: 50%;
height: 50%;
float: left;
}
#logo {
width: 20%;
position: absolute; /*fixed*/
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#process img {
width: 100%;
}
#process {
width: 100%;
}
<div id="container">
<div id="logo">
<a href="index.html">
<img src="http://oi68.tinypic.com/2njh9id.jpg">
</a>
</div>
<div class="containermenu">
<a href="packaging.html">
<img src="http://oi67.tinypic.com/vgmv80.jpg">
</a>
</div>
<div class="containermenu">
<a href="photography.html">
<img src="http://oi67.tinypic.com/vgmv80.jpg">
</a>
</div>
<div class="containermenu">
<a href="illustration.html">
<img src="http://oi67.tinypic.com/vgmv80.jpg">
</a>
</div>
<div class="containermenu">
<a href="about.html">
<img src="http://oi67.tinypic.com/vgmv80.jpg">
</a>
</div>
</div>
I'm trying to make a caption appear whenever I hover on the image. I want the height of the image to be set to 200px, but the width to be auto. How can I make the span with the caption also correspond to the image width? Thanks!
HTML:
<div class="projects">
<a name="folder"></a>
<h1 class="heading">Projects</h1>
<p class="classProjectsInfo">Recent class projects</p>
<div class="classProjects">
<ul class="img-list">
<li>
<img src="checkers_cover.JPG">
<span class="description2"><span>Checkers61B</span></span>
</li>
<li>
<img src="cover_ngram.JPG">
<span class="description2"><span>NGramMap</span></span>
</li>
<li>
<img src="gitlet_cover.JPG">
<span class="description2"><span>Gitlet</span></span>
</li>
</ul>
</div>
</div>
CSS:
.classProjects {
text-align: center;
margin: 0;
padding: 0;
list-style-type: none;
}
.classProjects li {
display: inline-block;
padding: 5px;
margin: 10px;
position: relative;
height: 250px;
width: auto;
}
.classProjects img {
height: 250px;
width: auto;
}
ul.img-list {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
}
ul.img-list li {
display: inline-block;
height: 250px;
position: relative;
width: auto;
}
span.description2 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 250px;
left: 0;
position: absolute;
top: 0;
width: auto;
}
span.description2 span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
span.description2 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 250px;
left: 0;
position: absolute;
top: 0;
width: auto;
opacity: 0;
}
ul.img-list li:hover span.description2 {
opacity: 1;
}
I have the following: http://jsfiddle.net/5mbK8/2/
The text Link is supposed to function as a link, but it doesn't work because .container .image has a z-index of -1. If I remove the z-index, it works, but then the image isn't behind the yellow shadow.
How can I make the text clickable while keeping the background image behind the yellow box shadow?
HTML:
<div class="container">
<div class="side"></div>
<div class="image" style="background: url('http://i.imgur.com/T0VWLqZ.png');">
<div class="menu">
<ul>
<li><a href="#">Link</li>
</ul>
</div>
</div>
</div>
CSS:
a {
color: black;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.container {
width: 900px;
height: 300px;
}
.container .image {
width: 598px;
height: 300px;
float: right;
position: relative;
z-index: -1;
}
.container .side {
float: left;
width: 302px;
height: 300px;
background: red;
box-shadow: 5px 0 5px -5px yellow;
}
.container .image .menu {
position: absolute;
bottom: 0;
left: -25px;
}
.container .image .menu ul {
list-style: none;
margin: 0;
}
.container .image .menu ul li {
display: inline-block;
text-align: center;
padding: 10px;
background: white;
}
Check out this fiddle: http://jsfiddle.net/5mbK8/5/
A solution would be to position the menu outside the .image div.
And of course you will have to adapt the left: 300px; depending on what width the .side will have.
EDIT (added code):
<div class="container">
<div class="side"></div>
<div class="image" style="background: url('http://i.imgur.com/T0VWLqZ.png');"> </div>
<div class="menu">
<ul>
<li>Link</li>
</ul>
</div>
</div>
CSS:
a {
color: black;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.container {
position: relative;
width: 900px;
height: 300px;
}
.container .image {
width: 598px;
height: 300px;
float: right;
position: relative;
z-index: -1;
}
.container .side {
float: left;
width: 302px;
height: 300px;
background: red;
box-shadow: 5px 0 5px -5px yellow;
}
.container .menu {
position: absolute;
bottom: 0;
left: 300px;
}
.container .menu ul {
list-style: none;
margin: 0;
}
.container .menu ul li {
display: inline-block;
text-align: center;
padding: 10px;
background: white;
}