I am trying to create a menu that slides up on hover. My problem is that all the links slide up instead of just one at a time.
This is my html
<section id="content">
<div id="stuffhere">asd</div>
</section>
<div id="bottom">
<nav id="links">
hello
every
one
</nav>
</div>
and my css
body,html {
height: 100%;
}
#content {
background: #ccc;
height: 40%;
}
#bottom {
height: 60%;
background: #444;
}
#links {
display: table;
position: absolute;
bottom: 0;
right: 0;
border-spacing: 1em 0;
border-collapse: separate;
}
.mlink {
display: table-cell;
text-align: center;
font-size: 2em;
padding: 0.2em 0.6em;
background: #ccc url('http://images.sodahead.com/polls/004017497/230735835_Emotes_face_wink_icon_answer_1_small.png');
background-repeat: no-repeat;
background-position: 50% 54px;
transition: padding 0.2s linear, background-position 0.4s ease;
}
.mlink:hover {
padding-top: 2em;
background-position: 50% 10px;
}
And here is my fiddle: http://jsfiddle.net/HfX2M/
Any help appreciated :)
Like this?
Fiddle: http://jsfiddle.net/SinisterSystems/HfX2M/1/
.mlink {
display: inline;
When you have table-cell selected for your display property, it is assuming it is just that - a table cell in a table row. So when one expands, so do the rest.
Alternatively, you can also use inline-block to make them side by side, but maintain their block status for individual changes.
For more information on display properties, here is the W3 Standards Page for reference.
http://www.w3.org/wiki/CSS/Properties/display
If you want to maintain your padding (it is no longer assuming its a table so you have to make your own, use inline-block and an additional margin.
.mlink {
display: inline-block;
margin-left:.4em;
Fiddle: http://jsfiddle.net/SinisterSystems/HfX2M/3/**
Related
I wanted to make a landing page for fun, and see how to make it look better, and I figured that I could make a sentence with spinning text in the middle. I've added a GIF to let you guys see what I want it to look like. I did see another post on here similar to mine, but the person that replied had it messed up slightly
I tried using CSS scrolling text, but that made the entire sentence start moving. I tried putting the beginning and end in different DIVs but then they were all seperated.
It needs to be independent element but you can inline-block it. Within this also overflow:hidden element will be a bigger element to be scrolled inside.
h1 {
display: flex;
height: 40px;
/* to center: */
justify-content: center;
}
.scroll-container {
text-align: center;
display: inline-block;
overflow: hidden;
position: relative;
height: 40px;
/* border: 1px solid red; */
margin-left: 10px;
margin-right: 10px;
}
.text-inside .item {
height: 40px;
}
.text-inside {
margin-top: 0;
transition: 500ms;
animation: 3s infinite test;
}
#keyframes test {
0% {
margin-top: 0;
}
25% {
margin-top: 0;
}
50% {
margin-top: -40px;
}
100% {
margin-top: -80px;
}
}
<div style="inline-block">
<h1>Welcome to
<div class="scroll-container">
<div class="text-inside">
<div class="item">Paris</div>
<div class="item">Frankfurt</div>
<div class="item">Milano</div>
</div>
</div>, Joshua
</h1>
#border {
position: static;
z-index: 1;
width: 120px;
height: 120px;
margin-left: 92% ;
padding: 15px;
border-radius: 11px;
background: white;
opacity: 0.2;
}
#text {
margin-left: 93%;
z-index: 2;
color: white;
font-weight: bold;
}
<div id="border"></div>
<div id="text">Users online</div>
I can't post the image here, cuz I have less than 10 reputation, so try to imagine it please. I want to place it's "Users online" inside the border, how should I do this? Thanks.
I'm assuming you are trying to have an element with a semitransparent background.
Since you are using the opacity property on the element with an id of border.
The problem here is that z-index will not have any effect, if the position is set to static, which is the default value for div elements.
The other thing is, that you should be using a relative positioned parent to make your life easier and have more control over the elements since positioned elements will leave the normal document flow and result in new stacking order.
Here you can find good information on the the z-index property, stacking and the document flow.
This is one solution to your problem.
body {
background:black;
}
.holder {
position:relative;
}
#border {
position: absolute;
z-index:1;
right:0;
width: 120px;
height: 120px;
padding: 15px;
border-radius: 11px;
background: white;
opacity: 0.2;
}
#text {
position: absolute;
z-index:2;
right:0;
width: 120px;
height: 120px;
padding: 15px;
text-align: center;
color: white;
font-weight: bold;
}
<div class="holder">
<div id="border"></div>
<div id="text">Users online</div>
</div>
But i would actually try to solve this with a different approach, because i find the above solution a bit to complex and it involves to much positioning, so if all you need is a semitransparent background just make use of the background property with an rgba value. Here is an example.
.user-panel {
float:right;
height: 120px;
width: 120px;
padding: 15px;
border-radius: 11px;
/* fallback for browser that do not support rgba */
background: #ccc;
/* semitransparent background */
background: rgba(0, 0, 0, .2);
text-align: center;
color: white;
}
/* clear the float using the pseudo after element */
user-panel:after {
clear: both;
display: block;
visibility: hidden;
height: 0px;
}
<header>
<div class="user-panel">Users online</div>
</header>
Hope that helps.
Change
position: static;
to
position: absolute;
for #border. That way, border will be "removed from the flow" (i.e. other elements will ignore it). You may need to adjust the margin-left property for #text so it properly aligns.
Fiddle: https://jsfiddle.net/xzdmLt33/1/
Up until a couple days ago using position:absolute; and bottom:-36px was enough to hide the controls down the page, and they would popup whenever the mouse was hovered over the player. Now I'm able to scroll down to see them. How can I fix this while keeping the same slide-up effect?
Also, one more thing... I set the controls div with line-height:36px expecting it to be 36px in height but it is actually 38px (making bottom:-36px kind of useless since 2px are visible). The timer and the P, M and F divs get two extra px on the top and the seek bar gets them on the bottom. Where are these extra px coming from?
Sample
Any help on how to fix these issues and understand what's going on will be greatly appreciated. Thank you.
EDIT1:
Thanks to Fahad I managed to solve my first issue. The snippet didn't work outside of codepen but I fixed it adding position:relative; to the parent div. It still is unclear to me why line-height adds those extra px, though.
Giving the parent div a relative position raised another problem, don't ask me why but sometimes I need to scroll inside the "player" (well, you can ask) and when I do the controls don't stay at the bottom. Please see for yourselves:
Sample
EDIT2:
Apparently that can be easily solved by replacing position:absolute; with position:fixed; in the controls div. I'm still testing just in case this little change is messing with anything else.
You can assign overflow-y: hidden; to your body tag using CSS (to disable vertical scrolling) and change the bottom value to -38px.
html,
body {
font-family: Verdana, Helvetica, Arial, sans-serif;
color: #EEE;
margin: 0;
overflow-y: hidden;
}
#player {
background-color: #333;
text-align: center;
height: 100vh;
}
#toggle {
margin: auto;
width: 500px;
font-size: 24px;
line-height: 60px;
background-color: #B83B3B;
}
#toggle:hover + #controls {
bottom: 0;
}
#controls {
position: absolute;
left: 0;
right: 0;
bottom: -38px;
line-height: 36px;
background-color: #B83B3B;
transition: bottom 0.3s ease;
}
#left {
float: left;
}
#right {
float: right;
}
#curTime {
font-size: 13px;
font-weight: bold;
margin: 0px 8px;
display: inline-block;
vertical-align: middle;
}
#center {
overflow: hidden;
}
#seekBar {
-webkit-appearance: none;
outline: none;
background-color: #1F7783;
height: 6px;
margin: 0;
width: 100%;
}
#seekBar::-webkit-slider-thumb {
-webkit-appearance: none;
background-color: #EEE;
height: 12px;
width: 12px;
border-radius: 12px;
cursor: pointer;
opacity: 0.8;
}
.button {
margin: 0px 8px;
font-size: 24px;
display: inline-block;
vertical-align: middle;
}
<div id="player">
<div id="toggle">Hover to show controls.</div>
<div id="controls">
<div id="left">
<div class="button">P</div>
<span id="curTime">0:01</span>
</div>
<div id="right">
<div class="button">M</div>
<div class="button">F</div>
</div>
<div id="center">
<input type="range" id="seekBar" step="any">
</div>
</div>
</div>
Here's the example on CodePen.
The question doesn't describe this pretty well.
So I got three small images that are suppose to change on hover and work as a link, but it ''detects'' the hover only in a small part of the image. If I drag my mouse to the bottom of the image link, it's not even clickable, so the link only works in the top part of the image.
See for yourself:
http://jsfiddle.net/M3LC9/ (JSFiddle doesn't like pictures..)
<div class="kielet">
<nav>
<!--Englanti-->
<img class="icon" src="iconit/en.gif" title="in english" onmouseover="this.src='iconit/en_hover.gif'" onmouseout= "this.src='iconit/en.gif'">
<!--Ruotsi-->
<img class="icon" src="iconit/swe.gif" title="på svenska" onmouseover="this.src='iconit/swe_hover.gif'" onmouseout="this.src='iconit/swe.gif'">
<!--Venäjä-->
<img class="icon" src="iconit/ru.gif" title="По русски" onmouseover="this.src='iconit/ru_hover.gif'" onmouseout="this.src='iconit/ru.gif'">
</div>
.kielet {
top:0px;
width:100%;
background: black;
right: 0px;
margin-bottom:0px;
padding:0px;
}
.kielet nav {
right: 0px;
margin-right: 0px;
text-align: right;
}
.icon {
width: 50px;
height: 100%;
right: 0px;
margin: 20px;
margin-top:0px;
margin-bottom:0px;
display:inline;
padding: 0px;
}
You currently have your images set to display as inline. This will make them adhere to any line-height defaults a browser may have set on your a element, keeping your a element at a smaller height. This can be visualised in Chrome's Element Inspector:
To change this, simply set the display on your a elements to inline-block:
a {
display: inline-block;
}
JSFiddle demo.
Note that you may want to be a bit more specific with your a selector by specifying .kielet nav a, for instance, or giving your a elements their own class identifier.
Try changing the display property to display:inline-block
.icon {
width: 50px;
height: 100%;
right: 0px;
margin: 20px;
margin-top:0px;
margin-bottom:0px;
display:inline-block; <----
padding: 0px;
}
JSFiddle
Usually you don't implement your hover-state with javascript and <img />
You can easily do this with CSS.
HTML
<div class="kielet">
<nav>
<!--Englanti-->
<!--Ruotsi-->
<!--Venäjä-->
</nav>
</div>
CSS
.kielet {
background: black;
padding: 5px;
text-align: center;
}
a.icon {
display: inline-block;
width: 16px;
heiht: 16px;
line-height: 16px;
}
a.icon_ru { background: url(http://placehold.it/16x16/ffc) center no-repeat; }
a.icon_ru:hover { background: url(http://placehold.it/16x16/ff0) center no-repeat; }
a.icon_en { background: url(http://placehold.it/16x16/cff) center no-repeat; }
a.icon_en:hover { background: url(http://placehold.it/16x16/0ff) center no-repeat; }
a.icon_swe { background: url(http://placehold.it/16x16/fcf) center no-repeat; }
a.icon_swe:hover { background: url(http://placehold.it/16x16/f0f) center no-repeat; }
jsFiddle
I have not been able to find a solution to this and am willing to change whatever I need to as long as I can keep a couple things.
The entire list element needs to be a link, the text within that link needs to be centered to the list item which has a background image. I need this fluid so I choose to use the padding-top to maintain the aspect ratio and to create the correct height. With using that padding top to create the height, I can not for the life of me figure out how to get the text vertically centered. I have seen a few other questions that addresses this issue somewhat but I have not found a single one answered. PLEASE help me!
Here is live example. I need the text to vertically align to the middle of blue elements.
http://jsbin.com/OxuxECI/1/edit?html,css,output
HTML
<section>
<ul>
<li><a id="monday" href="_monday.html"><span>Monday</span></a></li>
</ul>
</section>
CSS
section {
position: relative;
width: 86.029411764%;
height: 100%;
margin: -6px auto 0 auto;
overflow: hidden;
}
section ul {
list-style-type: none;
display: inline-block;
width: 35%;
min-width: 320px;
padding: 0;
margin: .8rem;
height: 100%;
}
section li {
width: 100%;
display: block;
background: url(_images/daybg_03.png) center center no-repeat;
background-size: contain;
margin: .8rem auto .8rem auto;
text-align: center;
font-size: 0;
line-height: 0;
}
section ul li a {
width: 100%;
**padding-top: 14.95%;** /* This gives my container height */
display: inline-block;
text-decoration: none;
text-align: center;
}
section ul li a span {
font-size: 1.3rem;
color: white;
text-align: center;
}
Ok so after searching high and low and no luck I have figured it out!!!
CSS
section li {
position: relative;
width: 100%;
height: auto;
display: block;
background: url(_images/daybg_03.png) center center no-repeat;
-webkit-background-size: contain;
-moz-background-size: contain;
background-size: contain;
margin: .8rem auto 0 auto;
list-style: none;
text-align: center;
font-size: 0;
padding-top: 14.95%;
}
section ul li a {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
text-decoration: none;
text-align: center;
background: rgba(0,191,85,.5);
}
section ul li a span {
display: block;
position: absolute;
bottom: 0;
width: 100%;
height: 50%;
line-height: 0;
font-size: 1.3rem;
color: white;
text-align: center;
background: rgba(0,159,255,.5);
}
And the bin http://jsbin.com/enuBeyE/1/edit?html,css,output
I left the background colors in there for visual help for each container.
Infinity Designs' answer works well, but only if you don't need content that spans more than one line.
If you do need content that spans more than one line inside responsive, dynamic height and width vertically centred containers with a fixed aspect ratio, there's good news and bad news:
Good news: there is a pure CSS method that works in GC, FF, IE7+, etc etc.
Bad news: the code ain't pretty: it needs four (!) wrapper elements plus a non-semantic spacer. Infinity Designs' method only needs three wrappers, so use that unless you need text wrap.
It's essentially Infinity Designs' approach to the responsive fluid aspect ratio, mixed with Kizu's approach to vertical centring on this other question, using side-by-side inline-blocks with vertical align around a nested block.
JSbin demo
Sample code:
<div class="w1">
<!-- make w2 <a> if like the asker you want it all to be a clickable link -->
<span class="w2"><span class="hh"> </span>
<span class="w3"> <!-- make w3 <a> if don't want the bkg clickable -->
<span class="w4"><!-- or, any block element -->
Monday
</span>
</span>
</span>
</div>
<style>
.w1 { /* outer wrapper for aspect ratio */
position: relative; /*or absolute*/
display: block; /*or inline-block*/
padding-top: 25%; /*aspect ratio*/
}
.w2 { /* wrapper2 resets position to top */
position: absolute;
top: 0;
width: 100%;
height: 100%;
display: block;
}
.w3 { /* wrapper3 and hh sit side by side */
display: inline-block;
width: 100%;
text-align: center;
}
.w3, .hh {
vertical-align: middle;
display: inline-block;
}
.hh { height: 100% }
.w4 { /* v.align applies to child block */
display: block;
}
</style>