Can you style html form buttons with css? - html

I don't like the default button style. It's really boring. I am using
<input type="submit">
type buttons. Can I style these somehow in css? If not, the other way of doing it i guess would be to use a div instead, and make it a link. How do you make those work with forms?

You can achieve your desired through easily by CSS :-
HTML
<input type="submit" name="submit" value="Submit Application" id="submit" />
CSS
#submit {
background-color: #ccc;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius:6px;
color: #fff;
font-family: 'Oswald';
font-size: 20px;
text-decoration: none;
cursor: pointer;
border:none;
}
#submit:hover {
border: none;
background:red;
box-shadow: 0px 0px 1px #777;
}
DEMO

Yeah, it's pretty simple:
input[type="submit"]{
background: #fff;
border: 1px solid #000;
text-shadow: 1px 1px 1px #000;
}
I recommend giving it an ID or a class so that you can target it more easily.

Yes you can target those specificaly using input[type=submit] e.g.
.myFormClass input[type=submit] {
margin: 10px;
color: white;
background-color: blue;
}

You can directly create your own style in this way:
input[type=button]
{
//Change the style as you like
}

You might want to add:
-webkit-appearance: none;
if you need it looking consistent on Mobile Safari...

write the below style into same html file head section or write into a .css file
<style type="text/css">
.submit input
{
color: #000;
background: #ffa20f;
border: 2px outset #d7b9c9
}
</style>
<input type="submit" class="submit"/>
.submit - in css . means class , so i created submit class with set of attributesand applied that class to the submit tag, using class attribute

Related

How to create a square that redirects you in CSS

I have looked everywhere for an answer for this but to no avail, I want to create a button that is a square. When your mouse goes over any part of the square I need it to be clickable. I'm very new to CSS so an example would be nice, thank you.
You can style the button like this.
.btn {
border: 2px outset green;
background-color: lightGreen;
height:75px;
width:75px;
cursor:pointer;
text-align: center;
margin: 4px 2px;
}
.btn:hover {
background-color: green;
color:white;
}
And apply this style class to the button.
<button class= "btn" onclick="myFunction()"> Click Here </button>
you can make button with tag <a> ... </a>, for example:
<a class="btn" href="www.facebook.com">Facebook</a>
and make the style:
.btn {border: 1px solid black; padding: 10px; text-decoration: none;}

Button Links in HTML [duplicate]

