I have two buttons in an html template, one inside a form, the other outside of it. How do I style them via CSS such that they appear inline? Including display: inline in the second button doesn't work.
E.g. looking at the following snippet, how would OK_1 and OK_2 appear inline (using CSS only):
<form action="some_url" method="POST" enctype="multipart/form-data">
<!-- some form -->
<input class="button" type="submit" value="OK_1">
</form>
<button>OK_2</button>
TRY THIS:
Here is a runnable snippet.
form input[type="submit"] {
display: inline-block;
padding: 10px;
background-color: #000000;
color: #ffffff;
float: left;
margin:5px;
}
.button {
display: inline-block;
padding: 10px;
background-color: #000000;
color: #ffffff;
border: 0;
float: left;
margin:5px;
}
<form action="some_url" method="POST" enctype="multipart/form-data">
<!-- some form -->
<input class="button" type="submit" value="OK_1">
</form>
<button class="button">OK_2</button>
You can customize all the styles above.
Simply make the parent a flex container:
body { display: flex; }
<form action="some_url" method="POST" enctype="multipart/form-data">
<!-- some form -->
<input class="button" type="submit" value="OK_1">
</form>
<button>OK_2</button>
In a flex formatting context, flex items (the child elements in a flex container) line up in a row by default.
Adding display: inline-block should do the trick.
form {
display: inline-block;
}
<form action="some_url" method="POST" enctype="multipart/form-data">
<!-- some form -->
<input class="button" type="submit" value="OK_1">
</form>
<button>OK_2</button>
You should give the form a class, so that other forms won't do that.
form.inline_after {
display: inline-block;
}
<pre>↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
↓The form element is <span style="border: 4px dotted red; color: magenta; background-color: maroon;">in red</span>!↓
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓</pre>
<form style="border: 4px dotted red; color: magenta; background-color: maroon;" class="inline_after" action="some_url" method="POST" enctype="multipart/form-data">
<!-- some form -->
<input style="margin: 5px; padding: 5px; color: magenta; background-color: maroon;" class="inline_after" class="button" type="submit" value="Button in the form!" onclick='alert("This is in the "+this.parentElement.nodeName+" element!")'>
</form>
<button style="padding: 5px;" onclick='alert("This is in the "+this.parentElement.nodeName+" element!")'>
Button out of the form, but inline!
</button>
Make css for the form :
form {
float: left;
margin-right: 10px;
}
<form action="some_url" method="POST" enctype="multipart/form-data">
<!-- some form -->
<input class="button" type="submit" value="OK_1">
</form>
<button>OK_2</button>
This is a short answer :)
Related
I have created a simple form like:
class PostForm(FlaskForm):
# for posting a new blog
title = StringField("Title", validators=[DataRequired()])
submit = SubmitField('Post')
And my HTML for the form looks like this:
<div class="post-project-fields">
<form method="POST" action="">
{{ form.hidden_tag() }}
<div class="row">
<div class="col-lg-12">
<!-- <input type="text" name="title" placeholder="Title"> -->
{{ form.title.label }}
{{ form.title }}
</div>
<div class="col-lg-12">
<ul>
<!-- <li><button class="active" type="submit" value="post">Post</button></li> -->
{{ form.submit }}
<li>Cancel</li>
</ul>
</div>
</div>
</form>
</div><!--post-project-fields end-->
The CSS styling for the class post-project-fields looks like:
.post-project-fields {
float: left;
width: 100%;
padding: 30px 20px;
background-color: #121212;
}
.post-project-fields form {
float: left;
width: 100%;
}
.post-project-fields form input {
padding: 0 15px;
height: 40px;
}
.post-project-fields form ul li button,
.post-project-fields form ul li a {
color: #000000;
font-size: 16px;
border: 1px solid #e5e5e5;
padding: 10px 25px;
display: inline-block;
background-color: #d7d7d7;
font-weight: 600;
cursor: pointer;
}
As the css class is like this, it is not styling the way I want, which is how it would look if I used HTML forms only (Only using the commented out lines from the HTML section.)
How do I get the specified styling under the CSS class to be added to the wtforms field?
The elements that are generated by wtforms are different from those you were initially rendering. Some of your css selectors target elements that don't exist on the page anymore.
For example you used a button for submitting the form before
<li><button class="active" type="submit" value="post">Post</button></li>
and you have a selector that targets this: .post-project-fields form ul li button, but
{{ form.submit }}
# renders
<input id="submit" name="submit" type="submit" value="Post">
So create a selector that targets the input instead.
You could also make a more generic selector that targets any element that has a type attribute of value "submit"
[type="submit"] {
color: #000000;
font-size: 16px;
border: 1px solid #e5e5e5;
padding: 10px 25px;
display: inline-block;
background-color: #d7d7d7;
font-weight: 600;
cursor: pointer;
}
Inspect the generated elements in the browser and create your styles around that.
I currently have the two following forms.
form {
text-align: center;
width: 100%;
}
<form>
<input type="text" name="email">
<input type="submit" value="Submit">
</form>
And
input[type=text] {
width: 80%;
padding: 1vh;
}
<form>
<p>First Name:</p>
<input type="text" name="firstname"><br>
</form>
How can I have different rules for each form? The first one needs the contents centre aligned and the second needs the contents aligned left/padded left.
If I change the css for either the alignment and size change.
Thanks in advance.
I've updated the form, how can I have it so that the text input is only styled for the left form? I don't want any text input rules on the center one.
.form-container {
background-color: #ff8e08;
width: 90%;
margin: auto;
}
.center-form {
text-align: center;
width: 100%;
}
.left-form {
text-align: left;
margin-left: 2vh;
}
input[type=text] {
width: 80%;
}
input[type="text"] {
padding: 1vh;
}
<div class="applicationform">
<br>
<form class="left-form">
<p>First Name:</p>
<input type="text" name="firstname">
</form>
</div>
</div>
<br>
<form class= "center-form">
<input type="text" name="email">
<input type="submit" value="Submit">
</form>
Add different class names for them.
CSS:
.center-form {
/* center-form specific rules here */
}
.left-form {
/* left-form specific rules here */
}
HTML:
<form class="center-form">
<input type="text" name="email">
<input type="submit" value="Submit">
</form>
<form class="left-form">
<p>First Name:</p>
<input type="text" name="firstname"><br>
</form>
And if you want to share some of the CSS rules that they both need:
.form {
/* shared CSS rules */
}
Then, add this form class name to both of them in the HTML like this:
<form class="form center-form">
<input type="text" name="email">
<input type="submit" value="Submit">
</form>
<form class="form left-form">
<p>First Name:</p>
<input type="text" name="firstname"><br>
</form>
Remeber, override class names like center-form and left-form should come after this formutility class name.
For your particular case, change your CSS to:
body {
margin: 0; /* Remove user agent default styles */
}
.center-form {
text-align: center;
width: 100%;
}
.left-form {
text-align: left;
margin-left: 2vh;
}
input[type=text] {
width: 80%;
}
input[type="text"] {
padding: 10px;
}
I know this type of question has been asked before, but I couldn't get the answer. I have a contact form, and I want to implement the new Invisible Google Recaptcha. However, I have used an <input> rather than a <button> and I can't figure out how to do this. Here is my code for the contact form I have:
input, textarea {
padding: 5px;
margin: 10px;
font-family: Cambria, Cochin, serif;
font-size: medium;
font-weight: bold;
outline: none;
}
input[type=text], textarea {
width: 350px;
background-color: #b6b6b4;
border: 1px solid #989898;
border-radius: 10px;
}
input[type=submit] {
width: 100px;
background-color: #989898;
border: 1px solid #707070;
font-size: large;
color: #000;
border-radius: 5px;
}
input[type=submit]:hover {
background-color: #848484;
cursor: pointer;
}
input[type=submit]:active {
background-color: #989898;
}
<script src="https://www.google.com/recaptcha/api.js"></script>
<!--CONTACT FORM-->
<form name="contactform" method="post" action="send_form_email.php">
<div>
<input name="name" type="text" placeholder="Name..." required> <br> </div>
<div>
<input name="email" type="text" placeholder="Email..." required>
<br>
</div>
<input type="checkbox" name="maillist" value="1" checked> Subscribe to mailing list<br>
<div>
<input name="game" type="text" placeholder="Game suggestions...">
<br>
</div>
<div>
<textarea cols="30" name="comment" rows="9" placeholder="Comments..."></textarea>
<br> </div>
<div>
<input name="submit" type="submit" value="Submit"> </div>
</form>
Then I have the google ReCaptcha button:
<button
class="g-recaptcha"
data-sitekey="############################"
data-callback="YourOnSubmitFn">
Submit
</button>
Any Help would be appreciated. Also, I was wondering if you could remove the ReCaptcha logo on the bottom right.
try this, It will hide the Google reCaptcha Invisible Badge over the page.
.grecaptcha-badge {
display: none !important;
}
Keep in mind the badge should be displayed as Google pretends the "privacy" and "terms" links to be present.
From the reCaptcha docs check this g-recaptcha tag attributes and grecaptcha.render parameters section:
g-recaptcha tag attribute: data-badge
grecaptcha.render parameter: badge
Value: bottomright
bottomleft
inline
Default: bottomright
Description: Optional. Reposition the reCAPTCHA badge. 'inline' allows you to control the CSS.
This is a basic example
<html>
<head>
<title>reCaptcha example</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
<style>
.grecaptcha-badge {
display: none;
}
</style>
</head>
<body>
<form id="demo-form" action="/post" method="post">
<button data-sitekey="your_site_key" data-callback='onSubmit' data-badge="inline">Login</button>
</form>
</body>
</html>
Set the data-badge attribute to inline, notice the data-badge="inline":
<button type="submit" data-sitekey="your_site_key" data-callback='onSubmit' data-badge="inline">Login</button>
And on the html code:
<style>
.grecaptcha-badge {
display: none;
}
</style>
You could also just add to your CSS:
.grecaptcha-badge {
display: none;
}
I want to check if give margin to divs that I got with foreach
echo "<div id='NotificationsDispl'><a href='main.php?u=".$initiator."'>
<img title='".$initiator."' src='../img/".$_SESSION['pr']."' id='FromsPP'></a>
<a id='NotificationFrom' href='main.php?u=$initiator'>".$initiator." Sent you a friend request</a>
<form class='submitForm Rejecat' method='post' onSubmit='return false;' >
<input value='Reject' type='submit' name='Reject' id='Reject'>
</form>
<form onSubmit='return false;' class='submitForm Accepta' method='post'>
<input name='Accept' type='submit' id='Accept' value='Accept'>
</form>
</div>";
I have got this css code
#NotificationFrom{
margin-left: 125px;
position: absolute;
text-decoration: none;
z-index: 102;
color: black;
margin-top:15px;
}
#NotificationsDispl{
display: list-item;
margin-top: 11px;
padding: 25px;
position: absolute;
}
But it is not working.
try:
<div class='notif_displ' id='NotificationsDispl'>
.notif_displ{
margin-top: 11px !important;
}
As per the jsfiddle, I tired copying your code.
<div id='NotificationsDispl'><a href='main.php?u=".$initiator."'>
<img title='".$initiator."' src='../img/".$_SESSION['pr']."' id='FromsPP'></a>
<a id='NotificationFrom' href='main.php?u=$initiator'>".$initiator." Sent you a friend request</a>
<form class='submitForm Rejecat' method='post' onSubmit='return false;' >
<input value='Reject' type='submit' name='Reject' id='Reject'>
</form>
<form onSubmit='return false;' class='submitForm Accepta' method='post'>
<input name='Accept' type='submit' id='Accept' value='Accept'>
</form>
</div>
#NotificationFrom{
margin-left: 125px;
position: absolute;
text-decoration: none;
z-index: 1;
color: black;
margin-top:15px;
}
#NotificationsDispl{
display: list-item;
margin-top: 11px;
padding: 25px;
position: absolute;
}
Check this link https://jsfiddle.net/p025mpbg/
Therefore, if CSS changes are not being applied,
Do the following:
1. Inspect element on the site by right clicking or pressing f12
2. Check for styling. There must be a CSS from different file that you are using is overwritten and your changes are not being applied.
I'm making a webpage for one of my projects and I'm trying to align the Upload buttons beside a text field. Maybe better explained as a picture. You can see that the two buttons are aligned on the bottom left of the submit button. I want it to be aligned on the left of the device Id text field. I've tried setting the display attributes for the text field, as well as the two buttons but it didn't work. I tried setting the float properties, which also didn't work. I was looking at grids I could possibly use from Purecss.io, but I'm not sure if that would fix the problem. I've tried using vertical-align attribute, still no dough.
I'm using a plain bootstrap theme. My HTML skills are pretty basic coming from Java. Anyone know what I can do here?
Here is my main container:
<div class="container">
<!-- Main content here -->
<div id="main">
<h1 id="mainheader">Send an image to a Wearable device</h1>
<hr>
<form method="post" action="/gcm/gcm.php/?push=true" onsubmit="return checkTextAreaLen()">
<textarea id="deviceID" rows="1" name="message" cols="25" placeholder="Device ID"></textarea> <br/>
<button type="submit" id="mainbutton" class="button-xlarge pure-button">Send Image</button>
</form>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<div id="filebutton">
<input type="file" name="fileToUpload" id="fileToUpload">
</div>
<input type="submit" value="Upload Image" name="submit">
</form>
</div>
Here are my styles
#main {
vertical-align: middle;
}
#status{
text-align: center;
background-color: #FFFFFF;
padding: 10px;
margin-top: 25px;
}
#mainheader{
margin-bottom: 20px;
text-align: center;
font-family: 'Raleway', sans-serif;
}
#deviceID {
display: block;
margin-left: auto;
margin-right: auto;
}
#mainbutton {
display: block;
margin-left: auto;
margin-right: auto;
}
.button-xlarge {
font-size: 125%;
width:350px;
background: rgb(66, 184, 221); /* this is a light blue */
}
Here is a preview image: (Having trouble uploading it directly)
http://tinypic.com/view.php?pic=1z499gw&s=8
EDIT:
I somewhat fixed this by applying "float:right" on the first whole form, the text area and the button. There is still a huge horizontal between the two.
#main {
float:right;
}
#main {
text-align: center;
}
#mainheader{
margin-bottom: 20px;
text-align: center;
font-family: 'Raleway', sans-serif;
}
#mainbutton {
display: block;
margin: 35px auto;
}
.button-xlarge {
font-size: 125%;
width:350px;
background: rgb(66, 184, 221); /* this is a light blue */
}
input[type="submit"], #deviceID {
display: inline;
vertical-align: middle;
margin-top: 35px;
}
.left{
float: left;
text-align: left;
}
<div id="main">
<h1 id="mainheader">Send an image to a Wearable device</h1>
<hr>
<form method="post" action="/gcm/gcm.php/?push=true" onsubmit="return checkTextAreaLen()">
<textarea id="deviceID" rows="1" name="message" cols="25" placeholder="Device ID"></textarea>
<input type="submit" value="Upload Image" name="submit">
<button type="submit" id="mainbutton" class="button-xlarge pure-button">Send Image</button>
</form>
<form class="left" action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<div id="filebutton">
<input type="file" name="fileToUpload" id="fileToUpload">
</div>
</form>
</div>
i think this is what you are asking for.
i rearranged your html a little and added a couple of css rules.
by setting the display on the device id field and the upload button to inline instead of block i got them to be on the same line.
i used vertical-align to... well... align them. and gave them a margin-top.
then floated your second form to the left.