How to apply MDL button style to a filePicker? - material-design

I would like to know if there is a way to apply the Material Design Lite button style to a file picker, i.e. a component created on an HTML page via:
<input type="file" id="filePicker" />
I would like the "Browse" button of the component to have the look of a Raised button (with ripple if possible). See http://www.getmdl.io/components/#buttons-section.
Thanks!

Using CSS, do you mean something like this?
<style>#file { display: none }</style>
<input type="file" id="file">
<label for="file" class="mdl-button mdl-js-button mdl-button--fab mdl-button--colored">
<i class="material-icons">+</i>
</label>
https://jsfiddle.net/sj838cLg/

Currently, there's no "official" way of doing that. According to the discussion on this issue, the reason is that there's no Material Design specification for that component, so they don't have a guideline to style it. On that same page, the user kybarg provided a CSS/JavaScript code to style a file picker which kind of matches the Material Design specification, so you can use that code:
HTML:
<form>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" />
<label class="mdl-textfield__label">Name</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text"/>
<label class="mdl-textfield__label">Position</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--file">
<input class="mdl-textfield__input" placeholder="File" type="text" id="uploadFile" readonly/>
<div class="mdl-button mdl-button--primary mdl-button--icon mdl-button--file">
<i class="material-icons">attach_file</i><input type="file" id="uploadBtn">
</div>
</div>
</form>
CSS:
html {
width: 100%;
}
body {
background: #f5f5f5;
margin: 50px auto;
width: 512px;
}
.mdl-button--file {
input {
cursor: pointer;
height: 100%;
right: 0;
opacity: 0;
position: absolute;
top: 0;
width: 300px;
z-index: 4;
}
}
.mdl-textfield--file {
.mdl-textfield__input {
box-sizing: border-box;
width: calc(100% - 32px);
}
.mdl-button--file {
right: 0;
}
}
JavaScript:
document.getElementById("uploadBtn").onchange = function () {
document.getElementById("uploadFile").value = this.files[0].name;
};
But as there's no official specification, you probably won't find an official implementation from the MDL team for now.

Related

Why flex-shrink doesn't work in inline-flex

Why items dont shrink in inline-flex. But it works fine in normal flex. Maybe it is supposed to work that way, I dont know. Maybe it is somewhere in the spec but I coudn't find anything related. I would be grateful if someone could explain this.
.container {
width: 100px;
margin 0 auto;
margin-top: 100px;
background-color: green;
}
.inline-flex {
display: inline-flex;
margin-bottom: 10px;
}
.flex {
display: flex;
}
.item {
width: 50px;
height: 50px;
margin-right: 5px;
background-color: blue;
}
<div class="container">
<div class="inline-flex">
<div class="item">no-shrink</div>
<div class="item">no-shrink</div>
<div class="item">no-shrink</div>
</div>
<div class="flex">
<div class="item">shrink</div>
<div class="item">shrink</div>
<div class="item">shrink</div>
</div>
</div>
As stated before, flex acts like a block and inline-flex like inline-block on the outside and their children behave identically. The flex-items .item are acting totally different when they should appear the same because their behavior is influenced by the flex-container (.flex and .inline-flex). Aside from the flex-containers having different display values, there are no other differences.
Each .item of .inline-flex has retained it's width of 50px
Each .item of .flex has a width of 34.6687px
I still haven't figured out why this is but I have 3 different solutions:
.container is too small, increase it's width.
See Example A
Figure I
.container {
width: 200px;
/* Increase .container to at least the .offsetWidth of the 3 .item`s */
Change the flex properties of .items or assign min-width
See Example B
Figure II
.B .item {
flex: 0 0 50px;
/* OR */
/* min-width: 50px */
}
*,
::before,
::after {
box-sizing: border-box;
}
.container {
width: 100px;
background-color: green;
}
.A {
width: 200px;
}
.inline-flex {
display: inline-flex;
margin-bottom: 10px;
}
.flex {
display: flex;
}
.item {
width: 50px;
height: 50px;
margin-right: 5px;
background-color: blue;
}
.B .item {
flex: 0 0 50px;
/* OR */
/* min-width: 50px */
}
h3 {
margin: 0 0 4px 0
}
<h3>OP</h3>
<div class="container">
<div class="inline-flex">
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
</div>
<div class="flex">
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
</div>
</div>
<h3>Example A</h3>
<div class="container A">
<div class="inline-flex">
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
</div>
<div class="flex">
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
</div>
</div>
<h3>Example B</h3>
<div class="container B">
<div class="inline-flex">
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
</div>
<div class="flex">
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
<div class="item">XXX XXX</div>
</div>
</div>

Negative margin-left to hide left side of element

I need to use a left negative margin so that my element left side would disappear on the left side of the screen.
I tried using position relative but it doesn't work...
<div class="card" id="historyCard">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" id="historyBtn" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
היסטוריה
<img src="images/clock.png" id="hamNavHistoryImg" width="87" height="87"/>
</button>
</h5>
</div></div>
#historyCard {
background-color: #ffb59b;
border-bottom-right-radius: 50%;
border-top-right-radius: 50%;
padding: 30px 0 80px 0;
margin-top: 10px;
z-index: 5;
margin-left:-50px;
}
screenshot

