I have a fixed navbar at the top of my page, and want to position an element below it, relative to how big the navbar is. When resizing the browser window, my navbar will jump into 2 or 3 lines from one, and I want my div (.articles-showcase) to move accordingly.
I tried achieving this by nesting my div inside the navbar container and using position: absolute;, top: 0;, but this just always positions my div at the top of the page.
Is there a way to do this using css, or should I look for a javascript solution?
I am currently using bootstrap and angular JS and wouldn't like to add jQuery to my project if not necessary.
Here's my html:
<div class="header" ng-controller="NavbarController">
<ul>
<li ng-class="{ active: isActive('/PTC-Testers') }">PTC-Testers</li><li ng-class="{ active: isActive('/articles') }">articles</li><li ng-class="{ active: isActive('/sites') }">PTC sites</li><li ng-class="{ active: isActive('/account_reviews') }">account reviews</li><li ng-class="{ active: isActive('/forum') }">forum</li><li ng-class="{ active: isActive('/contact') }">contact us</li><li ng-class="{ active: isActive('/login') }">login</li>
</ul>
<div class="articles-showcase">
<div class="col-xs-6 col-md-3">
<p>featured</p>
<h1>What I learned while cooking</h1>
<h3>author | posted </h3>
</div>
<div class="col-xs-6 col-md-3">
<p>most read</p>
<h1>My favorite things about dogs</h1>
<h3>author | posted </h3>
</div>
<div class="col-xs-6 col-md-3">
<p>highest rating</p>
<h1>It's finally friday people!</h1>
<h3>author | posted </h3>
</div>
<div class="col-xs-6 col-md-3">
<p>featured track</p>
<h1>starting your own adventure</h1>
<h3>author | posted </h3>
</div>
</div>
</div>
the relevant part of my CSS:
.header {
background-color: red;
color: #fff;
border-bottom: 0.3em solid cyan;
position: fixed;
top: 0;
z-index: 10;
width: 100%;
}
.header ul {
list-style: none;
text-align: center;
margin: 0;
padding: 0;
}
.header ul li {
display: inline-block;
}
.header ul li a {
font-family: 'Ubuntu', sans-serif;
font-weight: 400;
font-size: 1.3em;
color: #fff;
padding: 5px 1em;
margin: 0;
display: inline-block;
text-decoration: none;
outline: none;
}
.header ul li:hover {
background-color: #ff6666;
text-decoration: none;
}
.header ul .active {
background-color: cyan;
}
.articles-showcase {
position: absolute;
top: 0;
z-index: 11;
border-bottom: 0.2em solid cyan;
padding: 0.5em;
width: 100%;
}
.articles-showcase div {
text-align: center;
}
.articles-showcase div h1, .articles-showcase div h3, .articles-showcase div p {
margin: 0;
padding: 0.3em;
color: #660000;
}
.articles-showcase div p {
font-size: 1.2em;
color: red;
}
.articles-showcase div h1 {
font-size: 1.7em;
}
.articles-showcase div h3 {
font-size: 1.4em;
}
Based on the anwser from #Milos Miskone Sretin I came up with this crude jQuery solution:
$(window).resize(function() {
$('.articles-showcase').css('top', $('.header ul').outerHeight());
});
I still need to test this in different browsers and on mobile devices but for now, it seems to do the trick.
If anyone can come up with a css alternative to do this (maybe something including bootstrap classes that I do not know about), please let me know.
If you want to put div below fixed element you can do it by setting its top margin to height of navbar.
But, in your case, because you don't have fixed height it is not that simple. You need to use javascript to achieve this.
The simplest way is to use jQuery, if I am right, you already have it loaded since you are using bootstrap. Try in this way:
$(document).ready(function() {
$('.articles-showcase').css('top', $('.header').outerHeight());
});
Also, I am not completely clear. Is both .articles-showcase and ul under header div. If you want to put .articles-showcase under ul do it like:
$(document).ready(function() {
$('.articles-showcase').css('top', $('.header ul').outerHeight());
});
You can do it without jQuery but using jQuery is an easiest way.
Hope this can help you.
Related
I have looked at some other posts and all I could find was answers using javascript. Is there some way that I hover over an element on top of another element but the element at the bottom won't change its style? By the way, I only want to use vanilla HTML and CSS, no javascript. In this example, the goal is to hover over blabla or blablabla without adding a border to the navigation bar.
HTML
<div class="navBar">
<div>
<h1 id="Title">A Random Website</h1>
</div>
<div class="navBarChild">
Notepad
Help
</div>
</div>
CSS
.navBar{
display: flex;
position: sticky;
top:0;
padding: 20px;
border: 2px solid gainsboro;
width: 100%;
justify-content: center;
background-color: gainsboro;
z-index: 2;
}
#Title{
color: black;
font-family: monospace;
}
.navBar:hover{
border: 2px solid black;
}
h3{
z-index: 2;
}
body{
background:url("...") left / cover no-repeat;
}
.navBarChild{
display: flex;
flex-direction: row;
position: relative;left: 290px;top: 17px;
}
#linkBla{
font-weight: bold;
text-decoration: none;
font-size: 26px;
font-family: monospace;
color: black;
}
#linkBla:hover{
color: orangered;
}
#linkBlaBla{
position: relative;left: 50px;
font-weight: bold;
text-decoration: none;
font-size: 26px;
font-family: monospace;
color: black;
}
#linkBlaBla:hover{
color: orangered;
}
Add a new 'navBarContainer'
Try bringing the 'navBarChild' out of the 'navBar' like this:
<div class="navBar">
<div>
<h1 id="Title">A Random Website</h1>
</div>
</div>
<div class="navBarChild">
Notepad
Help
</div>
Make a whole new 'navBarContainer' for the both of them
<div class="navBarContainer">
<div class="navBar">
<div>
<h1 id="Title">A Random Website</h1>
</div>
</div>
<div class="navBarChild">
Notepad
Help
</div>
</div>
Set the '.navBarContainer' in your css to 'position: relative;'
position: relative;
Set the 'navBarChild' to
position: absolute;
display: flex; //to keep the a-links together
and then you can position it to your desire
top: 0; //important
left: 75%;
height: 100%;
At this point there should be no need for the z-index
Lastly
Add a little padding to the #linkBla and #linkBlaBla and set the display to 'flexbox'
#linkBla, #linkBlaBla {
padding: 40%;
display: flexbox;
}
Checkout the whole thing in this pen https://codepen.io/emekaorji/pen/mdOMMRr
I don't believe this is possible without javascript, but you can put the script inside of the HTML like so:
<html>
<body>
...
<script>
function removeOutline() {
document.getElementsByClassName("navBar")[0].style.border = "2px solid transparent";
}
function addOutline() {
document.getElementsByClassName("navBar")[0].style.border = "2px solid black";
}
</script>
</body>
</html>
and use it like:
<div class="navBarChild" onmouseover="removeOutline()" onmouseout="addOutline()">
CSS does not allow you to change elements above the current element. In other words, you can't change the parent element based on the child element (the reverse works by using child selectors).
Beginner CSS question here.
I have the home page of a website I'm working on set out perfectly. I have two `divs
#desktop-navbar {
text-transform: uppercase;
width: 100%;
height: 90px;
position: fixed;
z-index:1;
}
#desktop-nav-wrapper {
height: inherit;
padding: 0 45px;
}
#desktop-nav-wrapper nav ul {
float: right;
padding-top: 35px;
font-size: 16px;
}
#desktop-nav-wrapper nav li {
position: relative;
display: inline-block;
padding-left: 25px;
color: #000000;
font-family: Thasadith;
font-weight: 700;
}
#desktop-navbar #mobile-menu-link{
display: none;
}
#desktop-nav-wrapper nav li:hover {
font-weight: 900;
}
#desktop-nav-wrapper.solid {
transition: background-color 1s ease 0s;
background-color: #eeeeee;
}
#desktop-logo.solid-fonts {
transition: color 1s ease 0s;
background: linear-gradient(90deg, #000 100%, #000 0%) fixed;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
#desktop-nav-wrapper nav li.solid-fonts {
transition: color 1s ease 0s;
color: #000000;
}
#desktop-nav-wrapper {
font-weight: bold;
font-size: 18vw;
text-transform: uppercase;
color: black;
letter-spacing: 2px;
}
#home {
height: 700px;
position: relative;
}
#home-container {
height: inherit;
width: 100%;
display: flex;
position: absolute;
}
#home-colour-one {
height: inherit;
width: 33%;
background-color: #314455;
}
#home-colour-two {
height: inherit;
width: 67%;
background-color: #dddddd;
}
<div id="desktop-navbar">
<div id="desktop-nav-wrapper">
<nav>
<ul id = "desktop-nav-content">
<li class="desktop-items">Casa</li>
<li class="desktop-items">Sobre Mi</li>
<li class="desktop-items">Servicio</li>
<li class="desktop-items">Galería</li>
<li class="desktop-items">Contacto</li>
<li id="mobile-menu-link"><a>Menu</a></li>
</ul>
</nav>
</div>
</div>
<div id="home">
<div id="home-container">
<div id="home-colour-one">
<h3>Bettoo Kaozink</h3>
</div>
<div id="home-colour-two" class="container">
</div>
</div>
</div>
side by side with different colours (I know I could use one div and use the CSS gradient method, but I want to add some sweet fade-in to both of these divs at a later point).
But I want to place the text on the halfway point between the two divs (so one half is in the blue and the other half is in the grey).
Right now, I only have the text in one div of the home page (home-colour-one), but I'd like it to be spread across the two. Is there a way I can get the text to overflow into the grey div (home-colour-two)? Or just have the text in a separate div and place on the point separating the two divs?
I also know I can have the H3 of Bettoo Kaozink in the nav bar, but that is something I want to avoid. As ideally, I would like Bettoo Kaozink centered vertically in the container.
Cheers
One way to approach this is by using flexbox by adding display: flex to the container. If you haven't learned about how flexbox works, I'd recommend you to read up on this article.
I've created a mini prototype here of what you wanted. There are two things you should do to the JSFiddle in advanced to help you understand the code a bit better:
On line 15 of the CSS code, change the flex-grow property to some other value.
Use JavaScript to center the text relative to the div-container
Once you understand flexbox, it opens a door to so many different options that you can choose from.
I hope that it works out for you. If not, just tell me in the comments.
Honestly the structure of your page, based on what I can understand from here, it's not so solid.
Anyway, just in this context, and if I get right your goal, so having your h3 (or whatever text container you will add then) floating between the two divs [id="home-colour-one" and id="home-colour-two"], and centered vertically, a solution would be adding this ad the end of your CSS:
/* ADD THIS!!!*/
#home-colour-one h3 {
position: absolute;
top:50%; left:16.5%;
transform: translateY(-50%);
}
Here a JS Bin: https://jsbin.com/ralicul/edit?html,css,output
I'm trying to figure out why I can't fill this spot, despite trying many things I have been unable to figure out how to fix it. I tried padding the top, but to no avail. I have provided the code below as well as a picture of the space I'm talking about. In the picture there's a white space between the header 2 and the gray area that has a brief summary. I have tried padding and also increasing the height of the background color, but it doesn't seem to work. Thank you in advance for reading this and I really do thank you for taking the time to help me figure this out.
$(document).ready(function()){
$("figure img + figcaption").prev().addClass('hasCaption');
});
.body{
margin: 0px;
}
.homeButton{
width: 40px;
}
#MidPort{
background-image: url("http://www.geocities.ws/spahealthcare/pic/dark-green-home-button.png");
background-size:cover;
position:absolute;
margin-left:1565px;
bottom:10px;
}
.topnav{
font-size: 20px;
font-family: Times New Roman;
position:fixed;
top 0;
width:100%;
}
#bg2{
background-color:red;
}
ul{
list-style-type:none;
margin:0;
padding:0;
overflow: hidden;
background-color: #333
}
li{
float:left;
border-right:1px solid #bbb;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: red;
}
.active{
background-color:#4CAF50;
}
li a:hover:not(.active)
{
background-color: #111;
}
li:last-child{
border-right:none;
}
#margintop1{
margin-top: .5cm;
font-family: Gadget;
}
.jumbotron{
height:175px;
background-color:#808080;
}
hr.style17 {
border-top: 1px solid #8c8b8b;
text-align: center;
}
hr.style17:after {
content: '§';
display: inline-block;
position: relative;
top: -14px;
padding: 0 10px;
background: #f0f0f0;
color: #8c8b8b;
font-size: 18px;
-webkit-transform: rotate(60deg);
-moz-transform: rotate(60deg);
transform: rotate(60deg);
}
img.hasCaption {
padding-bottom: 50px;
}
figcaption {
position: absolute;
left: 14px;
right: 14px;
bottom: 16px;
background-color: white;
text-align: center;
color: blue;
font-family: 'Reenie Beanie', cursive;
font-size: 30px;
padding: 10px;
}
figure {
display: inline-block;
position: relative;
left: 0;
-moz-transform:rotate(-5deg);
-webkit-transform:rotate(-5deg);
-ms-transform:rotate(-5deg);
transform:rotate(-5deg);
}
img {
border-color: white;
border-width: 15px;
-moz-border-image: url(http://tobias-reinhardt.de/img/frame.png) 15 stretch;
border-image: url(http://tobias-reinhardt.de/img/frame.png) 15 stretch;
border-style: solid;
margin: auto;
}
#imgR{
margin-left:1285px;
height:400px;
}
font{
font-family:Gadget;
}
section{
background-color:#00FFFF;
margin-bottom:10cm;
font-family:Gadget;
}
}
<!-- Check to see if the navigation bar remains at the bottom if I use the nav class instead of ul. If not, revert back to ul for when the user scrolls down-->
<div>
<header>
<!--<div class="container">-->
<h2 class="topnav" id="cs2">
<ul>
<li><a class="active" href="/home">Home</a></li>
<li>About Me</li>
<li>Contact</li>
<li id="MidPort"></li>
</ul>
</h2>
</header>
</div>
<body>
<div class="intro-text">
<div class="jumbotron">
<div>
<p id="margintop1"style="margin-right:200px;">
<font color="white">Front-End Developer and Economist, with experience in project management, machine learning, and leadership roles; devoted to functional programming and analyzing mathematical models to solve emerging economic problems
</font>
</p>
<hr class="style17"/>
</div>
<figure>
<img src="http://i.maniadb.com/images/artist/116/116122.jpg" id="imgR">
</figure>
</div>
</div>
<div id="midSec">
<section>
<h2>
<center>
<font color="#2F4F4F" size="20">
Portfolio
</font>
</center>
</h2>
</section>
</div>
</body>
<!--setup a home button at the bottom-->
[![Space is in between Portfolio and the brief summary][1]][1]
You're using an h2 in your code that has a margin.
h2{margin: 0;}
This will fix it.
h2{margin-top:0}
will fix the issue
h2 by default has a margin top . Remove that.
Also, your HTML is not correct . ( that's why i post this as an answer, to explain to the op the problems from his html )
The biggest problem is that you nested ul inside h2 . This practice is not valid.
As stated in the doc
Most elements that are categorized as phrasing content can only contain elements that are themselves categorized as phrasing content, not any flow content.
Heading tags like h1,h2 etc. are pharsing content, ul is a flow content . So you cannot put ul inside h2
You can check your HTML here > HTML validator and check docs here > documentation
Second problem is that you write <li>About Me</li>
So you first open li, then a but you close first the li and then the a. You need to close the a before closing the li. a being a child of li . Correct form :
<li>About Me</li>
Another problem is using tags that are no longer supported in HTML5 . font,center . ( also the use of size is not supported either) You either use inline styles for example <h2 style="font-size:10px;text-align:center"> or you can use CSS styles separately .
These are just the problems i see from a first look over your code
So I'm using Foundation 6 to prototype a project and I'm noticing that top-bar, top-bar-left, and top-bar-right work just as shown on the docs page except when I want to wrap the left and right bars so that they don't touch the sides.
Both top-left-bar and top-right-bar take up the whole width of the top-bar area each and then end up stacking on top of each other. I want them to look like they do in the code pen link below:
(its linked with foundation 6.0.5, and I'm using 6.4.1 - couldn't find a link for that version)
https://codepen.io/mgrosen/pen/RgEVvY
relevant code from app.css
.wrap {
width: 90%;
max-width: 1100px;
margin: 0 auto;
}
.nav-desktop {
background-color: #222;
height: 80px;
padding: 0;
}
.site-logo {
color: white;
line-height: 80px;
}
.nav-desktop .menu-desktop {
line-height: 80px;
background-color: transparent;
}
.nav-desktop a {
display: inline-block;
}
.menu-desktop > li > a {
display: inline-block;
line-height: 80px;
padding-top: 0;
padding-bottom: 0;
color: white;
}
.menu-desktop > li > a:hover {
background-color: rgba(255,255,255, 0.1);
}
relevant index.html code
<nav class="top-bar nav-desktop" id="responsive-menu">
<div class="wrap">
<div class="top-bar-left">
<h3 class="site-logo">Site Logo</h3>
</div>
<div class="top-bar-right">
<ul class="menu menu-desktop">
<li>Home</li>
<li>About</li>
<li>Foundation Examples</li>
</ul>
</div>
</div>
</nav>
That's the actual code I'm using, but when open index.html to look at it (or run my flask application and view it on local host) this is what i see when I'm scrolled all the way to the top of the screen.
Anybody know why this is happening or how I might debug it with dev tools?
Thanks!
How to create menu like on the picture?
For now I have:
<div id="nav">
<nav class="top-nav">
<div class="shell">
HOMEPAGE<span></span>
<span class="top-nav-shadow"></span>
<ul>
<li class="active"><span>home</span></li>
<li><span>services</span></li>
<li><span>projects</span></li>
<li><span>solutions</span></li>
<li><span>jobs</span></li>
<li><span>blog</span></li>
<li><span>contacts</span></li>
</ul>
</div>
</nav>
</div>
And my css for div nav:
#nav{
background-color: transparent;
padding: 0em 0em 0em 2em;
white-space: nowrap;
list-style: none outside none;
margin: 0px;
height: auto;
line-height: normal;
}
How to style this? I'm newbie
From your picture i think you are looking for a way to make Tabs not a menu..
The best thing you can use i think is jQuery Tabs
From that link you can check how to make it using simple html and the jQueryUI css.
If you want to use only css and html kindly check this
How to make a simple tabbed menu with CSS and HTML
I created an example.
Please have a look at it.
Working Fiddle
The main concept this is positioning the li tags on ul.
Giving bottom: -1px to the li tags to let them come on the border of the ul.
If you give li border-bottom then it looks like border of ul.
I hope you can create your own styling by referring this (but not copying the code).
Here's a jsFiddle showing the styles you want.
The LI tags are floated left, and overflow: hidden; is set on the parent UL tag to contain the floats.
The entire UL tag is shifted down position: relative; margin-bottom: -1px; over the top of the element below it. The 1 pixel borders under the A tags give the illusion that the tab is part of the element below. The border-bottom-color on the active tab is set to match the background color of the content area.
The A tags are set as display: block; so that they can be given a min-width, text-align: center; and vertical padding
I also put a small border-radius on the A tags for flair :-p This can be removed if you don't want it.
I'm assuming the class .active will be changed by code running on your server. If not, the JS listed in several of the above answers will change the class when a tab is clicked. Some of the answers only change the class on the tab (which isn't really what you want…), so look at the libraries instead (however, the CSS will need to be modified accordingly as most JS tab libraries require a specific HTML structure). If you need further details, please leave a comment below.
You'll need a few js to do it.
Here is an example which doesn't require any framework, and fit to your needs (using jQuery) :
$('#tab-nav > li').click(function(e) {
// get new active pane id
var idPane = $(this).find('a:first').attr('href').substring(1);
// change active nav
$('#tab-nav > li').removeClass('active');
$(this).addClass('active');
// change active pane
$('.tab-pane').removeClass('active');
$('#'+idPane).addClass('active');
});
.clear { display: block; clear: both; height: 0px; }
#container {
position: relative;
color: #497188;
}
#tab-nav {
position: relative;
z-index: 20;
}
#tab-nav > li {
display: block;
border: 1px solid #497188;
border-bottom: 1px solid #497188;
padding: 1px 3px;
margin: 0 2px -1px;
float: left;
}
#tab-nav > li a {
color: #497188;
text-decoration: none;
}
#tab-nav > li.active,
#tab-content {
background: #DEE7EC;
border-bottom: 1px solid #DEE7EC;
}
#tab-content {
position: relative;
clear: both;
border: 1px solid #497188;
z-index: 10;
}
.tab-pane {
display: none;
position: absolute;
top: 0;
left: 0;
padding: 3px;
}
.tab-pane.active {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="container">
<ul id="tab-nav">
<li class="active"><span>home</span></li>
<li><span>services</span></li>
<li><span>projects</span></li>
<li><span>solutions</span></li>
<li><span>jobs</span></li>
<li><span>blog</span></li>
<li><span>contacts</span></li>
</ul>
<div id="tab-content">
<div id="home" class="tab-pane active">home</div>
<div id="services" class="tab-pane">services</div>
<div id="projects" class="tab-pane">projects</div>
<div id="solutions" class="tab-pane">solutions</div>
<div id="jobs" class="tab-pane">jobs</div>
<div id="blog" class="tab-pane">blog</div>
<div id="contacts" class="tab-pane">contacts</div>
<p class="clear"> </p>
</div>
</div>