Menu move effect in CSS - 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.

Related

How to make an element overflow outside of containing element?

<!DOCTYPE html>
<html lang="en">
<head>
<style>
*{
margin: 0px;
padding: 0px;
}
.squares {
color: rgb(212, 212, 212);
background-color: #2e2e2e;
width: 40px;
height: 40px;
}
.dropdown-content {
width: 100px;
height: 80px;
background-color: #7e7e7e;
}
#sidebar{
overflow: visible;
width: 40px;
height: 100px;
}
</style>
</head>
<body>
<div id="sidebar">
<div class="squares"></div>
<div class="dropdown-content"></div>
<div class="squares"></div>
</div>
</body>
</html>
How can I make .dropdown-content overflow to the right side of #sidebar without changing size of sidebar? I've tried using floats but that did not work. I've also tried containing the first .squares and .dropdown-content together but that causes the second .squares to be positioned away from the bottom of the first .squares.
You just need to add relative positioning to your .dropdown-content and absolute positioning to the inner sub menu wrapper. And then add top: 0 and left: 100%
Here's the working example for you:
body {
margin: 0;
}
.menu {
display: inline-flex;
justify-content: center;
align-items: center;
flex-direction: column;
background: #212121;
position: fixed;
overflow: visible;
}
.menu-item {
padding: 10px;
color: #fff;
cursor: pointer;
}
.expandable {
position: relative;
display: inline-flex;
justify-content: center;
align-items: center;
}
.expandable:hover > .sub-menu {
display: inline-flex;
flex-direction: column;
width: 200px;
}
.sub-menu {
position: absolute;
left: 100%;
top: 0%;
display: none;
width: 200px;
background: #fff;
color: #000;
border: 1px solid;
cursor: pointer;
}
.sub-menu-item {
padding: 10px;
}
.sub-menu-item:not(:last-child) {
padding: 10px;
border-bottom: 1px solid
}
<div class="menu">
<div class="menu-item">Simple Menu</div>
<div class="menu-item expandable">
Hover to Expand >
<div class="sub-menu">
<div class="sub-menu-item">Sub Menu 1</div>
<div class="sub-menu-item">Sub Menu 2</div>
<div class="sub-menu-item">Sub Menu 3</div>
</div>
</div>
<div class="menu-item">Simple Menu</div>
</div>
In my code .expandable is the one that have sub menus in it, on hovering over the element submenus will be opened on the right side of that menu-item.
The position will be depend upon the hovered element.
Also, here's the code pen link if you wish to tinker it:
https://codepen.io/prathameshkoshti/pen/zYBeWEz?editors=0110
In this one I have used multiple of this.
.dropdown-content {
position: relative;
right: -20px;
width: 100px;
height: 80px;
background-color: #7e7e7e;
}
simple version I do not change the container, and I shift it to the right.
If I understood correctly....
* {
margin: 0px;
padding: 0px;
}
#sidebar {
overflow: visible;
width: 40px;
height: 100px;
}
.squares {
position: relative;
border: 1px solid #fff;
color: rgba(212, 212, 212, 1);
background-color: #2e2e2e;
width: 40px;
height: 40px;
}
.dropdown-content {
position: absolute;
left: 40px;
top: 0px;
width: 100px;
height: 80px;
background-color: #7e7e7e;
display: none; /* sub menus will not be visible as a result */
}
.squares:hover > .dropdown-content {
display: block;
}
<body>
<div id="sidebar">
<div class="squares">1</div>
<div class="squares">
2
<div class="dropdown-content">
</div>
</div>
<!-- create another container to house the .dropdown-content -->
<div class="squares">3</div>
</div>
</body>
insert the .dropdown-content into a .square then add display:none to the styling of .dropdown-content and finally on hover change display: none to block

Custom checklist column width is not working

