I have navbar for all the sections on the site.
when it's mobile view this navbar is one line with a scroll.
I want to scroll this navbar auto when I scroll the page down to the section.
can I achieve that without using sliders?
.wrapper {
width: 360px;
height: 720px;
border: 1px solid #000;
}
ul {
list-style-type: none;
padding: 10px 0;
margin: 10px 0;
display: flex;
background: #ccc;
}
li {
margin: 0 8px;
}
<div class="wrapper">
<ul>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
</ul>
</div>
html, body {
margin: 0px;
padding: 0px;
}
header {
width: 100%;
position: fixed;
background-color: rgba(0, 0, 0, 0.7);
}
nav {
max-width: 700px;
margin: 0 auto;
padding: 4px;
}
nav a {
color: white;
padding: 2px;
}
.content-container {
max-width: 700px;
margin: 0 auto;
}
.section-content {
padding: 10px 0px;
}
.flex-container {
display: flex;
justify-content: space-around;
}
.flex-column {
width: 150px;
height: 150px;
background-color: yellow;
margin: 2.5px;
display: inline-block;
}
<header>
<nav>
Section1
Section 2
Section 3
Section 4
</nav>
</header>
<div class="content-container">
<div class="section-content" id="first">
<h3>Section 1</h3>
<div class="flex-container">
<p class="flex-column">Hello world!</p>
<p class="flex-column">Hello world!</p>
<p class="flex-column">Hello world!</p>
<p class="flex-column">Hello world!</p>
</div>
</div>
<div class="section-content" id="second">
<h3>Section 2</h3>
<div class="flex-container">
<p class="flex-column">Hello world!</p>
<p class="flex-column">Hello world!</p>
<p class="flex-column">Hello world!</p>
<p class="flex-column">Hello world!</p>
</div>
<p>Item of div section 2.</p>
</div>
<div class="section-content" id="third">
<h3>Section 3</h3>
<p>Item of div section 3.</p>
</div>
<div class="section-content" id="fourth">
<h3>Section 4</h3>
<p>Item of div section 4.</p>
</div>
</div>
<script type = "text/javascript">
$(document).ready(function(){
$('a[href^="#"]').on('click', function (e) {
e.preventDefault();
var target = this.hash;
var $target = $(target);
$('html, body').animate({
'scrollTop': $target.offset().top
}, 1000, 'swing');
});
});
</script>
Working code by me
Related
I've created horrible-looking demonstration of my current issue. The Question is, how can I have overflow-y as scroll, and overflow-x visible, while expandable content remains visible for all it's size (without been cut by end of div)?
In this example, expandable content shows in its full size without overflow, but with overflow, it is just cut with border. Tried the workaround with wrapper, but actually it's not working at all :(
body {
background-color: cyan;
}
.leftnav {
width: 8em;
height: 5em;
padding-right: 7em;
background-color: green;
color: white;
overflow-y: scroll;
overflow-x: visible;
direction: rtl;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
color: black;
display: none;
position: absolute;
left: 5em;
top: -1em;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 8px;
z-index: 2;
}
.dropdown:hover .dropdown-content {
display: block;
}
<body>
<p></p>
<div class="leftnav">
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</body>
Ok, with playing around and a bit of googling, this is not possible without JavaScript. You can get it outside, however, the element loses its actual position if you scroll. It is quite an interesting problem, more on it you can find here and problems solution.
$(function() {
// whenever we hover over a menu item that has a submenu
$('.dropdown').on('mouseover', function() {
var $menuItem = $(this),
$submenuWrapper = $('> .dropdown-content', $menuItem);
// grab the menu item's position relative to its positioned parent
var menuItemPos = $menuItem.position();
// place the submenu in the correct position relevant to the menu item
$submenuWrapper.css({
top: menuItemPos.top,
left: menuItemPos.left + Math.round($menuItem.outerWidth() * 0.75)
});
});
});
body {
background-color: cyan;
position: relative;
}
.wrapper {position: relative;}
.leftnav {
width: 8em;
height: 5em;
padding-right: 7em;
background-color: green;
color: white;
overflow-y: scroll;
overflow-x: visible;
direction: rtl;
}
.dropdown {
display: inline-block;
}
.dropdown-content {
color: black;
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 8px;
z-index: 2;
}
.dropdown:hover .dropdown-content {
display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<p></p>
<div class="wrapper">
<div class="leftnav">
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<br>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
</div>
</div>
</body>
This question already has answers here:
Text floating in block next to image
(6 answers)
Closed 2 years ago.
I am new to html + css and I can't seem to figure out how you place items horizontally despite reading a couple articles. What I am going for is having two lines of text on the right side of my image. Currently I have everything placed vertically.
Html:
#content {
max-width: 640px;
margin: 0 auto;
padding: 64px 24px;
}
.section {
padding-bottom: 48px;
margin-bottom: 48px;
border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.section:last-of-type {
border-bottom: 0;
padding-bottom: 0;
margin-bottom: 0;
}
.img {
width: 200px;
height: 200px;
border-radius: 40px;
margin-bottom: 12px;
}
```
<body>
<div id="content">
<div class="section">
<img src="Images/Logo.png" class="img">
<h1>Placeholder</h1>
<h2>Placeholder 2</h2>
</div>
<div class="section">
<h6>Projects</h6>
<ul>
<li>
<h3>Placeholder</h3>
<p> Placeholder </p>
</li>
<li>
<h3>Placeholder </h3>
<p> Placeholder </p>
</li>
</ul>
</div>
</div>
</body>
I am not sure if I am sharing everything I need too, Here's the GitHub repo with all the code if you need it.
You can use display: flex; property.
/* ↓ new styling ↓ */
.section-horizontal {
display: flex;
}
.description {
margin-left: 32px;
}
/* your styling */
#content {
max-width: 640px;
margin: 0 auto;
padding: 64px 24px;
}
.section {
padding-bottom: 48px;
margin-bottom: 48px;
border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.section:last-of-type {
border-bottom: 0;
padding-bottom: 0;
margin-bottom: 0;
}
.img {
width: 200px;
height: 200px;
border-radius: 40px;
margin-bottom: 12px;
}
<div id="content">
<div class="section section-horizontal"> <!-- class for flexbox -->
<img src="Images/Logo.png" class="img">
<div class="description"> <!-- add this block to align headings vertically -->
<h1>Placeholder</h1>
<h2>Placeholder 2</h2>
</div>
</div>
<div class="section">
<h6>Projects</h6>
<ul>
<li>
<h3>Placeholder</h3>
<p> Placeholder </p>
</li>
<li>
<h3>Placeholder </h3>
<p> Placeholder </p>
</li>
</ul>
</div>
</div>
try to get in touch with the flex property. It will make things alot more simple :)
html:
<body>
<div id="content">
<div class="section">
<img src="Images/Logo.png" class="img">
<div class="flex">
<h1>Placeholder</h1>
<h2>Placeholder 2</h2>
</div>
</div>
</div>
</body>
css:
.flex {
display: flex;
}
You can do with flexbox like this
#content {
max-width: 640px;
margin: auto;
padding: 64px 24px;
display:flex;
flex-wrap:wrap;
justify-content: space-evenly;
}
.section {
padding-bottom: 48px;
margin-bottom: 48px;
border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.section:last-of-type {
border-bottom: 0;
padding-bottom: 0;
margin-bottom: 0;
}
.img {
width: 200px;
height: 200px;
border-radius: 40px;
margin-bottom: 12px;
}
<body>
<div id="content">
<div class="section">
<img src="Images/Logo.png" class="img">
<h1>Placeholder</h1>
<h2>Placeholder 2</h2>
</div>
<div class="section">
<h6>Projects</h6>
<ul>
<li>
<h3>Placeholder</h3>
<p> Placeholder </p>
</li>
<li>
<h3>Placeholder </h3>
<p> Placeholder </p>
</li>
</ul>
</div>
</div>
</body>
I have a navbar that looks like this:
but when i added position: fixed on the header, the width changed and become like this:
Here is my index.html
<header>
<div class="logo-container">
<img src="https://i.ya-webdesign.com/images/rocket-logo-png-4.png" alt="logo" class="logo">
<h4>Rockode</h4>
</div>
<nav>
<ul class="nav-links">
<li class="nav-link active">Beranda</li>
<li class="nav-link">Produk</li>
<li class="nav-link">Pengembang</li>
<li class="nav-link">Kontak</li>
</ul>
</nav>
<div class="header-right">
<button class="btn btn-sign-up">Daftar</button>
<button class="btn btn-sign-in">Masuk</button>
</div>
</header>
<main>
<div class="content">
<article>This is article</article>
<article></article>
</div>
<aside></aside>
</main>
and here is style.css
main {
background-color: white;
height: 720px;
z-index: 1;
position: relative;
padding-top: 188px;
}
header {
display: flex;
padding: 30px 10%;
height: 88px;
align-items: center;
justify-content: space-between;
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.075);
z-index: 2;
position: fixed;
background: white;
}
Not 100% sure what the problem is, but I just added this and it works fine...
main {
position: relative;
padding-top: 88px
}
header {
position: fixed;
}
See fiddle: https://jsfiddle.net/8ktxzfvL/
That was my bad for didn't notice the width value on header section.
It solved by declaring width: 100%.
I need to create equal height cards using flexbox or any other methods in css. But one of those cards will have a ribbon on top of the card. That will be set dynamically in react.
So I need to create equal height cards except one. Something like below,
An example is here,
https://codepen.io/andichamy-ga/pen/MGJPXv
HTML:
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar<br>
foo
</div>
</div>
<div class="some">
<div class="recommended">Recommended Card</div>
<div class="box">
foo<br>
</div>
</div>
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar
</div>
</div>
</div>
CSS:
.container {
display: flex;
}
.some {
padding: 20px;
margin-right: 20px;
}
.recommended {
background-color: yellow;
width: 200px;
height: 20px;
padding: 5px 10px;
}
.one {
background-color: transparent;
}
.box {
width: 200px;
height: 150px;
background-color: green;
padding: 10px;
}
I tried in many different ways. But none of those seems like a proper way. How can I do this elegantly?
You can make the top ribbon to be absolute position and rely on flexbox for the remaining to have equal height:
* {
box-sizing:border-box;
}
body {
background-color: #a3d5d3;
}
.container {
display: flex;
}
.some {
margin-top:50px;
margin-right: 30px;
position:relative;
}
.recommended {
position:absolute;
background-color: yellow;
left:0px;
right:0px;
height: 40px;
top:-40px;
padding: 5px 10px;
}
.one {
background-color: transparent;
}
.box {
width: 200px;
height:100%;
background-color: green;
padding: 10px;
}
<div class="container">
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br> bar
<br> foo bar
<br> foo bar
<br>
</div>
</div>
<div class="some">
<div class="recommended">Recommended Card</div>
<div class="box">
foo<br>
</div>
</div>
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br> bar
</div>
</div>
</div>
You want something like a price table, more in number like below.
https://jsfiddle.net/rdggv429/
<h2 style="text-align:center">Responsive Pricing Tables</h2>
<p style="text-align:center">Resize the browser window to see the effect.</p>
<div class="columns">
<ul class="price">
<li class="header">Basic</li>
<li class="grey">$ 9.99 / year</li>
<li>10GB Storage</li>
<li>10 Emails</li>
<li>10 Domains</li>
<li>1GB Bandwidth</li>
<li class="grey">Sign Up</li>
</ul>
</div>
<div class="columns special">
<ul class="price">
<li class="special-li">Special</li>
<li class="header" style="background-color:#4CAF50">Pro</li>
<li class="grey">$ 24.99 / year</li>
<li>25GB Storage</li>
<li>25 Emails</li>
<li>25 Domains</li>
<li>2GB Bandwidth</li>
<li class="grey">Sign Up</li>
</ul>
</div>
<div class="columns">
<ul class="price">
<li class="header">Premium</li>
<li class="grey">$ 49.99 / year</li>
<li>50GB Storage</li>
<li>50 Emails</li>
<li>50 Domains</li>
<li>5GB Bandwidth</li>
<li class="grey">Sign Up</li>
</ul>
</div>
* {
box-sizing: border-box;
}
.columns {
float: left;
width: 33.3%;
padding: 8px;
}
.price {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
-webkit-transition: 0.3s;
transition: 0.3s;
margin-top: 50px;
position: relative;
}
.price:hover {
box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.2)
}
.price .header {
background-color: #111;
color: white;
font-size: 25px;
}
.price li {
border-bottom: 1px solid #eee;
padding: 20px;
text-align: center;
}
.price .grey {
background-color: #eee;
font-size: 20px;
}
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
font-size: 18px;
}
.special-li {
position: absolute;
top: -60px;
border: 1px solid #ccc;
width: 100%;
}
#media only screen and (max-width: 600px) {
.columns {
width: 100%;
}
}
If you want the header dynamically, give it on the page load, append the LI to the first element on the UL
HTML
<div class="some-all">
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar<br>
foo
</div>
</div>
<div class="some">
<div class="recommended">Recommended Card</div>
<div class="box">
foo<br>
</div>
</div>
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar
</div>
</div>
use css
<style>
.some-all{display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.some-all .some{
background-color: green;
}
</style>
I don't think that can be possible with flexbox, but this could be a possible solution for your question, hope it might help you.
You can also view it on Codepen: https://codepen.io/techyogi/pen/ervNWW
CSS
$blue: #a3d5d3;
body {
background-color: $blue;
}
.container {
display: flex;
padding-top: 20px;
}
.some {
padding: 20px;
margin-right: 20px;
position:relative;
}
.recommended {
position: absolute;
background-color: yellow;
width: 200px;
height: 20px;
padding: 5px 10px;
margin-top: -30px;
}
.one {
background-color: transparent;
}
.box {
width: 200px;
height: 100%;
background-color: green;
padding: 10px;
}
HTML
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar<br>
foo
</div>
</div>
<div class="some">
<div class="recommended">Recommended Card</div>
<div class="box">
foo<br>
</div>
</div>
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar
</div>
</div>
</div>
I'm running into an issue where I have two navigation menu's on the same page. I want both to be shown separately in which one involves being a sticky navigation. I want this one hidden until I scroll down and cant see the other that appears. Is there a way we can make this work?
<!-- Start Sticky Navigation -->
<nav id="mainnav">
<div class="container">
<div class="row">
<div class="span4">
<img src="img/logo2.png" alt="LOGO">
</div>
<div class="span8">
<ul id="fluid-nav" class="fluid-navigation visible-desktop">
<li class="current">Top</li>
<li>Overview</li>
<li>Gallery</li>
<li>No Compromises</li>
<li><button class="btnbuy small">Select & Buy</button></li>
</ul>
</div>
</div>
</div>
</nav>
<!-- End Sticky Navigation -->
CSS
nav#mainnav {
width: 100%;
height: 50px;
background-color: #cb0000;
overflow: hidden;
position: relative;
z-index: 999;
}
I Dont Actually get the full detail of what u What but this is Something i came up with
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="main">
</div>
<div id="float">
<div class="m">menu1</div>
<div class="m">menu2</div>
<div class="m">menu3</div>
<div class="m">menu4</div>
</div>
<div class="foot">
<div class="m">menu1</div>
<div class="m">menu2</div>
<div class="m">menu3</div>
<div class="m">menu4</div>
</div>
<div class="main">
</div>
</div>
</div>
Here is the Css
<style type="text/css">
#float{
background: #09C;
position:absolute;
right:60px;
top:20px;
width:90%;
padding:10px;
border-radius: 6px;
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.43);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.43);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.43);
}
.m{
display: inline-block;
}
.float_content_head{
padding:10px;
border-bottom: 1px solid #efefef;
text-align:center;
}
.float_content{
padding-top:10px;
}
.main{
height: 800px;
margin: 0 auto;
border:1px solid #efefef;
padding: 10px;
background:#ccc;
}
.foot{
background:#09F;
width: 90%;
margin: 0 auto;
border:1px solid #efefef;
padding: 10px;
border-radius: 6px;
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.43);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.43);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.43);
}
#box p{
margin:0;
padding:0;
}
</style>
And .js
<script type="text/javascript">
$(document).ready(function() {
var starting_position = $('#float').offset();
var top_padding = 20; // Distance from top while scrolling
var bottom_limit = $('.foot').offset();
var box_height = $('#float').height() + 15; // Distance from top
$(window).scroll(function(){
var top_window = $(window).scrollTop();
if (top_window > starting_position.top && top_window < bottom_limit.top - box_height){
$('#float').stop().animate({top: top_window - starting_position.top + top_padding}, 0); //0 makes it sticky
} else if (top_window > bottom_limit.top - starting_position.top - box_height){
$('#float').stop().animate({top: bottom_limit.top - starting_position.top - box_height }, 0);
} else { $('#float').stop().animate({top: 10 }, 400);
}
});
});
</script>
And fiddle Here
You can do this easily by using position:sticky for your headers.
Here is my code:
nav {
position: sticky;
top: 0
}
/* This just makes your navbar look good as I didn't know what library you were using. */
.fluid-navigation {
margin: 0;
padding: 0;
}
.fluid-navigation li {
display: inline;
padding-left: 0.3em;
margin: 0;
}
.row {
display: flex;
flex-direction: row;
}
nav {
background: #222;
padding: 1em 0.5em;
}
.contentBody {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 200vh;
}
a {
color: yellow
}
a:hover {
color: royalblue
}
body {
padding: 0;
margin: 0;
<body>
<div class="content">
<nav id="mainnav">
<div class="container">
<div class="row">
<div class="span4">
<img src="img/logo2.png" alt="LOGO">
</div>
<div class="span8">
<ul id="fluid-nav" class="fluid-navigation visible-desktop">
<li class="current">Top</li>
<li>Overview</li>
<li>Gallery</li>
<li>No Compromises</li>
<li><button class="btnbuy small">Select & Buy</button></li>
</ul>
</div>
</div>
</div>
</nav>
Scroll to the bottom
<div class="contentBody">Content 1<br>Keep Scrolling<br>Content 1<br></div>
</div>
This Navbar will push the top navbar and take its place.
<div class="content">
<nav id="mainnav">
<div class="container">
<div class="row">
<div class="span4">
<img src="img/logo2.png" alt="LOGO2">
</div>
<div class="span8">
<ul id="fluid-nav" class="fluid-navigation visible-desktop">
<li class="current">Top2</li>
<li>Overview2</li>
<li>Gallery2</li>
<li>Compromises2</li>
<li><button class="btnbuy small">Select & Buy</button></li>
</ul>
</div>
</div>
</div>
</nav>
Scroll to the bottom
<div class="contentBody">Content 2<br>Keep Scrolling<br>Peace 🖖.<br></div>
</div>
Hope this helps.
Peace 🖖.