How to download a file through HTML? - html

Simply put, I want to make an icon button with text that downloads a file when the user clicks it, and my html code isn't doing that. The twist is, I have an icon button elsewhere on my page to do that exact same thing, and that one works.
The reason I'm including this ability twice in my page is because I want the user to be able to download this file no matter where they are in the page. The icon-button-with-text is the expected go-to place to get the file because it has an icon and text explaining what the button does. Here's its example code:
button {
cursor: pointer;
height: 56px;
width: 214px;
margin-bottom: 5%;
border-radius: 4px;
font-family: sans-serif;
font-size: 16px;
line-height: 56px;
filter: drop-shadow(2px 2px 4px rgb(0 0 0/0.75));
}
.button1 {
background: none;
border: none;
outline: 2px black solid;
padding-left: 8.2%;
}
.button1 a {
color: black;
}
.button1 a:hover {
cursor: pointer;
}
.button1 span {
position: absolute;
top: 0px;
left: 42px;
}
.activeState {
display: none;
}
.inactiveState {
position: absolute;
height: 18px;
width: 18px;
top: 8px;
left: 16px;
}
.button1:active .activeState {
display: inline-block;
position: absolute;
height: 18px;
width: 18px;
top: 8px;
left: 16px;
}
.button1:active .inactiveState {
display: none;
}
<button class="button1">
<a href="files\downloadableFile.pdf" download>
<img class="inactiveState" src="graphics\downloadFile_inactive.svg">
<img class="activeState" src="graphics\downloadFile_active.svg">
<span>
Download File
</span>
</a>
</button>
However, the icon-button-with-text is part of the body content, and so will scroll up and out of sight as the user goes through the page. So that the user can download the file no matter where they are in the page, I made an icon-button in my fixed top app bar. Here's its example code:
li {
list-style-type: none;
}
.icon {
width: 24px;
height: 24px;
padding-top: 8px;
text-align: center;
}
.inactiveState {
height: 24px;
width: 24px;
top: 16px;
filter: drop-shadow(2px 2px 4px rgb(0 0 0/0.75));
}
.activeState {
display: none;
height: 24px;
width: 24px;
top: 16px;
margin-left: 12px;
filter: drop-shadow(2px 2px 4px rgb(0 0 0/0.75));
}
li:active .inactiveState {
display: none;
}
li:active .activeState {
display: block;
margin-left: auto;
margin-right: auto;
}
li:hover {
cursor: pointer;
background: none;
outline: 2px black solid;
border-radius: 4px;
}
<li class="icon downloadResume">
<a href="files\downloadableFile.pdf" download>
<img class="inactiveState" src="icons\downloadFile_inactive.svg">
<img class="activeState" src="icons\downloadFile_active.svg">
</a>
</li>
The icon-button was part of a menu of other links, so I made it a list item instead of an actual button.
Both buttons have the same icons and the same link states for those icons. Aside from the icon-button not having text and being a list item instead of a button proper, I don't see any difference between the two.
And yet, when I click on the icon-button, my file downloads. When I click on the icon-button-with-text, the icon state also changes like it's supposed to, but the file doesn't download. There's not even a snackbar in the corner mentioning the address of the file when I hover over the icon-button-with-text, whereas that happens when I hover over the icon-button.
Why is this happening, and what can I do so that the same file downloads from the two buttons?
Thank you in advance!

You must not wrap an anchor in a button. Both elements are clickable, so behavior is not really consistent accross browsers ¹ ²
Alas, W3C's validator reports an error when nesting those elements, so it simply is not valid HTML.
Error: The element a must not appear as a descendant of the button element.
<button>stackoverflow</button>
Instead, replace your button with a div:
<div class="button1">
<a href="files\downloadableFile.pdf" download>
<img class="inactiveState" src="graphics\downloadFile_inactive.svg">
<img class="activeState" src="graphics\downloadFile_active.svg">
<span>
Download File
</span>
</a>
</div>
And of course change your CSS accordingly:
div.button1 {
cursor: pointer;
height: 56px;
width: 214px;
margin-bottom: 5%;
border-radius: 4px;
font-family: sans-serif;
font-size: 16px;
line-height: 56px;
filter: drop-shadow(2px 2px 4px rgb(0 0 0/0.75));
}
.button1 {
background: none;
border: none;
outline: 2px black solid;
padding-left: 8.2%;
}
/* ... */

