Relatively position menu-item in a dropdown/collapsible menu? - html

First, here's the dropdown/collapsible menu I've constructed.
As for what the "menu" and "menu-item" are in the preview shown in the fiddle -- Channels, Search, and About Us are menus, while the ones that drop-down/slide-out when you click on the menus are menu-items.
SCREENSHOT:
I am using position: absolute; on the menu-items (.collapse), and position: relative; on the menus.
The Relevant code (more in the fiddle):
/* Menu: <li class="float-left top-menu">... */
.top-menu {
position: relative;
}
/* Menu-Item: <div id="channels-menu-item-container" class="collapse">... */
.collapse {
position: absolute;
width: 570px;
z-index: 1000;
padding: 0;
margin: 0;
color: #222;
background-color: #fff;
-webkit-box-shadow: 0 5px 5px rgba(0, 0, 0, 0.2), 0 10px 20px rgba(0, 0, 0, 0.12);
-moz-box-shadow: 0 5px 5px rgba(0, 0, 0, 0.2), 0 10px 20px rgba(0, 0, 0, 0.12);
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.2), 0 10px 20px rgba(0, 0, 0, 0.12);
overflow: hidden;
}
Is it possible to achieve the same functionality using position: relative; on the "menu-item" (.collapse) as well?
NOTE: Before you submit an answer with a fiddle, please do make sure that the menus in both fiddles (yours and mine) are functioning the same by clicking on each menu and comparing (so as to confirm that no menu-items are misplaced due to change in positioning).
You may add extra bits of HTML and CSS, of course.
And yes, I tried for hours in vain, and wanted to see if it's at all possible.

How about something like this:
Remove the width from .collapse.
Remove float from the columns, change to inline-block.
Change white-space to nowrap.
Html:
<div class="in collapse" id="channels-menu-item-container" style="height: auto;">
<div id="channels-menu-item-wrapper">
<ul class="channel-column" id="nav-channels">
<!-- ... -->
</ul>
<ul class="channel-column" id="nav-topics">
<!-- ... -->
</ul>
<ul class="channel-column" id="nav-editions">
<!-- ... -->
</ul>
<div class="aahans"></div>
<div class="clearfix"></div>
</div>
</div>
Css:
.collapse {
position: absolute;
min-width:200px; /*for the seach box*/
/* ... */
}
#channels-menu-item-wrapper {
border-bottom: 4px solid #259;
white-space:nowrap;
}
.channel-column {display:inline-block; vertical-align:top;}
You may also want to reset the white-space value in each .channel-column.
Result: http://jsfiddle.net/kobi/fxSYT/1/embedded/result/

Related

Using bootstrap Well class for hover effect

