How to style WTForm fields using custom css classes? - html

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.

Related

Style does not affect input in Ionic 3

I am trying create a login page for my app. But style does not work as I wish, here is the photo from problem
1
Here is the login.html codes
<ion-content class="app-content padding main-bg text-center">
<div class="logo animated pulse infinite">
<img src="../../assets/imgs/logo1.png" />
</div>
<form class="app-form">
<div class="list list-inset">
<label class="item item-input sec-main-text">
<input type="text" class="text-center" placeholder="username">
</label>
<label class="item item-input sec-main-text">
<input type="password" class="text-center" placeholder="Password">
</label>
</div>
<button class="button button-block button-clear main-btn main-bg-color" ng-click="goto('/app/home')">Login</button>
Register
<p class="forget" ng-click="forget_password()">Forget Password?</p>
</form>
</ion-content>
Here is the login.scss codes
.app-form .list-inset {
margin-left: 0;
margin-right: 0;
background: none;
}
.app-form {
.item-input {
margin-bottom: 20px;
background: none;
border: 1px solid;
border-radius: 30px;
padding: 5px 10px;
}
.list-inset .item {
border-radius: 30px;
height: 46px;
&.item-input input {
padding: 0;
color: white;
}
}
input {
&::-webkit-input-placeholder, &:-moz-placeholder {
color: white;
text-transform: capitalize;
}
}
}
.app-form .item-select {
select {
width: 100%;
max-width: 100%;
background: none;
text-align-last: center;
padding: 0;
text-align: -moz-center;
text-align: -webkit-center;
text-align-last: -moz-center;
text-align-last: -webkit-center;
direction: ltr;
}
&:after {
top: 60%;
right: 55px;
}
}
And here is the what I want from original login.html :)
2
And from original html's browser screenshot
3
And from my app's browser screenshot
4
Thanks for your helping :)
EDIT
After change html tags with ion tags
Ionic introduces and uses their own tags, for example, which has default styles added to it. It seems that you are using standard tags in your app such as and . Change your input to something like
<ion-item>
<ion-label>Username</ion-label>
<ion-input type="text"></ion-input>
</ion-item>
and things shall work smoother.
Ionic is fun to learn because it is easy. Have a visit the Official Doc to see how you can make things easier. With the proper syntax, you will not less styling rules.

Invisible Google reCaptcha

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;
}

HTML need a button that will change an output of another button

