floating a list within a div - css

I want to do a collapsible button that opens a list of items when clicked, I'm trying to float the elements left within the button but it's not seem to be working.
.collapsible-group {
overflow: hidden;
}
.collapsible-content {
float: left;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
display: block;
}
.collapsible {
color: black;
cursor: pointer;
padding: 18px;
width: 33%;
border: none;
text-align: center;
outline: none;
font-size: 15px;
background-color: Transparent;
display: block;
margin: auto;
}
<div class="collapsible-group">
<button class="collapsible">Modern Trade</button>
<div class="collapsible-content">
<ul>
<li>num 1</li>
<li>num2</li>
<li>num3</li>
<li>num4</li>
</ul>
</div>
</div>

Please try the following
<div class="collapsible-content">
<ul class=my-float"> <li>num 1</li>
<li>num2</li>
<li>num3</li>
<li>num4</li></ul>
// in your css file add this
.my-float li{
float:left;
}

You need Javascript to detect the button click and then do something with it. This code adds a class to the div containing the menu and changes the maximum height.
const myButton = document.getElementsByTagName("button")[0];
myButton.onclick = () => {
const menu = document.getElementsByClassName("collapsible-content")[0];
menu.classList.toggle("showMenu");
}
.collapsible-group {
overflow: hidden;
}
.collapsible-content {
float: left;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
display: block;
}
.collapsible-content.showMenu {
max-height: 1000px;
}
.collapsible {
color: black;
cursor: pointer;
padding: 18px;
width: 33%;
border: none;
text-align: center;
outline: none;
font-size: 15px;
background-color: Transparent;
display: block;
margin: auto;
}
<div class="collapsible-group">
<button class="collapsible">Modern Trade</button>
<div class="collapsible-content">
<ul>
<li>num 1</li>
<li>num 2</li>
<li>num 3</li>
<li>num 4</li>
</ul>
</div>
</div>

Related

How to do margin-top only in Firefox browser

I have menu bar which need to be margin-top: 150px;
But visually in Firefox looking different as on Chrome.
Header code: https://codepen.io/bugerman21/pen/rNxvyOv
Chrome:
Correct display
Firefox:
Incorrect display
HTML:
<nav>
<ul class="nav">
<li class="category"><span>Category <i class="fas fa-sort-down"></i></span>
<ul>
<li>Qwerty 1</li>
<li>Qwerty 2</li>
<li>Qwerty 3</li>
<li>Qwerty 4</li>
</ul>
</li>
<li>Cuntact us</li>
<li>FAQ</li>
</ul>
CSS:
* {
margin: 0;
pading: 0;
}
.nav li ul {
position: absolute;
margin-top: 150px;
min-width: 150px;
list-style-type: none;
display: none;
}
How to do margin-top only for the Firefox browser?
Unsuccessful attempt:
#-moz-document url-prefix() {
.nav li ul {
margin-top: 150px;
}
}
Here ya go buddy, sorry I left for the day yesterday but see the changes made and I left outlines on the elements to give a better visual reference. As it is now it will display as expected on all browsers even old internet explorer. Although you could accomplish the same thing cleaner overall, this at least gets you back on track. Cheers and welcome to StackOverflow! :)
PS : since the nav menu items don't have a fixed height you might want to consider making that something static so you can change the top: 56px to a value that places the drop down consistently no matter the width of the screen. If you make the example full screen you'll see what I mean.
header {
display: flex;
margin: 0;
padding: 0 20px;
justify-content: space-between;
align-items: center;
background-color: silver;
}
.header {
grid-area: header;
background-color: #1f1f1f;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
/*---------- Logo ----------*/
.logo {
font-family: 'Gentium Book Basic', serif;
font-size: 2.5em;
color: #808080;
}
/*---------- Nav menu ----------*/
.nav {
list-style-type: none;
display: flex;
justify-content: flex-start;
margin: 0;
}
.nav > li {
text-decoration: none;
font-family: 'Roboto', sans-serif;
color: #ffffff;
transition: background-color .25s ease;
}
.nav a {
display: block;
padding: 20px;
color: #ffffff;
font-size: 1em;
}
.category {
padding: 0 20px;
display: flex;
align-items: center;
position: relative;
overflow: visible;
border: red 1px solid;
}
/*---------- Sub menu ----------*/
.nav li ul {
position: absolute;
top: 56px;
left: 0;
min-width: 150px;
margin: 0;
padding: 0;
list-style-type: none;
display: none;
border: green 1px solid;
}
.nav li > ul li {
border-bottom: 1px solid #ffffff;
background-color: #1f1f1f;
}
.nav li > ul li a {
text-transform: none;
}
.nav li:hover > ul {
display: block;
}
.nav > li:hover {
background-color: #404040;
/* box-shadow: -5px 5px #1f1f1f; */
}
.nav li ul > li:hover {
background-color: #404040;
}
/*---------- Search & Profile----------*/
.search_and_profile {
display: flex;
align-items: center;
}
.search_and_profile > p {
margin: 0;
color: #ffffff;
}
.search-container button {
float: right;
padding: 6px 10px;
background: #e0e0e0;
font-size: 17px;
border: none;
cursor: pointer;
}
.search-container input[type=text] {
padding: 6px;
font-size: 17px;
border: none;
}
<header class="header">
<span class="logo">Qwerty</span>
<nav>
<ul class="nav">
<li class="category"><span>Category <i class="fas fa-sort-down"></i></span>
<ul>
<li><a href=#>Qwerty 1</a></li>
<li>Qwerty 2</li>
<li>Qwerty 3</li>
<li>Qwerty 4</li>
</ul>
</li>
<li>Cuntact us</li>
<li>FAQ</li>
</ul>
</nav><!-- .nav -->
<div class="search_and_profile">
<div class="search-container">
<form action="#">
<input type="text" placeholder="Search.." name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div><!-- .search-container -->
</div><!-- .search_and_profile -->
</header>
It will work for me, additionally i included color too to make sure.
Also you try this option too
#media screen and (-moz-images-in-menus:0) {
/* your style */
}
* {
margin: 0;
pading: 0;
}
.nav li ul {
position: absolute;
margin-top: 150px;
min-width: 150px;
list-style-type: none;
display: none;
}
/* Added */
#-moz-document url-prefix('') {
.nav li ul {
margin-top: 150px;
color: orange;
}
}
<div class="nav">
<ul>
<li>Home</li>
<li>About
<ul>
<li>Some text</li>
<li>Some more text</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>