I have 3 elements(p elements) inside a row class ( with col-md-4 each). Now I want to pass a class ( "well" ) on hover, so that whenever mouse hovers they each element can have an individual well class. I can do it without hover but with hover, I am struggling. Can anybody help?
use jquery to apply the class on hover:
$('.myText').mouseenter(function(){
$(this).addClass("well");
});
$('.myText').mouseleave(function(){
$(this).removeClass("well");
});
Use CSS
I would recommend you to do this in CSS alone. All you want is to have the well effect on your p tag when user hovers the mouse on the element. Instead of using Jquery and adding removing the classes its better if you pull out the bootstrap well style definition and use it on your p:hover rule.
The bootstrap definition of well is as below.
.well {
min-height: 20px;
padding: 19px;
margin-bottom: 20px;
background-color: #f5f5f5;
border: 1px solid #e3e3e3;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .05);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .05);
}
All you have to do is to add this custom CSS rule in your page
.YourMainDivClass p:hover {
min-height: 20px;
padding: 19px;
margin-bottom: 20px;
background-color: #f5f5f5;
border: 1px solid #e3e3e3;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .05);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .05);
}
Here the idea with YourMainDivClass is that your p tag must be a part of div (as understood by your question), And you don't want this effect to work on all the p tags in your page. So to restrict the effect to specific group I have used the parent class in the selector.
Hope this helps!!
You can simply use jQuery's mouseenter and mouseleave functions:
$('p').mouseenter(function() {
$(this).addClass("well");
});
$('p').mouseleave(function() {
$(this).removeClass("well");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-4">
<p>Item</p>
</div>
<div class="col-md-4">
<p>Item</p>
</div>
<div class="col-md-4">
<p>Item</p>
</div>
</div>
</div>
Of course you should change the selectors for your needs.

CSS not inheriting parent class properties

I have the following HTML
<div id="borderContainer" class="scViewer" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline',gutters:false">
<div id="buttonPagerContentPane" data-dojo-type="dijit/layout/ContentPane" align="center" data-dojo-props="region:'bottom'" class="buttonContentPane">
<div id="buttonPagerTitle" class="ContentPaneTitle">
Sheet Selector <br>
</div>
<button data-dojo-type="dijit/form/Button" type="button" data-dojo-attach-point="PreviousButtonAttachNode" id="previousButton" class="scViewButtonContent buttonContentPane">
Previous
</button>
<button data-dojo-type="dijit/form/Button" type="button" data-dojo-attach-point="NextButtonAttachNode" id="nextButton" class="scViewButtonContent">
Next
</button>
</div>
</div>
And the following CSS:
.scViewer {
color: #2546ff;
}
.scViewer .buttonContentPane {
padding: 5px 5px;
color:#FFFFFF;
border-radius: 5px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
}
.scViewer .ContentPaneTitle{
color: #2546ff;
font-weight: bold;
}
.scViewer .buttonContentPane .scViewButtonContent{
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.4);
text-decoration: none;
}
My problem is that the two previous/next buttons don't inherit the buttonContentPane class without explicitly defining it again, even though it is within the parent buttonPagerTitle <div> ..To demonstrate this above, I explicitly define the nextButton without the buttonContentPane property, and the resultant HTML in the dev tools does not contain the buttonContentPane in the defined, but the inherited section contains buttonContentPane with its properties grayed out:
My overall goal is to boilerplate CSS code for re-use within my organization. Is my syntax wrong? Did I structure the selectors improperly? Thank you for your time
I assume you want your 'next' and 'previous' buttons to inherit these properties:
.scViewer .buttonContentPane {
padding: 5px 5px;
color:#FFFFFF;
border-radius: 5px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
}
Unfortunately (for you), not all properties are inherited by an element's children/descendants, and not all elements will inherit from their parents/ancestors. You're experiencing both problems.
Padding, border-radius, and box-shadow aren't automatically inherited: https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/Cascade_and_inheritance
Color usually is inherited but buttons are form elements, and form elements don't inherit properties from their parents: Why are CSS-styles not inherited by HTML form fields?
You'll need to either directly add the class to the buttons if you want them to be styled correctly (as you mentioned you did in your question), or you'll need to write rules in your CSS that explicitly state the buttons should inherit properties from their parents.
The following is a simple example showing how to explicitly tell an element to inherit properties from its parent. Click "Run code snippet" to see the resulting buttons.
.wrapper1,
.wrapper2 {
color:red;
padding: 20px;
box-shadow: 0 0 3px rgba(0,0,0,0.4);
border-radius: 10px;
margin: 10px;
width: 100px;
}
.wrapper2 button {
color: inherit;
padding: inherit;
box-shadow: inherit;
border-radius: inherit;
border: none;
}
<div class="wrapper1">
This button doesn't inherit.
<button>My button</button>
</div>
<div class="wrapper2">
This button does inherit.
<button>My button</button>
</div>

Style file input

I want to update this file input to look like the image I've attached.
Currently I have this view:
http://davis-design.de/marktadresse/mein-profil.html
But I would like it to look like the following:
My current attempt:
<span class="btn">
<span class="fileupload-new">Bild auswählen</span>
<span class="fileupload-exists">Ändern</span>
<input type="file" name="bild" id="bild">
</span>
How would I go about styling the default file input element?
Just as a word of warning from past experience, certain methods of styling a file upload doesn't always work cross browser, and has given me some gray hair. But I believe the below solution should work for most cases
Based on the answer from #BjarkeCK
https://stackoverflow.com/a/9182787/1105314
Fiddle
http://jsfiddle.net/D9T4p/1/
Markup
<div style="padding:100px;">
<div class="uploadButton">
BILD AUSWÄHLEN
<input type="file" />
</div>
</div>
Javascript
$(function() {
$(".uploadButton").mousemove(function(e) {
var offL, offR, inpStart
offL = $(this).offset().left;
offT = $(this).offset().top;
aaa= $(this).find("input").width();
$(this).find("input").css({
left:e.pageX-aaa-30,
top:e.pageY-offT-10
})
});
});
CSS
.uploadButton input[type="file"] {
cursor:pointer;
position:absolute;
top:0px;
opacity:0;
}
.uploadButton {
position:relative;
overflow:hidden;
cursor:pointer;
/*** (Copied from the link you supplied) ***/
text-transform: uppercase;
font-size: 13px;
font-family: 'Roboto',Arial,sans-serif;
padding: 8px 22px;
display: inline-block;
-moz-border-radius: 2px;
border-radius: 2px;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
text-align: center;
vertical-align: middle;
cursor: pointer;
-webkit-box-shadow: 0 -2px 0 rgba(0, 0, 0, 0.1) inset;
-moz-box-shadow: 0 -2px 0 rgba(0, 0, 0, 0.1) inset;
box-shadow: 0 -2px 0 rgba(0, 0, 0, 0.1) inset;
color: #FFF;
background-color: #2561BA;
}
Update
CSS only solution:
http://geniuscarrier.com/how-to-style-a-html-file-upload-button-in-pure-css/
You can use jqtransform here to customize your input type here
There is a easy css-only solution. you don't need any javascript for it. so - just dont.
The keyword of the solution is: <label>.
Label? - Yes a label!
The simple HTML Element. You can easily style an <label> element.
Here is a sample:
HTML
<label for"foo"></label>
<input type="file" id="foo"/>
CSS
label {
cursor: pointer;
}
#foo {
height: 0.1px;
width: 0.1px;
z-index: -1;
}
You dont use the input element itself. You'll use the label instead. If you click on the label, you'll get referenced to the 'real' input element and its functionality.