If file's path is files\downloadableFile.pdf then in href="" set the path and in download="" set the file.
<a href="files" download="downloadableFile.pdf">
<img class="inactiveState" src="icons\downloadFile_inactive.svg">
<img class="activeState" src="icons\downloadFile_active.svg">
</a>

Related

Website button underline won't go away, how can I fix this?

I'm quite new to web development and am making a website for myself. I've come across an issue regarding buttons on my website where the text underline for a button doesn't go away. For some reason, even after applying text-decoration: none !important; it's still there.
A bit of background on what I'm trying to do
I've added two buttons that look the same, but they link to different things. This is because I want the links to change on mobile. In the CSS media query I've specified which button displays on mobile devices. The original buttons are fine, but the ones I want to use on mobile devices have a purple underline for some reason.
I'd love some help to have this sorted out because the underline makes the button look a bit odd when displayed on mobile. I've attached some images and code for one of the buttons below.
Images:
Code:
This is the HTML for a pair of the buttons:
<div class="cont3_left_wrapper">
<h2 class="hd2_1">Header Text</h2>
<p>
Body Text
</p>
<a href="#/" id="header_button_3">
<button type="button" class="btn_chat">Let's Chat</button>
</a>
<a href="#/" id="header_button_3_mob">
<button type="button" class="btn_chat_mob" onClick="location.href='contact.html'">Let's Chat</button>
</a>
</div>
This is the CSS for the buttons:
.btn_chat {
padding: 13px 0 11px 0;
background-color: #E84855;
border-radius: 4px;
border: none;
text-decoration: none;
text-align: center;
font-size: 24px;
font-weight: 700;
color: white;
box-shadow: 0px 2.0407px 20.407px rgba(0, 0, 0, 0.25);
margin-top: 35px;
width: 270px;
}
.btn_chat_mob {
display: none;
padding: 13px 0 11px 0;
background-color: #E84855;
border-radius: 4px;
border: none;
text-align: center;
font-size: 24px;
font-weight: 700;
color: white;
box-shadow: 0px 2.0407px 20.407px rgba(0, 0, 0, 0.25);
margin-top: 35px;
width: 270px;
}
#media screen and (max-width: 480px) {
.btn_chat {
display: none;
width: 100%;
}
.btn_chat_mob {
display: block;
width: 100%;
text-decoration: none !important;
}
}
.btn_chat_mob {
display: inline-block;
width: 100%;
}
Since Your button is inside [a tag] and it has underlined as default CSS you should apply following CSS to [a tag] also it should work..
a {
text-decoration: none;
outline: none;
}
a:hover {
outline: none;
}
a:focus {
outline: none;
}

How to style file input?