I'm using ASP.NET, some of my buttons just do redirects. I'd rather they were ordinary links, but I don't want my users to notice much difference in the appearance. I considered images wrapped by anchors, i.e. tags, but I don't want to have to fire up an image editor every time I change the text on a button.
Apply this class to it
.button {
font: bold 11px Arial;
text-decoration: none;
background-color: #EEEEEE;
color: #333333;
padding: 2px 6px 2px 6px;
border-top: 1px solid #CCCCCC;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-left: 1px solid #CCCCCC;
}
Example
Why not just wrap an anchor tag around a button element.
<button type="button">Text of Some Page</button>
This will work for IE9+, Chrome, Safari, Firefox, and probably Opera.
IMHO, there is a better and more elegant solution. If your link is this:
Click me!!!
The corresponding button should be this:
<form method="GET" action="http://www.example.com">
<input type="submit" value="Click me!!!">
</form>
This approach is simpler because it uses simple html elements, so it will work in all the browsers without changing anything. Moreover, if you have styles for your buttons, this solution will apply the same styles to your new button for free.
The CSS3 appearance property provides a simple way to style any element (including an anchor) with a browser's built-in <button> styles:
a.btn {
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
}
<body>
<a class="btn">CSS Button</a>
</body>
CSS Tricks has a nice outline with more details on this. Keep in mind that no version of Internet Explorer currently supports this according to caniuse.com.
If you want nice button with rounded corners, then use this class:
.link_button {
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
border: solid 1px #20538D;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.4);
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
background: #4479BA;
color: #FFF;
padding: 8px 12px;
text-decoration: none;
}
Example
a {
display: block;
height: 20px;
width: auto;
border: 1px solid #000;
}
You can play with <a> tags like this if you give them a block display. You can adjust the border to give a shade like effect and the background color for that button feel :)
As TStamper said, you can just apply the CSS class to it and design it that way. As CSS improves the number of things that you can do with links has become extraordinary, and there are design groups now that just focus on creating amazing-looking CSS buttons for themes, and so forth.
For example, you can transitions with background-color using the -webkit-transition property and pseduo-classes. Some of these designs can get quite nutty, but it's providing a fantastic alternative to what might in the past have had to have been done with, say, flash.
For example (these are mind-blowing in my opinion),
http://tympanus.net/Development/CreativeButtons/ (this is a series of totally out-of-the-box animations for buttons, with source code on the originating page).
http://www.commentredirect.com/make-awesome-flat-buttons-css/ (along the same lines, these buttons have nice but minimalistic transition effects, and they make use of the new "flat" design style.)
You may do it with JavaScript:
Get CSS styles of real button with getComputedStyle(realButton).
Apply the styles to all your links.
/* javascript, after body is loaded */
'use strict';
{ // Namespace starts (to avoid polluting root namespace).
const btnCssText = window.getComputedStyle(
document.querySelector('.used-for-btn-css-class')
).cssText;
document.querySelectorAll('.btn').forEach(
(btn) => {
const _d = btn.style.display; // Hidden buttons should stay hidden.
btn.style.cssText = btnCssText;
btn.style.display = _d;
}
);
} // Namespace ends.
<body>
<h3>Button Styled Links</h3>
<button class="used-for-btn-css-class" style="display: none"></button>
first
second
<button>real button</button>
<script>/* You may put JS here. */</script>
</body>
You could create a standard button, then use it as the background image for a link. Then you can set the text in the link without changing the image.
The best solutions if you don't a special rendered button are the two already given by TStamper and Ólafur Waage.
This gets into the details of the css a bit more too, and gives you some images:
http://www.dynamicdrive.com/style/csslibrary/item/css_square_buttons/
Much belated answer:
I've been wrestling with this on and off since I first started working in ASP. Here's the best I've come up with:
Concept: I create a custom control that has a tag. Then in the button I put an onclick event that sets document.location to the desired value with JavaScript.
I called the control ButtonLink, so that I could easily get if confused with LinkButton.
aspx:
<%# Control Language="VB" AutoEventWireup="false" CodeFile="ButtonLink.ascx.vb" Inherits="controls_ButtonLink" %>
<asp:Button runat="server" ID="button"/>
code behind:
Partial Class controls_ButtonLink
Inherits System.Web.UI.UserControl
Dim _url As String
Dim _confirm As String
Public Property NavigateUrl As String
Get
Return _url
End Get
Set(value As String)
_url = value
BuildJs()
End Set
End Property
Public Property confirm As String
Get
Return _confirm
End Get
Set(value As String)
_confirm = value
BuildJs()
End Set
End Property
Public Property Text As String
Get
Return button.Text
End Get
Set(value As String)
button.Text = value
End Set
End Property
Public Property enabled As Boolean
Get
Return button.Enabled
End Get
Set(value As Boolean)
button.Enabled = value
End Set
End Property
Public Property CssClass As String
Get
Return button.CssClass
End Get
Set(value As String)
button.CssClass = value
End Set
End Property
Sub BuildJs()
' This is a little kludgey in that if the user gives a url and a confirm message, we'll build the onclick string twice.
' But it's not that big a deal.
If String.IsNullOrEmpty(_url) Then
button.OnClientClick = Nothing
ElseIf String.IsNullOrEmpty(_confirm) Then
button.OnClientClick = String.Format("document.location='{0}';return false;", ResolveClientUrl(_url))
Else
button.OnClientClick = String.Format("if (confirm('{0}')) {{document.location='{1}';}} return false;", _confirm, ResolveClientUrl(_url))
End If
End Sub
End Class
Advantages of this scheme: It looks like a control. You write a single tag for it, <ButtonLink id="mybutton" navigateurl="blahblah"/>
The resulting button is a "real" HTML button and so looks just like a real button. You don't have to try to simulate the look of a button with CSS and then struggle with different looks on different browsers.
While the abilities are limited, you can easily extend it by adding more properties. It's likely that most properties would just have to "pass thru" to the underlying button, like I did for text, enabled and cssclass.
If anybody's got a simpler, cleaner or otherwise better solution, I'd be happy to hear it. This is a pain, but it works.
This is what I used. Link button is
<div class="link-button">Example</div>
CSS
/* body is sans-serif */
.link-button {
margin-top:15px;
max-width:90px;
background-color:#eee;
border-color:#888888;
color:#333;
display:inline-block;
vertical-align:middle;
text-align:center;
text-decoration:none;
align-items:flex-start;
cursor:default;
-webkit-appearence: push-button;
border-style: solid;
border-width: 1px;
border-radius: 5px;
font-size: 1em;
font-family: inherit;
border-color: #000;
padding-left: 5px;
padding-right: 5px;
width: 100%;
min-height: 30px;
}
.link-button a {
margin-top:4px;
display:inline-block;
text-decoration:none;
color:#333;
}
.link-button:hover {
background-color:#888;
}
.link-button:active {
background-color:#333;
}
.link-button:hover a, .link-button:active a {
color:#fff;
}
How about using asp:LinkButton?
You can do that - I made a linkbutton look like a standard button, using TStamper's entry. Underlining showed under the text when I hovered, though, in spite of the text-decoration: none setting.
I was able to stop the hover-underlining by adding style="text-decoration: none" within the linkbutton:
<asp:LinkButton
id="btnUpdate"
CssClass="btnStyleTStamper"
style="text-decoration: none"
Text="Update Items"
Onclick="UpdateGrid"
runat="server"
/>
By using border, color and background color properties you can create a button lookalike html link!
a {
background-color: white;
color: black;
padding: 5px;
text-decoration: none;
border: 1px solid black;
}
a:hover {
background-color: black;
color: white;
}
<a href="https://stackoverflow.com/
">Open StackOverflow</a>
Hope this helps :]
Use this class. It will make your link look the same as a button when applied using the button class on an a tag.
or
HERE IS ANOTHER DEMO JSFIDDLE
.button {
display: inline-block;
outline: none;
cursor: pointer;
border: solid 1px #da7c0c;
background: #478dad;
text-align: center;
text-decoration: none;
font: 14px/100% Arial, Helvetica, sans-serif;
padding: .5em 2em .55em;
text-shadow: 0 1px 1px rgba(0,0,0,.3);
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-radius: .3em;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.button:hover {
background: #f47c20;
background: -webkit-gradient(linear, left top, left bottom, from(#f88e11), to(#f06015));
background: -moz-linear-gradient(top, #f88e11, #f06015);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f88e11', endColorstr='#f06015');
}
.button:active {
position: relative;
top: 1px;
}
HTML
<a class="btn">Button</a>
CSS
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
.button {
font: bold 11px Arial;
text-decoration: none;
background-color: #EEEEEE;
color: #333333;
padding: 2px 6px 2px 6px;
border-top: 1px solid #CCCCCC;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-left: 1px solid #CCCCCC;
}
Example
I use an asp:Button:
<asp:Button runat="server"
OnClientClick="return location='targetPage', true;"
UseSubmitBehavior="False"
Text="Button Text Here"
/>
This way, the operation of the button is completely client-side and the button acts just like a link to the targetPage.
Use below snippet.
.a{
color: $brn-acc-clr;
background-color: transparent;
border-color: #888888;
&:hover:active{
outline: none;
color: #888888;
border-color: #888888;
}
&:fill{
background-color: #888888;
color: #fff;
box-shadow: 0 3px 10px rgba(#888888, 0.5);
&:hover:active{
color: #fff;
}
&:hover:not(:disabled){
transform: translateY(-2px);
background-color: darken(#888888, 4);
}
}
}
Simple button css now you can play around with your editor
a {
display: inline-block;
background: #000000c9;
color: #000;
padding: 12px 24px;
text-align: center;
text-decoration: none;
font-size: 16px;
cursor: pointer;
}
a:hover {
background:#000
cursor: pointer;
transition: 0.3s ease-in;
}
Link tag
<a href="#">Hover me<a>
If you need some cool effect, hover and shadow; you can use this:
.button {
text-decoration: none;
padding: 15px 25px;
font-size: 24px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #450775;
border: none;
border-radius: 15px;
box-shadow: 0 9px #e1d5ed;
}
.button:hover {background-color: #220440}
.button:active {
background-color: #230545;
box-shadow: 0 5px #e1d5ed;
transform: translateY(4px);
}
This worked for me. It looks like a button and behaves like a link. You can bookmark it for example.
<a href="mypage.aspx?param1=1" style="text-decoration:none;">
<asp:Button PostBackUrl="mypage.aspx?param1=1" Text="my button-like link" runat="server" />
</a>
How about using asp:LinkButton?

How Can I customize browse button like this? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
This is an image of a browse button for uploading file. I want to craete a browse button like in this image. How can I do that?
Here's how you do it! Steps:
We use <input type=file> for uploading files. But we don't actually display it.
We use our own customized button and redirect all clicks to our <input type=file>.
Every time our <input type=file> changes its value, we display it in our span.
We style our file browser form to anything we like.
The following were made similar to the image, as close as possible.
.browse-field {
position: relative;
display: inline-block;
font-family: Arial, sans-serif;
font-size: 15px;
color: #999;
border-radius: 5px;
border: 1px solid #CACACA;
background-image: linear-gradient(rgba(0,0,0,0.15), transparent 13%);
}
.browse-field>input[type=file] { display: none; }
.browse-field .file {
display: inline-block;
margin: 0 0 0 0.8em;
min-width: 25ch; /* Modify as needed! */
}
.browse-field .btn {
margin: 6px 9px;
padding: 5px 14px;
outline: none;
border: none;
border-radius: 4px;
background: #CACACA;
color: #FFF;
font: inherit;
}
/* Modify the following styles as desired */
.browse-field .btn:hover { background: #DADADA; }
.browse-field .btn:active { background: #CACACA; }
.browse-field .btn:focus { box-shadow: 0 0 0 2px rgba(0,0,0,0.1); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(function(){
$(".browse-field>input[type=file]").each(function(){
var inpfile = $(this);
inpfile.change(function(){
inpfile.siblings(".file").text(this.value)
})
inpfile.siblings(".btn").click(function(){
inpfile.click();
})
})
})
</script>
<div class=browse-field>
<input type=file>
<span class=file>No file selected.</span>
<button class=btn>Browse</button>
</div>
Check out this website: http://css3buttongenerator.com
It will help you creating a Button like in your link.
I think do you need this. Chick it out on : click
<div>
<form>
<input type="text" name=""/>
<input type="submit" value="Submit" class="button"/>
</form>
</div>
Css
form input {
border:0px;
margin:0px;
padding:0px;
}
form .button{
padding:5px;
border-radius:3px;
}
div {
border:1px solid #B2B2B2;
border-radius:3px;
width:33%;
height:auto;
padding:5px;
}

Set default css of input type button

I am applying a background image on input type button. for this i have written my code in style.css. But now i want that button will look like as it is default, but my restriction is that i can not delete css style from style.css. But i can override it in other css style1.css.
so how can i override this?
style.css
button
{
background:red;
}
if i override like this it shows nothing.
style1.css
button
{
background:none;
}
Probably a duplicate question for Can you style html form buttons with css?.
Well, as far as button or any other input type is considered you can do that by adding this:
HTML
<input type="submit" name="submit" value="Submit Application" id="submit" />
CSS
#submit {
background-color: #ccc;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius:6px;
color: #fff;
font-family: 'Oswald';
font-size: 20px;
text-decoration: none;
cursor: poiner;
border:none;
}
#submit:hover {
border: none;
background:red;
box-shadow: 0px 0px 1px #777;
}
You can even try this,
input[type="submit"]{
background: #fff;
border: 1px solid #000;
text-shadow: 1px 1px 1px #000;
}
or even, you can add a class:
.my_button_type
{
background: #fff;
border: 1px solid #000;
text-shadow: 1px 1px 1px #000;
}
You can apply inline styling also:
<input type="button" style="background: #333; border: 0px;" />
So, you have many ways to do it.
You can either use inline styles, or use !important.
Example:
style1.css
button
{
background:none !important;
}
Or inline:
<button style="background: none;">
You can do it like this...
button { background:none !important; }
First, precedence is important:
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="style1.css" />
You must put the css file after the original css that you want to overwrite.
Second, in your style1.css, there are so many approach do achieve what you want. Like cancelling out the css style that you want to overwrite
//style.css
button {
background: url("...");
}
//style1.css
button {
background: none;
}
or using !important to attributes you want to implement.

Forms and buttons

I would like to have some guidance on how to make good forms with submit buttons that look flat but not like the default ones that are done when using html. I want the submit buttons like those found on this website.
You should try applying CSS to your submit buttons like follow:
<head>
.......
your html code
.....
<style>
.pass {
width: 105px;
padding: 5px;
margin: 2px;
font-weight: bold;
color: #065fba;
background: #f4f5f8;
font-size: 11px;
border: #e2e2e2 1px solid;
}
</style>
</head>
.......
your html code
.....
<input trpe="submit" class="pass" value="Submit" />
......
...
.
Hope this helps.
The css use for the 'Post Your Answer' button on this website is (more or less):
input[type="submit"] {
border: 1px solid #888888;
font-family: Trebuchet MS,Liberation Sans,DejaVu Sans,sans-serif;
font-size: 130%;
font-weight: bold;
margin: 3px;
padding: 2px;
For cross-browser compatibility you'll need to add a class to your <input type="submit" /> as the CSS [type=""] attribute isn't recognised in older versions of Internet Explorer.
If you want to see how any element has been styled on any examples you like the look of, use Firebug or its equivalents for other browsers, which will show you the CSS applicable to a selected element.
In Stack Overflow's case, it's this, with the buttons being wrapped with a <div class="form-submit">:
.form-submit input {
border: 1px solid #888888;
font-family: Trebuchet MS,Liberation Sans,DejaVu Sans,sans-serif;
font-size: 130%;
font-weight: bold;
margin: 3px;
padding: 2px;
}