Nav bar will not move up to be even with the img at the top using CSS dreamweaver

I have a logo image on the upper left side of the site and want my nav to show on the upper right side of the site. The nav is showing on the right side of the page but instead of being parallel to the logo it is below it even thought the logo is on the left side. Any idea what I am missing in the code below that is preventing the nav from moving up.
#charset 'UTF-8';
html,
html * {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: arial, sans-serif;
<!-- font-size: 1vw;>
background: white;
}
img {
width: 100%;
max-width: 100%;
height: auto;
vertical-align: middle;
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
a, a:visited {
color: inherit;
}
header {
position: fixed;
padding: 1.5em;
top: 0;
left: 0;
width: 100%;
z-index: 1000;
}
.site-logo {
width: 30%;
max-width: 30%;
position: relative;
display: block;
}
.site-logo img {
width: 22em;
}
.logo {
opacity: 1;
}
.site-nav {
position: relative;
float: right;
z-index: 400;
top: 0;
left: 0;
display: block !important;
width: 68%;
padding: .75em 1em 0 0;
opacity: .95;
background: none;
}
.site-nav ul {
list-style-type: none;
margin: 0;
text-align: right;
}
.site-nav ul li {
display: inline-block;
margin-bottom: 0;
margin-left: 1.5em;
}
.site-nav ul li a {
font-size: .85em;
padding-bottom: .5em;
text-decoration: none;
letter-spacing: .15em;
text-transform: uppercase;
color: #000000;
-webkit-transition: color .3s;
transition: color .3s;
}
.site-nav ul li a:hover {
outline: none;
border-bottom: 1px solid black;
}
HTML
<header>
<!-- Logo -->
<a class="site-logo">
<img class="logo" src="images/SBI Logo.png" alt=""/>
</a>
<!-- Navigation Menu -->
<nav class="site-nav">
<ul>
<li>Home</li>
<li>Rooms</li>
<li>Gift Certificates</li>
<li>About Us</li>
<li>Things To Do</li>
<li>Contact Us</li>
<li>Blog</li>
</ul>
</nav>
</header>
enter image description here
You are getting bogged down in the style sheet and using EM too, it would be much easier for you to use PIXELS instead of EM to position your elements.
<style>
.mysitelogo
{
margin-top: 16px;
width: 458px;
height: 114px;
}
.mysitenav
{
float: right;
padding: 8px;
opacity: .95;
}
</style>
<header>
<!-- Logo -->
<img class="mysitelogo" src="logo.gif" alt="" />
<!-- Navigation Menu -->
<nav class="mysitenav">
<ul>
<li>Home</li>
<li>Rooms</li>
<li>Gift Certificates</li>
<li>About Us</li>
<li>Things To Do</li>
<li>Contact Us</li>
<li>Blog</li>
</ul>
</nav>
</header>
Using the code above you can get the layout you desire, THEN fine tune your layout in the stylesheet.
Some times it is easier to break the bigger problem down into basic parts.
Read this page for better understanding of using EM which is relative to FONT SIZE
https://www.w3schools.com/CSSref/css_units.asp

Menu move effect in CSS

Yo.
I have some question to you guys.
Here is my test code:
*{
border:1px solid #333;
width:100%;
max-width: 1240px;
margin: 0 auto;
}
.menu{
width:60%;
border:1px solid #444;
float:left;
text-align:center
}
.menu ul{
display:flex;
justify-content: center;
flex-flow: row;
float:left;
}
.topnav{
width:50px;
float:left;
}
.topnav:hover,.topnav:focus{
transition: 0.6s linear;
width: 100px;
float:left;
}
.something{
border:1px solid #000;
width: 50px;
float:right;
}
.topnav-something{
display: block;
width: auto;
float:right;
margin-right:20%;
}
<div class="content">
<div class= "menu">
<ul>
<li>ONE</li>
<li>Second</li>
<li>Third</li>
</ul>
</div>
<div>
<div class="topnav-something">
<div class="topnav">
<input type="text" placeholder="Search..">
</div>
<div class="something">
SOME TEXT
</div>
</div>
</div>
How can I receive move-menu effect like on this page?(search hover)
http://kindsgut.de/
And why when I clicked on this input he decreases?
Somebody know how to fix it?
I dont know what I doing wrong.
Have a nice day!
First, you set the transition only on the hovered event, that's why when you mouseout the animation has no transition. So you need to set the transition on the default state not on the hover state of the element.
Second, you should add the hover event on the outer div that contains both the some text and the input . So in your case on the .topnav-something
Also, add width:0 to your input (.topnav) as a initial value. So it can transition from 0 to 100px.
So in the end your code will look like this
( i removed the margin-right:20% from topnav-something so it will fit the small screen of the snippet )
* {
border: 1px solid #333;
width: 100%;
max-width: 1240px;
margin: 0 auto;
}
.menu {
width: 60%;
border: 1px solid #444;
float: left;
text-align: center
}
.menu ul {
display: flex;
justify-content: center;
flex-flow: row;
float: left;
}
.something {
border: 1px solid #000;
width: 50px;
float: right;
}
.topnav-something {
display: block;
width: auto;
float: right;
margin-right: 0%;
}
.topnav {
width: 0px; /*added*/
float: left;
transition: 0.6s linear; /*added*/
}
/*added*/
.topnav-something:hover .topnav {
width: 100px;
}
<div class="content">
<div class="menu">
<ul>
<li>ONE</li>
<li>Second</li>
<li>Third</li>
</ul>
</div>
<div>
<div class="topnav-something">
<div class="topnav">
<input type="text" placeholder="Search..">
</div>
<div class="something">
SOME TEXT
</div>
</div>
</div>
You'd need to set your input to a width of 0 , then depending what you want to trigger it (text, or the container) you define the width on hover.
You can also apply a transition to the container, and to the input for the slide effect.
<div class="content">
<div class="menu">
<ul>
<li>ONE</li>
<li>Second</li>
<li>Third</li>
</ul>
</div>
<div>
<div class="topnav-something">
<div class="topnav">
<input class="search-field" type="text" placeholder="Search..">
</div>
<div class="something">
SOME TEXT
</div>
</div>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.menu {
width: 60%;
float: left;
text-align: right;
outline: 1px solid red;
}
.menu ul {
display: flex;
justify-content: right;
flex-flow: row nowrap;
/* float: left; */
}
.menu li {
display: inline;
padding: 10px;
}
.topnav-something {
/* display: block; */
padding: 10px;
width: 40%;
float: right;
/* margin-right: 20%; */
transition: width 0.5s;
outline: 1px solid blue;
}
.search-field {
width: 0;
transition: all 0.5s;
}
.topnav-something:hover input,
.topnav-something:focus input {
width: 140px;
}
.topnav {
display: inline-block;
}
/* .topnav {
width: 50px;
float: left;
} */
/* .topnav:hover,
.topnav:focus {
transition: 0.6s linear;
width: 100px;
float: left;
} */
.something {
display: inline-block;
/* border: 1px solid #000; */
/* width: 50px; */
/* float: right; */
}
I've created a demo for you here: https://codepen.io/blueocto/pen/zWoNZj
#Mihal If my answer did help solve your issue, I'd really appreciate the upvote, thank you.

Navigation Bar Height and Functionality

So I'm looking at creating a navigation bar that'll sit at the top of my webpage and stick to it no matter where I scroll, but it always gets caught and disappears as I scroll away?
Not only that, but this is what happens when I hover over it:
Is it possible to also only have the darker background fill the actual black bar it sits inside?
This is the snippet from my style sheet as well:
body {
background-color: #ecf0f1;
margin: 0;
font-family: Arial;
}
header {
background-color: #333;
}
.navbar {
height: 5%;
overflow: auto;
margin: auto;
width: auto;
min-height: 60px;
top: 0;
text-align: center;
}
.title {
display: block;
}
.navbar ul {
list-style-type: none;
position: fixed;
top: 0;
padding: 0;
overflow: hidden;
}
.navbar li {
display: inline-block;
}
.navbar li a {
padding: 25px;
display: block;
height: 100%;
color: white;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
.navbar li a:hover {
background-color: #111;
}
All help is greatly appreciated! First time playing around with CSS!
EDIT:
Here is the snippet of HTML that creates this header
<link rel="stylesheet" type="text/css" href="style/style.css">
<header>
<div class="navbar">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Contracts</li>
<li>Other</li>
</ul>
</div>
</header>
Fix the header...not the navbar or the menu.
body {
background-color: #ecf0f1;
margin: 0;
font-family: Arial;
}
header {
background-color: #333;
position: fixed;
top: 0;
width: 100%;
}
.navbar {} .title {
display: block;
}
.navbar ul {
list-style-type: none;
padding: 0;
margin: 0;
overflow: hidden;
}
.navbar li {
display: inline-block;
}
.navbar li a {
padding: 25px;
display: block;
height: 100%;
color: white;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
.navbar li a:hover {
background-color: #111;
}
body {
height: 2000px; /* so you can see the header NOT moving */
}
<header>
<div class="navbar">
<ul>
<li class="hvr-underline">Home
</li>
<li>About Us
</li>
<li>Contracts
</li>
<li>Other
</li>
</ul>
</div>
</header>

Pure CSS Accordion Issue

I'm playing around with a pure CSS accordion http://reversl.net/accordion/ I can get the basic functionality to work (headings 2 & 3 both toggle) But I can't get heading 1 to toggle if I add the same UL to it. Because Heading 1 is styled differently the problem (I think) lies within naming/targeting it's + div ?
Please note: I removed the UL from Heading 1 for the sake of the demo because it was preventing Headings 2 & 3 from toggling.
You made several mistakes. Too many to count:
Here is a working example: Try and see, what I changed
http://jsfiddle.net/HerrSerker/ASqE9/
HTML
<div id="wrap">
<div class="accordion">
<div id="two" class="section">
<h4>
Heading 2
</h4>
<div class="sub_section">
<ul class="list">
<li>Sample Text 1</li>
<li class="last">Sample Text 2</li>
</ul>
</div>
</div><!--#two-->
<div id="four" class="section progress">
<h4>
Heading 4 (With Progress Bar)
</h4>
<div class="metrics">
<div class="meter">
<span style="width: 75%"></span>
</div><!--.meter-->
</div><!--.metrics-->
<div class="sub_section">
<ul class="list">
<li>Sample Text 1</li>
<li class="last">Sample Text 2</li>
</ul>
</div><!--.sub_section-->
</div><!--#one-->
</div><!--accordian-->
</div>​
CSS
#wrap {
width: 320px;
background: #f0f0f0;
margin: auto;
}
.accordion {
clear: both;
padding: 0;
margin: 0 auto;
}
.accordion h4 {
margin: 0;
}
.accordion h4 a {
padding: 1em;
color: #999;
display: block;
font-weight: normal;
text-decoration: none;
}
.accordion h4 a:hover {
text-decoration: none;
background: #111;
}
.accordion .section {
background: #222;
border-bottom: 1px solid #000;
}
.accordion .sub_section {
border-bottom: none;
background: #f0f0f0;
}
.list {
padding: 0;
margin: 0;
}
.list li {
background: url('http://www.placehold.it/40x40') no-repeat;
color: #999;
list-style: none;
padding: .7em .7em .7em 4em;
border-bottom: 1px solid #fff;
}
.list .last {
border-bottom: none;
}
.accordion .sub_section {
height: 0;
overflow: hidden;
-webkit-transition: height 0.3s ease-in;
-moz-transition: height 0.3s ease-in;
-o-transition: height 0.3s ease-in;
-ms-transition: height 0.3s ease-in;
transition: height 0.3s ease-in;
}
.accordion :target h4 a {
text-decoration: none;
font-weight: bold;
}
.accordion :target .sub_section {
height: 80px;
}
.accordion .section.large:target h4 + div {
overflow: auto;
}
.accordion p {
color: #646464;
}
.accordion .progress .meter {
width: 90%;
height: 2px;
position: relative;
background: #555;
margin: -.9em auto .5em auto;
padding: 1px;
}
.meter > span {
height: 2px;
display: block;
background-color: #f0f0f0;
position: relative;
overflow: hidden;
}
​
This is because the class "progress" assigned to the div id="one" that keeps constant the size of the div with the content.

Resources