Ok so I got the following:
What I want to do is to make the button which says "Elegir archivos" to be orange like the button that says "Finalizar" and make the text the file-input produces grey like the text which says "Formatos aceptados".
Here's what I tried:
<tr>
<td class="upload-pic"><input class="file-submit" type="file" name="fileUpload" size="50" multiple="multiple"/></td>
</tr>
CSS:
.file-submit {
height: 35px !important;
width: 300px !important;
padding: 5px !important;
font-size: 15px !important;
margin-right: 10px !important;
margin-top: 10px !important;
margin-bottom: 20px !important;
background-color:red;
}
input[type="file"] {
width: 80%;
color: white;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
background-color: #FD8907;
margin-left: 10px;
float: right;
}
What I want: The button which says "Elegir archivos" has to be orange with its text in white. The text next to it which says "No se eligio archivo" has to be grey with the white background. For some reason everything ends up in a big orange box and the button still looks like the default one.
In order to achieve that, you can wrap the input button with "label", so that label becomes clickable. Then make your input button opacity 0 (transparent).
$('.file-submit').on('change', function(){
$(this).closest('.btn-wrapper').find('span')
.text('FOTOS Formatos aceptados: JPG');
})
.btn-wrapper {
font-family: 'Veranda', sans-serif;
}
.btn-file {
padding: 8px 15px;
background-color: #fd8907;
border-radius: 3px;
color: #fff;
margin-right: 8px;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}
.btn-file span {
display: block;
color: #777;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td>
<div class="btn-wrapper">
<label class="btn-file">
Elegir archivos
<input type="file" class="file-submit" name="fileUpload" accept=".jpg" multiple="multiple">
</label>
<span>No se eligio archivo</span>
</div>
</td>
But if you want to change the text after file is selected, you will need some help with javascript or jQuery.
Basically what the problem is, that the browser doesn't know that you want it to be orange. Because your file says that it is a button, it is applying the default HTML button style to it. To clear this, in the CSS, all you have to say is:
tr td input.file-submit {
text-decoration: none;
color: #ffffff;
}
Then, just change the color of the text to #848D95.
There you go. Done.
Hope this helps!!!

Apply Dynamic Color Scheme (through class or other means) to HTML Menu Tabs

I am trying to create a custom-made HTML based calendar that displays the past 5 days. I have not yet created the content to be updated once the user clicks on the different dates. I'm actually still stuck on the proper styling. Right now, in its static state, the first tab (the top tab) is selected. I have given it a class to make the font larger and thereby making its containing <li> element larger.
What I would like to do is have the user click on different tabs and have the background color updated to white. From the snippet below, you will see that I got that far. However the color scheme for the other tabs becomes tricky once the user clicks on any given tab. Right now it's a simple gradient, light at the top darker towards the bottom. But suppose the user clicked in the middle. Then the gradient would have to change to have the adjacent tabs directly above and below it to have the 2nd lightest coloring (the lightest would be the active tab, being white). In my css I tried to code that in intuitively by having a class called secondTab.
Question: How do I apply a dynamic color scheme as described above based on user click? In other words, whichever tab the user clicks on will be white, and all the other tabs will update the background-color based on their relational position to the active tab?
.secondTab {
background-color: #cbdeea;
}
.thirdTab {
background-color: #a6cdd9;
}
.fourthTab {
background-color: #77b4c9;
}
.fifthTab {
background-color: #519ab6;
}
.contentTitleSize {
font-size: 50px;
}
.contentTitle {
color: #000;
height: 73px;
margin-top: 27px;
font-family: Play;
}
.contentTitle, .contentArea {
display:inline-block;
}
.contentArea {
height:320px;
width:312px;
margin-left: 25px;
overflow: hidden;
}
.subheading {
font-size: 18px;
height: 20px;
font-family: Play;
color: #77b4c9;
margin-top: 14px;
margin-bottom: 24px;
}
.outerContainer {
width:566px;
display:inline-block;
vertical-align: top;
margin-right: 27px;
}
section {
display:block;
}
*, :after, :before {
-webkit-box-sizing: inherit;
box-sizing: inherit;
}
*, :after, :before {
-webkit-box-sizing: inherit;
box-sizing: inherit;
}
::selection {
background: #b3d4fc;
text-shadow: none;
}
.tabPanel {
display:inline-block;
vertical-align: top;
width:160px;
margin:0;
padding:0;
}
ul {
list-style-type: disc;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;
}
li {
display:list-item;
}
.listTabs {
display:block;
list-style: none;
font-size: 22px;
font-family: Play;
text-align: center;
padding-top: 12px;
padding-bottom: 13px;
color: #fff;
cursor: pointer;
-webkit-box-shadow: inset 0 1px 2.5px 0 rgba(0,0,0,.11);
box-shadow: inset 0 1px 2.5px 0 rgba(0,0,0,.11);
}
.container {
height:320px;
width: 100%;
margin-bottom:24px;
border-radius: 2px;
background-color: #fff;
font-family: Roboto-Regular,serif;
line-height: 1;
box-shadow: 0 2px 5px 0 rgba(0,0,0,.1)
}
.activeFont {
color:#77b4c9;
box-shadow: none;
transition: all .2s linear;
}
.activeTab {
background-color: #fff;
font-size: 50px;
margin-top: 15px;
display:block;
}
.bottomButton {
height: 61px;
background-color: #327ca3;
border-radius: 3px;
font-size: 20px;
font-family: Play;
letter-spacing: .4px;
color: #fff;
text-align: center;
line-height: 61px;
cursor: pointer;
}
<div class="outerContainer">
<section class="container">
<ul class="tabPanel">
<li class="listTabs activeFont" role="button" id="wotdDay0-select">
<span class="activeTab">02</span>
<span>OCT</span>
</li>
<li class="listTabs secondTab" role="button" id="wotdDay1-select">
<span>01</span>
<span>OCT</span>
</li>
<li class="listTabs thirdTab" role="button" id="wotdDay2-select">
<span>30</span>
<span>SEP</span>
</li>
<li class="listTabs fourthTab" role="button" id="wotdDay3-select">
<span>29</span>
<span>SEP</span>
</li>
<li class="listTabs fifthTab" role="button" id="wotdDay4-select">
<span>28</span>
<span>SEP</span>
</li>
</ul>
<div class="contentArea">
<a class="contentTitle contentTitleSize">Content Area</a>
<div class="subheading">
<span>
<strong>First</strong>
"Second and Third"::after
</span>
<span>more info</span>
</div>
<div class="A7AhX">
<p>lots of details</p>
</div>
</section>
<div>
<div class="bottomButton">
Click Me</div>
</div>
</div>

How to create link in content element

I have been tasked with creating this.
I can create the box, font-awesome icon and the non-linking text using a pseudo element content, but I am unable to create the Learn More link (with a span class to include the >).
If I add text directly into the html, it will not fill the box (and spills out below it). I would also be forced to use inline styles to keep it top-aligned with the !.
We want to keep this in the CSS if at all possible. I realize that the real answer is that you can't do it, but I'm looking for a workaround to make it work.
This is the CSS I can use to place the non-linking message:
&:after {
color: #7b7b7b;
margin-top: -43px;
padding-left: 19%;
line-height: 18px;
display: flex;
font-weight: normal;
content: "You are no longer on FPC, you will now be back to your regular contract.";
#media #{$small} {
padding-left: 15%;
margin-top:-37px;
}
}
&:before {
color: #7b7b7b;
margin-left: 10px;
}
And this is the line of HTML:
<i class="fa fa-exclamation-circle"></i>; Learn more <span class="arrow-right"></span>
Does anyone have a solution to help me make this work?
Thanks
Here is a different structure & CSS if you end up going in that direction.
.message {
border: 2px solid #7b7b7b;
border-radius: 2px;
position: relative;
width: 220px;
font-size: 13px;
font-family: Arial;
background: #f7fcff;
padding: 7px 8px 5px 42px;
}
.message>.message-icon {
position: absolute;
color: #7b7b7b;
font-size: 26px;
left: 10px;
}
p {
color: #7b7b7b;
margin: 0 0 3px 0;
}
a {
color: #1464ae;
font-size: 12px;
text-decoration: none;
}
a .action-icon {
margin-left: 3px;
font-size: 10px;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="message">
<span class="message-icon"><i class="fa fa-exclamation-circle"></i></span>
<p>You are no longer on FPC, you will now be back to your regular contract.</p>
<a href="">Learn More
<span class="action-icon"><i class="fa fa-chevron-right"></i></span>
</a>
</div>

Control side that shortens when changing div height on hover

I'm using this hover effect for buttons, but in a few cases when the height changes, the top remains the same and the bottom moves up, instead of vice versa like it should. How can I make sure it always goes in the correct direction?
jsfiddle
.button {
box-sizing: border-box;
display: inline-block;
width: 215px;
height: 55px;
color: white;
font-family: $arial;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
text-align: center;
text-decoration: none;
text-shadow: 1px 1px 1px rgba(43, 36, 36, 0.35);
letter-spacing: .1em;
border-radius: 3px;
position: relative;
background: #009ee0;
border: 1px solid #148fc6;
border-bottom: 4px solid #148fc6;
}
.button:hover {
border-bottom: 1px;
height: 53px;
}
.button span {
position: absolute;
width: 90%;
left: 0;
right: 0;
margin: auto;
top: 50%;
transform: translateY(-43%);
line-height: 1.2;
}
div {
padding: 20px 5px;
}
<div>
<a href="#" class="button">
<span>Wrong way</span>
</a>
</div>
<div>
<a href="#" class="button">
<span>I work fine</span>
</a>
<a href="#" class="button">
<span>I work fine</span>
</a>
</div>
You're reducing the height from 55px to 53px. That 2px has to go somewhere. The top button is just collapsing it. (The bottom two are doing the same, it just doesn't look like it because they are being affected by vertical text alignment). change your hover rule to this to accommodate for the height loss.
.button:hover {
border-bottom: 1px;
margin-top: 2px;
height: 53px;
}
https://jsfiddle.net/exd6hhvz/
I was able to make it work consistently by adding margin-top: 2px; to .button:hover
Here's an example: https://jsfiddle.net/vf03czp5/