I can't seem to change the width of my checklist. I'm trying to reduce the width and have some margin around the checklist item but it doesn't work. Here's what I have so far: https://jsfiddle.net/h64f1otw/1/
Snippet of my checklist:
.checkList {
list-style-image: url('http://i66.tinypic.com/6nv3me.png');
columns: 2 4em;
}
.checkList li{
color: #fff;
}
I'm trying to achieve something like below:
what i did is adding display:flex for ul element and applying margin on li element with width:50% for each
to center your div you need to add margin:0 auto on heroInner class and remove padding on content class
.hero {
position: relative;
height: 44vh;
max-height: 64rem;
min-height: 28rem;
}
.background {
background-image: url('https://images.unsplash.com/photo-1531845116688-48819b3b68d9?ixlib=rb-1.2.1&auto=format&fit=crop&w=2851&q=80');
background-repeat: no-repeat;
background-position: 50%;
background-size: cover;
width: 100%;
height: 100%;
}
.overlay {
background: linear-gradient(to right, #1d1d1d, rgba(0, 0, 0, 0));
position: absolute;
top: 0;
left: 0;
display: table;
height: 100%;
width: 100%;
}
.inner {
display: table-cell;
width: 100%;
padding-top: 6rem;
padding-bottom: 6rem;
vertical-align: middle;
text-align: center;
}
.content {
max-width: 80rem;
margin-left: auto;
margin-right: auto;
width: 100%;
}
#media (min-width: 62.25rem)
{
.content {
padding-left: 3rem;
padding-right: 3rem;
}
}
.heroInner {
text-align: left;
max-width: 31rem;
margin:0 auto;
}
.checkList {
list-style-image: url('http://i66.tinypic.com/6nv3me.png');
display:flex;
flex-wrap:wrap;
justify-content:space-between;
}
.checkList li{
color: #fff;
margin-top: 30px;
}
.checkList li:nth-child(odd){
width:30%;
}
.checkList li:nth-child(even){
width:60%;
}
<div class="hero">
<div class="background"></div>
<div class="overlay">
<div class="inner">
<div class="content">
<div class="heroInner">
<div class="checkListContainer">
<ul class="checkList">
<li>Long term leases</li>
<li>Bespoke solutions</li>
<li>Multi city campaigns</li>
<li>Measuring success with data</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>

why does my column go down?

http://codepen.io/anon/pen/OMLLwB
#news {
width: 85%;
margin: 0 auto;
}
#news ul {
list-style: none;
margin: 0;
padding: 0;
}
#worldMap img {
width: 100%;
}
.newspiece {
margin-bottom: 2.5%;
padding: 20px;
background-color: #90C3D4;
height: 130px;
}
.newspiece h3 {
border-bottom: 3px solid black;
margin-bottom: 10px;
}
#media(min-width: 600px) {
.newspiece {
width: 25%;
margin-left: 5%;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
.newspiece:first-child {
margin-left:0;
}
}
Am i missing something here? the width the total container (#news) is 85%, the width of each item is 25%, and two of them have a 5% left margin, total sums to 85%, then why do i resize it, the rightmost column goes down?
i have changed your html/css. this is a cleaner solution and is suported among all browsers
html:
<div class="flex">
<div class="box">
<h3>Title</h3>
<p>Content</p>
</div>
<div class="box">
<h3>Title</h3>
<img src="http://www.placecage.com/400/300" alt="">
</div>
<div class="box">
<h3>Title</h3>
<p>Content</p>
</div>
</div>
css:
.flex {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.box {
width: 300px;
margin: 10px;
padding: 20px;
background: #90C3D4;
}
.box h3 {
padding-bottom: 5px;
border-bottom: 3px solid black;
}
.box img {
max-width: 100%;
}
* { box-sizing: border-box; }
The padding adds to the total width of the element if box-sizing: border-box is not used.

CSS > Div float

I'm trying to design a layout like:
But as you can see on here: http://codepen.io/amonello/pen/zxemxb
<ul>
<li>
<div class="picture"></div>
<div class="name">name</div>
<div class="title">title</div>
<div class="title2">title2</div>
<div class="title3">title3</div>
<div class="phone">phone</div>
<div class="email">email</div>
</li>
</ul>
I've got some trouble doing it. I have a hard time understanding the float and the display.
Could any of you point me in the right direction?
I cannot add a wrapper around name/titles and phone/email.
Maybe this way
http://codepen.io/kazup/pen/raPRXz
ul, li {
margin: 0;
padding: 0;
list-style: none;
}
.picture {
float: left;
width: 73px;
height: 100px;
background: gray;
border: 1px solid black;
}
.name,
.title,
.title2,
.title3,
.phone,
.email {
float: left;
clear: left;
width: 90%;
border: 1px solid green;
}
#media screen and (min-width: 600px) {
.picture {
position: absolute;
float: none;
}
.name,
.title,
.title2,
.title3 {
margin-left: 90px;
width: 35%;
}
.phone,
.email {
float: none;
clear: none;
margin-left: 55%;
width: 35%;
border: 1px solid red;
}
}
<ul>
<li>
<div class="picture"></div>
<div class="name">name</div>
<div class="title">title</div>
<div class="title2">title2</div>
<div class="title3">title3</div>
<div class="phone">phone</div>
<div class="email">email</div>
</li>
</ul>
Only the .picture has absolute positioning, divs are floated, except for the phone and email in desktop view.
Don't care about the widths of the divs, it's just nicer this way.

Removing border from first-child

Is it possible to remove the first transparent border-left without increasing the height of the first box? I initially tried using margins, but this cannot work due to the use of percentages. Here is what I have - http://jsfiddle.net/KCbgM/1/
Update: The border that I am trying to remove is already transparent - the left border of the first box. I am trying to get the boxes to fit in the 100% with no gap before the first child - which at the moment is a transparent border using the '.grid ul li .grid-item' class.
HTML:
<div class="grid">
<ul>
<li>
<div class="grid-item grid-five">
<div class="grid-person-wrapper">
<img class="grid-person-mug" src="http://boardingarea.wpengine.netdna-cdn.com/deltapoints/files/2012/07/test.jpg">
</div>
</div>
</li>
<li>
<div class="grid-item grid-five">
<div class="grid-person-wrapper">
<img class="grid-person-mug" src="http://boardingarea.wpengine.netdna-cdn.com/deltapoints/files/2012/07/test.jpg">
</div>
</div>
</li>
<li>
<div class="grid-item grid-five">
<div class="grid-person-wrapper">
<img class="grid-person-mug" src="http://boardingarea.wpengine.netdna-cdn.com/deltapoints/files/2012/07/test.jpg">
</div>
</div>
</li>
<li>
<div class="grid-item grid-five">
<div class="grid-person-wrapper">
<img class="grid-person-mug" src="http://boardingarea.wpengine.netdna-cdn.com/deltapoints/files/2012/07/test.jpg">
</div>
</div>
</li>
<li>
<div class="grid-item grid-five">
<div class="grid-person-wrapper">
<img class="grid-person-mug" src="http://boardingarea.wpengine.netdna-cdn.com/deltapoints/files/2012/07/test.jpg">
</div>
</div>
</li>
</ul>
</div>
CSS:
.grid {
display: block;
float: left;
border:1px solid #000;
}
.grid ul {
list-style: none;
margin: 0;
padding: 0;
}
.grid ul li {
display: inline;
text-align: -webkit-match-parent;
}
.grid-five {
width: 20%;
}
.grid-item {
float: left;
display: block;
background: transparent;
position: relative;
overflow: hidden;
}
.grid ul li .grid-item {
border-left: 34px solid transparent;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.grid ul li:first-child .grid-item {
margin-left:0px;
}
.grid-person-wrapper {
border: 8px solid #cad7c5;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: #fff;
float: left;
position: relative;
z-index: 1;
width: 100%;
cursor: pointer;
display: block;
-webkit-transition: All 0.1s ease;
-moz-transition: All 0.1s ease;
-o-transition: All 0.1s ease;
-ms-transition: All 0.1s ease;
transition: All 0.1s ease;
}
.grid-person-wrapper:hover {
border: 8px solid #a9f001;
opacity: 0.8;
}
.grid-person-mug {
width: 100%;
border: none;
max-width: 100%;
}
Remove the transparent borders, and instead set text-align:justify; on the list and use a pseudo element to stretch contents to 100% width:
FIDDLE
(Relevant) CSS
.grid ul {
list-style: none;
margin: 0;
padding: 0;
text-align:justify;
}
.grid ul:after {
content: '';
width: 100%;
display: inline-block;
}
.grid ul li {
display: inline;
}
.grid-five {
width: 18%;
}
You can try this...
Fiddle here..
.grid ul li:first-child .grid-person-wrapper
{
border-left:transparent;
}
If your requirement is different then let me know..
Good Luck...:)
You need to address the width change also. Try :
.grid ul li:first-child .grid-item {
border-left: none;
width: 15%;
}
Fiddle : http://jsfiddle.net/KCbgM/5/
Edit 1 :
How about changing the margin between the divs to account for the variation ?
.grid ul li .grid-item {
-moz-box-sizing: border-box;
border-left: 34px solid rgba(0, 0, 0, 0);
margin-left: 1.25%;
}
.grid ul li:first-child .grid-item {
border-left: medium none;
margin-left: 0;
width: 15%;
}
Fiddle : http://jsfiddle.net/KCbgM/6/
Let me know if this is what you want.
Try:
.grid ul li .grid-item {
padding-left: 34px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
EDITED:
Ok, now I see the issue.
This should solve the problem:
.grid ul li:first-child .grid-item {
margin-left:-34px;
}

Resources