I'm very new to CSS and HTML combination. I'm trying to make use of following code for dropdown menu. But when mouse is moved away from dropdown menu, it gets closed. I would like to close it onclick outside the dropdown menu. Can anyone suggest me a fix in CSS to achieve this? JSFiddle for me code is at following location Fiddle link. Your help will be much appreciated. HTML looks like this.
<div id="main">
<div class="wrapper">
<div class="content">
<content>
<div>
<ul>
<li>Lorem ipsum dolor</li>
<li>Consectetur adipisicing</li>
<li>Reprehenderit</li>
<li>Commodo consequat</li>
</ul>
</div>
</content>
</div>
<div class="parent">Drop Down Parent 1</div>
</div>
And CSS looks like this
#main {
margin: 30px 0 50px 0;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
}
#main .wrapper {
display: inline-block;
width: 180px;
margin: 0 10px 0 0;
height: 20px;
position: relative;
}
#main .parent {
height: 100%;
width: 100%;
display: block;
cursor: pointer;
line-height: 30px;
height: 30px;
border-radius: 5px;
background: #F9F9F9;
border: 1px solid #AAA;
border-bottom: 1px solid #777;
color: #282D31;
font-weight: bold;
z-index: 2;
position: relative;
-webkit-transition: border-radius .1s linear, background .1s linear, z-index 0s linear;
-webkit-transition-delay: .8s;
text-align: center;
}
#main .parent:hover, #main .content:hover ~ .parent {
background: #fff;
-webkit-transition-delay: 0s, 0s, 0s;
}
#main .content:hover ~ .parent {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
z-index: 2;
}
#main .content {
position: absolute;
top: 0;
display: active;
z-index: 2;
height: 0;
width: 180px;
padding-top: 30px;
-webkit-transition: height .5s ease;
-webkit-transition-delay: .4s;
border: 1px solid #777;
border-radius: 5px;
box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
#main .wrapper:active .content {
height: 123px;
z-index: 3;
-webkit-transition-delay: 0s;
}
#main .content div {
background: #fff;
margin: 0;
padding: 0;
overflow: hidden;
height: 100%;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
#main .content:hover {
height: 123px;
z-index: 3;
-webkit-transition-delay: 0s;
}
I'm looking at something like this and will set new content to content tag. What I'm really looking at is following
1) Click on dropdown menu. Show the dropdown.
2) When hovered on it keep displaying. When hover outside dropdown keep showing it.
3) When clicked somewhere outside dropdown then close the dropdown.
I know I'm using hover selector so my behavior is like that. But I want to covert it to above behavior and I don't know how to do it.
<div id="main">
<div class="wrapper">
<div class="content">
<content>
</content>
</div>
<div class="parent">Drop Down Parent 1</div>
Your HTML is wrong. If you see, you have wrapped <li> inside the <a> tag. That's a basic issue you have. And there are other issues.
Change your existing HTML:
<a><li>...</li></a>
To the right form:
<li><a>...</a></li>
And then the click works. An <a> cannot contain an <li> inside it. So the click doesn't happen.
Related
I am trying to create an effect when div class="container" is being hovered, a smooth upper transition occurs of another div from bottom. Only during hover, this should happen cause I want that .bottom div to be hidden. When that div is not hidden, I can see the effect as I want. But as I hide the bottom div, that hovering effect smooth transition effect cannot be seen. Check this code once.
HTML CODE
<div class="box">
Hello
<div class="bottom">
Everyone
</div>
</div>
CSS code
.box{
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top:80px;
left:0;
/* display: none; */
}
.box:hover .bottom {
display: block;
transition: linear 0.2s;
top:55px;
}
Here is the codepen link
https://codepen.io/Biebk/pen/MWpREqb
First off, rather than display: none to hide the incoming element altogether, you can set its opacity to 0, and then when the parent is hovered, set it to 1, like so:
.bottom {
opacity: 0;
}
.box:hover .bottom {
opacity: 1;
}
I suppose that given you want an incoming "pull-up" effect on hover, you want to that element to also "pull-down" when the hover ends. You can reverse the same effect by using a :not(:hover) on the parent element:
.box:not(:hover) .bottom {
opacity: 0;
}
Also, be sure to set the transition on the non-hovered state. The following example provides the smooth transition you're looking for:
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
left: 0;
transition: all .25s ease;
}
.box:not(:hover) .bottom {
top: 80px;
opacity: 0;
}
.box:hover .bottom {
top: 55px;
opacity: 1;
}
<div class="box">
Hello
<div class="bottom">
Everyone
</div>
</div>
A secondary approach would be to place the bottom div as a sibling to the box, and use the adjacent sibling combinator to apply the hover effects:
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
font-size: 20px;
background: pink;
width: 80px;
text-align: center;
position: absolute;
left: 0;
top: 80px;
opacity: 0;
cursor: default;
transition: all .25s ease;
}
.box:hover + .bottom {
top: 55px;
opacity: 1;
}
<div class="box">
Hello
</div>
<div class="bottom">
Everyone
</div>
Use opacity property rather than display to achieve the desired effect, then
use the following code
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top: 80px;
left: 0;
opacity: 0;
}
.box:hover .bottom{
opacity: 1;
transition: opacity 0.2s , top 1s;
top: 55px;
}
Use the following code.
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.hovered{
transition: all .2s;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top: 80px;
left: 0;
visibility: hidden;
}
.hovered:hover+.bottom {
transition: all .2s;
top: 55px;
visibility: visible;
}
<div class="box">
<div class="hovered">Hello</div>
<div class="bottom">
Everyone
</div>
</div>
So, I have a div that appears at the top of my screen, and when you hover over it, at the bottom of the screen, text appears.
I want to add another effect to the div that makes more text appear in a completely different place on the screen, while the other text stays in the same place.
Is that possible? Preferably using CSS/HTML instead of Java or anything?
You can use ~ (tilde) operator to target all your siblings (all should have the same parent) show on hover. Please have a look at the example snippet below:
body { margin: 0; }
.holder {
text-align: center;
height: 100vh;
}
.hover {
position: absolute;
top: 10%;
left: 50%;
transform: translateX(-50%);
color: red;
font-size: 30px;
font-weight: bold;
border: 2px solid red;
padding: 10px 15px;
cursor: default;
transition: all .2s linear;
}
.hover:hover {
background: rgba(255, 0, 0, 0.1);
}
.hover:hover ~ .show-text {
opacity: 1;
transition: all .2s linear;
}
.show-text {
position: absolute;
opacity: 0;
font-size: 20px;
border-bottom: 1px solid #aaa;
transition: all .2s linear;
}
.one {
bottom: 20%;
left: 20%;
}
.two {
bottom: 20%;
right: 20%;
}
<div class="holder">
<div class="hover">Hover Me!</div>
<div class="show-text one">I'm Text 1</div>
<div class="show-text two">I'm Text 2</div>
</div>
Hope this helps!
I want to center my text in a relative height div which contains an image. I use absolute position but when my text is on two lines, the text is not centered. I've already tried to use a table but it doesn't work due to the img.
HTML:
<div id="hubs">
<h3>Nos Hubs</h3>
<hr>
<a class="thumbnail vignette-hub" href="http://kkw.fr">
<img style="opacity: 0.6;filter: alpha(opacity=60);" alt="AĆ©roport de Nantes" src="http://kkw.fr/uploads/upload-center/nantes-vue-aerienne091501270208.png" width="100%" />
<p class="txt-hub-image">
Hub de</br>Nantes
</p>
</a>
</div>
CSS :
.txt-hub-image {
z-index: 100;
position: absolute;
left: 0px;
top: 50%;
width: 100%;
height: 100%;
text-align: center;
text-decoration: none;
color: white;
font-weight: bold;
font-size: 16px;
}
.vignette-hub {
position: relative;
width: 25%;
min-width: 135px;
}
.thumbnail {
display: block;
padding: 4px;
margin-bottom: 20px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-transition: border .2s ease-in-out;
-o-transition: border .2s ease-in-out;
transition: border .2s ease-in-out;
}
.thumbnail > img,
.thumbnail a > img {
margin-right: auto;
margin-left: auto;
}
a.thumbnail:hover,
a.thumbnail:focus,
a.thumbnail.active {
border-color: #337ab7;
}
.thumbnail .caption {
padding: 9px;
color: #333;
}
Do you have any ideas ?
There are a few changes required to your snippet to make it automatically work for all dimensions:
p tags by default have a margin-top. If you don't reset it, then absolutely positioning it at 50% would become 50% + margin-top. This needs to be reset.
When you absolutely position an element at top: 50%, the box gets positioned at 50% height of the container and text keeps getting added from that position on. So, to match the center of the text block with the center of the parent, you have to translate the box with the text up by 50% of its own size. This can be done by adding transform: translateY(-50%).
You don't need to add a height: 100% on the p tag and it can be removed.
Note: Using transform method for positioning needs CSS3 support but I assume this shouldn't be a problem because you are already using transition.
If you want to support non CSS3 compatible browsers, have a look at the other approaches mentioned here. I have added a different answer just to explain the first two points I had mentioned above.
.txt-hub-image {
z-index: 100;
position: absolute;
left: 0px;
top: 50%;
width: 100%;
text-align: center;
text-decoration: none;
color: white;
font-weight: bold;
font-size: 16px;
/* added to fix the vertical centering */
margin-top: 0px;
transform: translateY(-50%);
}
.vignette-hub {
position: relative;
width: 25%;
min-width: 135px;
}
.thumbnail {
display: block;
padding: 4px;
margin-bottom: 20px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-transition: border .2s ease-in-out;
-o-transition: border .2s ease-in-out;
transition: border .2s ease-in-out;
}
.thumbnail > img,
.thumbnail a > img {
margin-right: auto;
margin-left: auto;
}
a.thumbnail:hover,
a.thumbnail:focus,
a.thumbnail.active {
border-color: #337ab7;
}
.thumbnail .caption {
padding: 9px;
color: #333;
}
<div id="hubs">
<h3>Nos Hubs</h3>
<hr>
<a class="thumbnail vignette-hub" href="http://kkw.fr">
<img style="opacity: 0.6;filter: alpha(opacity=60);" alt="AĆ©roport de Nantes" src="http://kkw.fr/uploads/upload-center/nantes-vue-aerienne091501270208.png" width="100%" />
<p class="txt-hub-image">
Hub de</br>Nantes
</p>
</a>
</div>
Here is a demo fiddle as the snippets feature seems to be down.
Change your .txt-hub-image class, top value from 50% to 25%.
Currently I have a sidebar on my website, and when a user hovers something on the sidebar it should bring up a popover. Yet there is this really weird issue!
The sidebar has a vertical scroll bar, and when the popover comes up it will not go over the scroll bar. Here is a image of it (Please note that is not going to be the actual popover, it is just for testing):
Sorry, not sure why the text is appearing down here. Anyhow as you can see when there is a scroll bar the text will not pass through it, yet when the scroll bar is removed the text WILL pass through it. Here is all of the important CSS:
.sidebarbuttons2 {
width: 100%;
height: 5%;
margin-left: auto;
margin-right: auto;
background-color: gray;
text-align: center;
font-size: 70%;
border-bottom: 2px solid #474747;
z-index: 2;
}
.sidebarbuttons2 li .dropdownbuttonsholder {
display: none;
margin: 0;
padding: 0;
margin-left:150px;
float:left;
margin-top: -45px;
height: 0;
z-index: 3;
}
.sidebarbuttons2 li:hover .dropdownbuttonsholder {
width: 200px;
background-color: blue;
border: 1px solid black;
list-style: none;
height: 25px;
display: block;
z-index: 4000;
position: absolute;
}
#dropdownbuttonitem1 {
background-color: red;
height: 25px;
z-index: 5;
}
#dropdownbuttonitem2 {
background-color: green;
height: 25px;
z-index: 5;
}
#dropdownbuttonitem3 {
background-color: yellow;
height: 25px;
z-index: 5;
}
#dropdownbuttonitem4 {
background-color: orange;
height: 25px;
z-index: 5;
}
/*-------------------------------------------------------*/
/*Sidebar Style*/
/*-------------------------------------------------------*/
.sidebarpostinbutton {
color: orange;
font-weight: bold;
}
#sidebar {
width: 20%;
height: 1900px;
background-color: gray;
z-index: 1;
border-right: 3px solid #474747;
position: absolute;
overflow-y: scroll;
font-size: 88%;
}
#sidebar:hover {
width: 25%;
z-index: 5;
-webkit-transition: 1s linear;
-moz-transition: 1s linear;
-o-transition: 1s linear;
-ms-transition: 1s linear;
transition: 1s linear;
}
.sidebarbuttons {
width: 100%;
height: 5%;
margin-left: auto;
margin-right: auto;
background-color: gray;
text-align: center;
font-size: 70%;
line-height: 0%;
border-bottom: 2px solid #474747;
}
#sidebarbuttonlast1 {
border-bottom: 0px;
}
#sidebarscrollinformation {
display: none;
}
/*-------------------------------------------------------*/
/*Main Contents Box Style*/
/*-------------------------------------------------------*/
.maincontentssection {
background-color: lightgray;
margin-left: 20%;
height: 1900px;
position: absolute;
width: 80%;
overflow-y: scroll;
z-index: 1;
}
And then here is the important HTML:
<div id="sidebar">
<div class="col-xs-12 col-sm-6 col-md-12">
<ul class="nav sidebarbuttons2"> <!-- navbar -->
<li> <h1> Art </h1>
<ul class="dropdownbuttonsholder row">
<ul id="dropdownbuttonitem1" class="col-xs-3"> All Posts </ul>
<ul id="dropdownbuttonitem2" class="col-xs-3"> Most Popular </ul>
<ul id="dropdownbuttonitem3" class="col-xs-3"> Most Viewed </ul>
<ul id="dropdownbuttonitem4" class="col-xs-3"> Newest </ul>
</ul>
</li>
</ul>
</div>
</div>
I can not figure out why it is not going through the scroll bar. Please Help! :)
P.S. If you would like the full HTML go here: http://pastebin.com/c89M7MPk (it is a include), and the full CSS go here: http://pastebin.com/yJZp9HT2
That's just how overflow: scroll works. Even if you use overflow-x or overflow-y, you cannot mix this with overflow: visible in the same element.
The only thing you can do, is to use overflow-x: visible; overflow-y: hidden; for the CSS, and use javascript to scroll the element. Check out a library like this for the scroll: http://darsa.in/sly/
In the CSS, LINE 974 change margin-left:150px; to margin-left: 0px;
My codepen
http://codepen.io/leongaban/pen/sBvfL
So having a strange issue, I'm trying to get the background of the #portfolio div to stretch to contain the thumbnails below which are in an ul list inside of the portfolio div.
However 100% or auto doesn't affect the height. I have to set a static height, like 1000px. To get the background to cover the thumbs. However I'm trying to not set a static height since the thumbnails will get longer.
Perhaps I've been coding this too long, how would you code this?
HTML
<div id="portfolio">
<div class="portfolio-nav">
<h1>Portfolio</h1>
</div>
<div id="showcase-holder">
<div id="showcase-div">
<ul id="portfolio-thumbs">
<li>
<a href="/portfolio/chipestimate">
<img class="role-thumb" src="http://leongaban.com/images/thumb_chipestimate.jpg" alt="ChipEstimate"/>
</a><p>ChipEstimate</p>
</li>
<li>
<a href="/portfolio/shabang" title="Shabang">
<img class="role-thumb" src="http://leongaban.com/images/thumb_shabang.jpg" alt="Shabang"/>
</a><p>Shabang</p>
</li>
</ul>
</div>
</div>
CSS
body {
background: brown;
}
#portfolio {
position: relative;
width: 100%;
height: 50%;
background: #fff;
border-top: 2px solid #ccc;
z-index: 1;
}
#portfolio ul { list-style: none; }
.portfolio-nav { margin: 0 0 20px 0; }
.portfolio-nav h1 {
padding: 30px 0 10px 0;
text-align: center;
font-size: 2.5em;
font-weight: 700;
color: #d74927;
text-shadow: 1px 1px #ccc;
}
#showcase-holder {
position: relative;
width: 80%;
height: 100%;
margin: 0 auto;
border-bottom: 2px solid #ccc;
}
#portfolio-thumbs {
position: relative;
float: left;
list-style-type: none;
margin: 0 0 40px 0;
padding: 0 0 0 5%;
width: 100%;
height: 100%;
}
#portfolio-thumbs li {
position: relative;
float: left;
width: 20%;
margin: 1%;
text-align: center;
padding: 5px 5px 15px 5px;
background-size: 100% auto;
overflow: hidden;
background: white;
-webkit-transition: background .3s;
-moz-transition: background .3s;
-ms-transition: background .3s;
transition: background .3s;
}
#portfolio-thumbs li:hover {
color: #fff;
background: #d74927;
-webkit-transition: background .5s;
-moz-transition: background .5s;
-ms-transition: background .5s;
transition: background .5s;
}
#portfolio-thumbs li a {
color: #333;
text-decoration: none;
}
#portfolio-thumbs li p {
padding: 10px 0 0 0;
}
#portfolio-thumbs li img.role-thumb {
width: 95%;
min-width: 170px;
padding-top: 5px;
}
Parents will normally expand to the height of their children, though won't in case the children are relative.
You can remove positions and floats to accomplish expanding.
In order to expand a parentdiv based on positioned children try overflow: auto; on #portfolio. This will make #portfolio expand to the height of its children. As seen on this fork of your example.
overflow: auto; will actually let your browser decide, which normally renders this to overflow: hidden;. Though I tend to use overflow: auto; to prevent issues with scrollbars as the page possibly expands later on.
You have added float to your li elements, which means that the parent will not expand to contain these elements.
You can work around this by adding a clearing div.
<div style="clear:both;"></div>
after the showcase-holder div.
Adding overflow: hidden to both #showcase-div and #portfolio-thumbs should do it for you.
http://jsfiddle.net/5SFFP/