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>
Related
Here is my issue. I have 2 css classes, my elements can have either
.classA{box-shadow:inset -2px 0px 0px 0px rgba(63,191,31,1);}
.classB{box-shadow:inset -2px 0px 0px 0px rgba(204,29,29,1);}
I wish to use a third class to change the inset but not the color
.classC{box-shadow:inset -10px 0px 0px 0px;}
That works (the shadow is here) but the color turns black. I would like to keep my original color.
How to change the shadow properties using CSS ONLY without losing the color?
Box-shadow cannot be broken into parts like for example border can. But a trick you can use is that box-shadow inherits its color from the color attribute of the element.
<div class="box">
</div>
<div class="shadow box">
</div>
.box{
box-shadow: 0 0 10px;
width: 100px;
height: 100px;
margin: 10px;
background: #fff;
}
.box.shadow{
color: rgba(255,0,0,.3);
}
http://jsfiddle.net/82z8r73o/
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.
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.
I have a problem with the CSS precedence of an input box. A width of 96% is being applied while according to precedence rules an auto width should be applied. If I apply !important, the style I want is applied. However this is not how I would like to solve the problem.
I have an input box implemented in this way
<fieldset>
<label>Search</label>
<input type="text" class="standard-size"> <!-- Referring to this -->
</fieldset>
And impacted by these 2 CSS declarations:
fieldset input[type=text] {
width: 96%;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px solid #BBBBBB;
height: 20px;
color: #666666;
-webkit-box-shadow: inset 0 2px 2px #ccc, 0 1px 0 #fff;
-moz-box-shadow: inset 0 2px 2px #ccc, 0 1px 0 #fff;
box-shadow: inset 0 2px 2px #ccc, 0 1px 0 #fff;
padding-left: 10px;
background-position: 10px 6px;
margin: 0;
display: block;
float: left;
margin: 0 10px;
}
.standard-size {
width: auto ;
}
According to this link:
http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/
precedence works this way
(Inline Style , ID, Class, Element). A number on the left precedes any number on the right.
In my case:
fieldset input[type=text] translates to (0,0,0,2) because fieldset and input are 2 elements
AND
.standard-size translates to (0,0,1,0) because .standard-size is one CSS class
(0,0,1,0) should take precedence over (0,0,0,2) because the 1 is simply more to the left than the 2 and that makes it more important. So why is the width of 96% taking over?
Thank you
You forgot to count the [type=text] attribute selector, which is equivalent to a class selector (also mentioned in the article you linked to):
fieldset input[type=text] /* 1 attribute, 2 types -> specificity = (0, 0, 1, 2) */
.standard-size /* 1 class -> specificity = (0, 0, 1, 0) */
While an attribute selector and a class selector are equivalent, it's the two type selectors in your first rule that cause it to outweigh the second.
Because [type=text] is an attribute, it adds (0,0,1,0) (source). So your first set of rules actually has specificity (0,0,1,2), which is greater than (0,0,1,0).
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/