Place a circle outside every <article>

I have a liste of articles in my HTML code, I would like to place a circle to the left of every article. Which means that if there is a way to do it without having to manually place the circle next to every article that would be perfect.
The idea is to place the circle exactly where I've already place a vertical line (which is just basically a div with 100% height) so that it could create a sort of timeline effect.
Because the whole idea is to have this timeline (the line with each circles next to each article) and a year right next to the circle.
To make sure I was clear enough I've quickly made a picture on Photoshop of the result I have in mind. The grey circle is the same for every article, the white rectangle should be able to contain text.
Here's the HTML for the articles
<section class="content">
<article class="CV">
<h1>Lorem ipsum dolor sit amet</h1>
<p>
Lorem ipsum ...
</p>
</article>
</section>
And the CSS for the , the and the CV class :
.content
{
position: relative;
top: 50px;
left: 125px;
}
article
{
background-color: #FFFFFF;
border-left: 4px #E52522 inset;
-webkit-box-shadow: 3px 2px 6px 1px rgba(50, 50, 50, 0.45);
-moz-box-shadow: 3px 2px 6px 1px rgba(50, 50, 50, 0.45);
box-shadow: 3px 2px 6px 1px rgba(50, 50, 50, 0.45);
}
.CV
{
display: block;
padding : 5px;
margin: 20px 0px;
opacity: 0.9;
max-width: 800px;
}
And the code for what I intended to be the line (but it doesn't quite work, its only the size of the browser's window):
#timeline
{
background-image: url('img/tweed.png');
width: 8px;
height: 100%;
position: absolute;
left: 50px;
-webkit-box-shadow: 2px 0px 6px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 2px 0px 6px 0px rgba(50, 50, 50, 0.75);
box-shadow: 2px 0px 6px 0px rgba(50, 50, 50, 0.75);
}
If my question is unclear, please let me know. Thank you.
Edit: I can give you more of the code if needed.
You can use the ::before pseudo element:
article:before{
position:absolute;
height:40px;
width:40px;
border-radius:20px;
background-color:#777;
content:'';
display:block;
top:10px;
left:-90px;
}
The specific styles are up to you. Your articles need to be positioned relatively.
JSFiddle
you'll need to add a new element for the year to to your article tag
<article>
<span class="timestamp">2014</span>
...
</article>
and then add these to your css
article { position: relative }
article .timestamp { position: absolute; left: ??px; top: ??px; }
article .timestamp:before { content:''; width: 50px; border-radius: 50%; }
more details here: http://jsfiddle.net/RdXw9/1/
Try just putting the circle inside the article and then positioning the div img tag right: "x"px...
kinda a hacky way to do it, I'm sure li styles may be better but... that should work
edit: example
CSS
#article img {
position:relative:right:50px;
}
html:
<div id="article" class="CV">
<img src="#"> CIRCLE </img>
<h1>Lorem ipsum dolor sit amet</h1>
<p>
Lorem ipsum ...
</p>
</div>

CSS box-shadow to one direction

I am requested to make the following design:
Here's how I'm trying to achieve the cascaded shadow:
box-shadow: -6px 0px 10px #514E49
But it results in the shadow being displayed in the opposite direction:
I tried changing the h-shadow parameter to 6px, but then the shadow is only visible in the rightmost edge.
I tried using inset as Emil suggested, but it causes the v-shadow to display inset as well and becomes visible inside the box, which should be avoided, here is what it looks like:
try this:
box-shadow:inset 6px 0px 10px #514E49;
edit:
box-shadow: 6px 0px 10px #514E49;
float:right;
http://jsfiddle.net/6V7Et/4/
you have to reverse the order of the menu
Another way to avoid float:right and reversing the menu is by using a negative spread and increased h-shadow like this:
.box {
background: #817E77;
display: inline-block;
width: 100px;
height: 40px;
box-shadow: inset 10px 0px 10px -4px #514E49;
float:left;
}
jsFiddle result
I believe this will best be tackled with z-index since your problem is the other divs are hiding the previously rendered ones.
so:
.box {
....your stuff here....
float:right
}
http://jsfiddle.net/XKNn4/
Another solution, one that doesn't involve reversing the order of the menu or using z-index would be to put the box-shadow on a pseudo-element.
demo
Relevant CSS:
li {
overflow: hidden;
position: relative;
box-shadow: 6px 0px 10px #514E49;
/* the other styles */
}
li:not(:first-child):after {
position: absolute;
right: 100%; width: 100%; height: 100%;
box-shadow: 6px 0px 10px #514E49;
content: '';
}