I'm doing a little HTML project, I Have a Main CSS code the HTML that I'm stuck on,
I have (as you'll see in my code) a dropdown button which gives you several options, Now what I want is for when you click one of the options-
1. It shows the option in the main dropdown button (The text on it [Changing from "$4-$30 Aud" to whatever they pick])
and I want somehow for the "Add to cart" button to change to code that would redirect to what has been picked above it (the options mention above)
Anyway thanks for you help
CSS:
.button {
background-color: #ffffff;
border: none;
color: black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 1px 2px;
cursor: pointer;
}
ul {display: inline;
list-style-type:none;
text-decoration: none;}
.button:hover{
background-color: #595959;
}
.header {
text-align: center;
background-color: #2ac9b7;
color: black;
position: fixed;
width: 100%;
padding: 20px;
}
html, body{
width:100%;
height:100%; background-color: #62666d; margin: 0px;
}
h1 {
font-weight:bold;
color: #000000;
font-size:42px;
}
.main {
font-family: arial;
margin: 0px;
}
.Content {
top:0;
bottom:0
left:0;
right:0;
margin-top: 160px
}
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
img
{
display: block;
margin: 0 auto;
}
HTML
<html>
<head>
<link rel="stylesheet" href="Masters_baby.css">
<div class="Main">
<div class="header">
<div class="links">
<ul><button class="button">Home</button> </ul>
<ul><button class="button">Shop</button></ul>
<ul><button class="button">Art</button></ul>
<ul><button class="button">About Me</button></ul>
<ul><button class="button">Support</button> </ul>
<ul><button class="button">Production</button></ul>
</div>
</div>
</div>
</div>
<IMG STYLE="position:absolute; TOP:23px; LEFT:20px; WIDTH:130px; HEIGHT:50px" SRC="Logo.png">
</head>
<body>
<IMG STYLE="TOP:180px; LEFT:30px; WIDTH:50px; HEIGHT:50px" SRC="Flame.png">
</body>
</div>
</div>
<div class="parallax"></div>
<div style="height:4950px; width:80%; margin:0 auto; background-color:#98eacc; margin-top: 44px">
<div class="Products" style="padding-top: 50px;">
<div class="∞ Frosted Kumquat" style= "width: 100%; height:9.1%; width:80%; margin:0 auto; background-color:#fff; ">
<p style="font-size: 25px">∞ Frosted Kumquat</p>
<IMG STYLE="WIDTH:35%; HEIGHT:63%" SRC="candle.jpg" >
<table style="width: 100%;">
<tbody>
<tr>
<td style="width: 80%;">A fresh citrusy smell that fills the room, Its is fairly stong washing out any unwanted smells or just lifting the room. Best for someone who doesnt like the smell of overly sweet but likes the fresh smell of fruit.</td>
<td>
<div class="dropdown"><button class="dropbtn">$4-$30 AUD</button>
<div class="dropdown-content">Melts $4.00 Tea light(6) $5.00 Candle in a Tin $14.00 Specitally Candles $15.00-$30.00 Boxed candle $22.00 Triplet pack of candles $28.00</div>
</div>
</td>
</tr>
<tr>
<td></td>
<td>
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="kin#kinskards.com">
<!-- Specify a PayPal Shopping Cart Add to Cart button. -->
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="Birthday - Cake and Candle">
<input type="hidden" name="amount" value="3.95">
<input type="hidden" name="currency_code" value="USD">
<!-- Display the payment button. -->
<input type="image" name="submit"
src="Add2Cart.png"
alt="Add to Cart" STYLE="WIDTH:70%; HEIGHT:20%">
<img alt="" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif">
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</html>
Again Thanks for any help :)
First of all, place all of your content in the <body>. Your head is where you link to stylesheets, load scripts and set meta-data etc. you don't want to have any content such as your header in the head.
You can achieve things like this with JavaScript. Let me give you an example.
Lets say we have the following HTML:
<select class="selector">
<option value="10">10$</option>
<option value="20" selected>20$</option>
<option value="30">30$</option>
</select>
Selected plan: <span class="selected_plan">20$</span>
We want to change the content of the span with class selected_plan to the value selected in our select element.
First we need to create a new script (load your scripts at the bottom of your body).
<script> // place your script here </script>
or
<script src="link_to_your_js_file.js"></script>
Next we need to select our elements like so:
let selector = document.querySelector('.selector');
let selectedPlan = document.querySelector('.selected_plan');
Then we listen for when the select changes:
selector.addEventListener('change', function() {
selectedPlan.innerHTML = selector.value + '$';
});
I created this JSFiddle for you so you can experiment with this particular example: https://jsfiddle.net/dgyyyoh8/1/
EDIT:
If I'm correct you want to change attributes as well. You can use the setAttribute method for this.
let link = document.querySelector('.element');
link.setAttribute('href', selected.value);
Take a look at this JSFiddle: https://jsfiddle.net/dgyyyoh8/2/
Select our element
Create an event for when the selector changes
Set the innerHTMl of the link equal to 'Go to (text of the option)'
Set the href attribute equal to the selected options' value.
EDIT:
There are ways to change the appearance of the select element.
For example: https://codepen.io/ericrasch/pen/zjDBx
I'd suggest you also take a look at the CSS Framework Bootstrap. This framework contains a lot of classes you can work with to really take your styling to the next level.

Inlining two buttons - one inside a <form>, one outside

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 :)

Search field isn't on same line as text

I'm trying to insert a search field in my header (black zone) but doesn't work. I want the search field inline with "SimpleCMS"...
See this screenshot to understand:
I want it on the same line as the header text...
There's my HTML code:
<div id="header"><h1><?php echo($header_text); ?></h1>
<div style="float: right;">
<form action="search.php" method="get">
<input type="text" name="q" id="q" value="Search..." />
<input type="submit" value="Search" />
</form>
</div>
</div>
And my CSS:
#header
{
padding: 5px 10px;
background: #000;
color: #FFF;
text-align: left;
}
The problem is that you use a <h1> element. This will span over the whole width (see here) of the top so that every other element will be placed below it. Use a <span> instead and style it according to your needs. Using position-absolute as alpaca lips nao suggests might work as well.
Update: Use position: absolute;
#header
{
padding: 5px 10px;
background: #000;
color: #FFF;
text-align: left;
position: relative;
}
#header div form {
position: absolute;
top: 75px;
right: 25px;
}