I can not click div with the item class on jquery masonry

I am using the Masonry. I have the fallowing code after masonry loads the page:
<div id="main_container">
<div id="container" class="masonry" style="position: relative; height: 655px; width: 1128px;">
<div class="item masonry-brick" style="position: absolute; top: 0px; left: 0px;">
<img class="images" src="http://www.elektriklihafifticari.com/ca_images/small/67923429.jpg">
<p class="note"></p>
</div>
<div class="item masonry-brick" style="position: absolute; top: 0px; left: 282px;">
<img class="images" src="http://www.elektriklihafifticari.com/ca_images/small/30446134.jpg">
<p class="note"></p>
</div>
</div>
I want to add a new div to the body as i click on any of these 'item masonry-brick' classes.
And i use the fallowing code to make this:
$(".item.masonry-brick").click(function(){
var body_m=$('body');
var blur_div=$('<div></div>');
blur_div.attr('class','blurred');
body_m.prepend(blur_div);
});
Unfortunately it does not work. I tried many diffrent solutions but could not succeed. I realised that if i change the code as:
$("#container").click(function(){
var body_m=$('body');
var blur_div=$('<div></div>');
blur_div.attr('class','blurred');
body_m.prepend(blur_div);
});
i got what i want as i click on the div with the id=container.
Any ideas?
Thanks.
Edited.
Now there is a new problem about the situation:
the html code is:
<div id="container" class="masonry" style="position: relative; height: 335px; width: 846px;">
<div class="item masonry-brick" style="position: absolute; top: 0px; left: 0px;">
<img class="images" src="http://www.dostahediye.com/ca_images/small/230352553.jpg" data-id="1000014037951491000">
<p class="note">teşekkürler</p>
</div>
<div class="item masonry-brick" style="position: absolute; top: 0px; left: 282px;">
<img class="images" src="http://www.dostahediye.com/ca_images/small/660575147.jpg" data-id="1000014037951491001">
<p class="note">5 kişi lütfen</p>
</div>
<div class="item masonry-brick" style="position: absolute; top: 0px; left: 564px;">
<img class="images" src="http://www.dostahediye.com/ca_images/small/474047220.jpg" data-id="1000014037951491002">
<p class="note">7 kişi lütfen</p>
</div>
When i use the code below to recognise which div.item.masonry-brick is clicked, always the first data-id '1000014037951491000' is alerted.
$("#container").on("click",".item.masonry-brick",function(){
var data_id=$('img',this).data('id');
alert(data_id);
Any ideas?
Thanks in advance.
I guess the .item.masonry-brick elements are added dynamically.
You cannot attach events on dynamically generated elements like this,
Use on instead.
$("#container").on("click",".item.masonry-brick",function(){
var body_m=$('body');
var blur_div=$('<div></div>');
blur_div.addClass('blurred');
body_m.prepend(blur_div);
});

How to make parts of a div element resize automatically?

I'm trying to create a small html fragment (a div element) consisted of three parts: a label, textbox, and a button.
Within that div element the label would be on the left (autosized), the button would be on the right (again, autosized) and the textbox should take up all remaining space within the parent div element.
This is what I've tried (assuming I want my div to be 400 pixels wide):
<div style="width:400px">
<div style="float: left">Label</div>
<input style="width:100%"> <!-- doesn't work -->
<button type='button' style='float: right'>Click</button>
</div>
The trouble is, my textbox does not get resized automatically. Add 'width=100%' to the textbox doesn't work.
What would be the way to make it take up all remaining space between the label and the button? Ideally it should be done just by applying some styles, not by introducing new elements.
(I guess the issue isn't related only to div element, but that just happens to be my work scenario.)
Perhaps something like this will be what you want. Yeah I know it's cheating. And yeah, I agree with #Paul re: label, so i swiped his id. :)
EDIT: Obligatory Self-Referencing Demo
Warning: not tested in all browsers.
CSS:
div {
display: table;
width: 400px;
white-space: nowrap;
}
label {
display: table-cell;
padding-right: 3px;
width: 1em;
}
input {
display: table-cell;
width: 100%;
}
span {
display: table-cell;
padding-left: 6px;
width: 1em;
}
HTML:
<div>
<label for="my-very-special-input">Label</label>
<input id="my-very-special-input"/>
<span><button type="button">Click</button></span>
</div>
The only way I could think of making this work was with percents. I enclosed everything in seperate divs (probably uneccesary) and then assigned percentages to each div. Take a look:
<div style="width=400px">
<div style="float:left; width:10%">Label</div>
<div style="float: left; width:70%"><input style="width:100%"></div> <!-- doesn't work -->
<div style="float: right width:20%"><button type='button' style=''>Click</button></div>
It's by no means a perfect solution, but hopefully it will suit your needs to some extent.
Elliott
Does it help if you wrap the <input> in a <div> with overflow: hidden?
<div style="width: 400px;">
<div style="float: left;">Label</div>
<div style="overflow: hidden;">
<input style="width: 100%;">
</div>
<button type="button" style="float: right;">Click</button>
</div>
See xHTML/CSS: How to make inner div get 100% width minus another div width.
And although it’s off-topic, please note that your label should be, well, a <label>.
<div style="width: 400px;">
<label for="my-very-special-input" style="float: left;">Label</label>
<div style="overflow: hidden;">
<input id="my-very-special-input" style="width: 100%;">
</div>
<button type="button" style="float: right;">Click</button>
</div>

How do I align text/images on bottom/right/center/middle of a container using the blueprint css framework?

Is there some easy way to align stuff in div containers to the right or bottom:
<div class="span-24 align-right last">Text appears on the right side of the layout</div>
or:
<div class="span-2" id="lots-of-content"></div><div class="span-22 last bottom">Appears at bottom of container</div>
or:
<div class="span-24 vertical-middle last">Middle of the container</div>
Here's a sample of what I'm working with trying to position the "topnav" below:
<div class="container">
<div class="span-16">
<h1>Header</h1>
</div>
<div class="span-8 last vertical-middle">
<div id="topnav" class="align-right"><input type="button" id="register" class="ui-button ui-state-default ui-corner-all" value="Register" /> or <button type="button" id="signin" class="ui-button ui-state-default ui-corner-all">Sign in</button></div>
</div>
<hr />
...
</div>
Use position: absolute. For example:
.align-right {
position: absolute;
right: 0;
}
/* Or, alternatively, */
.align-right {
float: right;
}
.bottom {
position: absolute;
bottom: 0;
}
.vertical-middle {
position: absolute;
top: 50%;
}
Note that for vertical-middle, this will center the top edge of the content, no the content itself.
Make sure that the containing DIV is position: relative to force it to become the offset parent (which the position of the children are relative to) EDIT: In other words, add the following rule:
.container {
position: relative;
}

Resources