label and input not on the same margin in react - javascript

How do I make my url and https:// to start on the same margin?
<div className="card">
<div className="card-body">
<div className="form-group col-12">
<label className="">URL</label>
<div className="row">
<p className=""> {baseURL} </p>
<input type="text" name="url" id="url" value={url} onChange={this.onURLChange}/>
</div>
</div>
</div>
</div>

You can use a flexbox as -
.row {
display: flex;
align-items: center;
}

If you wrap your label with a div having same className (row) as you’ve done with your input, you might see the same result.
<div className = "row">
<label className="">URL</label>
</div>

In this case I would add the following to the class form-group, I also make the assumption you want some space between the label and input so I add a bit of padding which you can adjust.
.form-group {
display: flex;
align-items: center;
padding-right: .5rem;
}
Also add for on the label, have it match the input name it is for. Doing so clicking it will focus the input.
<label for="url">URL</label>

Related

How to align textarea height with next input element

I set some input design in my sample app. inside it , I have input and textareas. from perspective view,our requirement is to set height aligned with input element.
I would like to align height of textare with input element close to it.When I simply set them as follows. it distorted.
<div>
<input value="input test">
<textarea>textarea test</textarea>
</div>
My desired result is like follows. the height of textare is aligned with input element. How can I achieve this ?
Thanks
You can start by doing this:
.wrapper {
display: flex;
}
.wrapper > input {
margin: 0;
}
<div class="wrapper">
<input value="input test">
<textarea>textarea test</textarea>
</div>
<div style="display: flex; align-items: start;">
<input value="input test">
<textarea>textarea test</textarea>
</div>
The form-group div container has the display: flex and align-items: stretch properties, which align the heights of the child elements. The textarea element has the height: 100% property
<div style="display: flex;">
<input value="input test">
<textarea>textarea test</textarea>
</div>

Button does not work if its on the same line as a h1

So I want my page title and profile button to be on the same line (header of each page). However, the button does not work when it's on the same line and works when on different lines.
return (
<div className='Master-div'>
<Sidebar />
<div className='contacts'>
<div className='header-dashboard'>
<h1>Dashboard</h1>
<ProfileButton></ProfileButton> /*this does not work*/
</div>
<div><ProfileButton></ProfileButton></div> /*this works*/
<div className='line'></div>
<div className='contents'></div>
</div>
</div>
)
}
export default Dashboard
.header-dashboard{
display: flex;
align-items: center;
justify-content: space-between;
}
I have tried making different divs and putting them on the same line using CSS but that doesn't work either. I would really appreciate some help.
Default h1 element style is display:block.
If you give it manually as inline, then they will appear next to each other.
h1 style="display: inline"

how to style two elements floated right in two rows in a row?

Im stuck with a problem.
I'm working on a website and I want to style an input with a label to float on the right side and the label to stay on top of the input on that line but the elements are staying as showing in the picture below.
the image
this is what I've done so far:
<h2>Pacients Info</h2>
<button className="addNewPacient" onClick={showModal}>Create</button>
<button className="addNewPacient">Read</button>
<button className="addNewPacient">Update</button>
<button className="addNewPacient">Delete</button>
<label for="rowsNo"><b>Rows no.</b></label>
<input
type="number"
placeholder="Rows no"
name="rowsNo"
value="10000"
onChange={e => onInputChange(e)}
/>
label[for="rowsNo"],
input[name="rowsNo"] {
float: right;
}
input[name="rowsNo"] {
width: 100px;
}
wrap the input and label inside some div container and add styles to it something like this
<div className="some-class-name">
<label for="rowsNo"><b>Rows no.</b></label>
<input
type="number"
placeholder="Rows no"
name="rowsNo"
value="10000"
onChange={e => onInputChange(e)}
/>
</div>
Update the CSS to
.some-class-name {
display: flex;
flex-direction: column;
float: right;
min-width: 100px;
}
input[name="rowsNo"] {
width: 100px;
}
Instead of using float will recommend to use flex property of CSS, it really makes like easier.
You can follow this link for an overview https://css-tricks.com/snippets/css/a-guide-to-flexbox/

How do I set the width of my label to be centered over the chart on the canvas?

I have the following html. I would like the label (Open/Resolved Issues (All Teams) to be centered above my chart (which is rendered in the canvas). I have tried it without the span, and with the span tag, nothing changes. I am using bootstrap and chart.js if that matters.
<div class="container-fluid">
<div class="row">
<div class="col-xs-1"><p></p></div>
<div class="border col-xs-4">
<label class="graph_caption" for="open_resolved_chart">
<span class="center full">Open/Resolved Issues (All Teams)</span><br />
<canvas id="open_resolved_chart" width="400" height="400"></canvas>
</label>
<br>
<span id="open_resolved_chart_legend"></span>
</div>
<div class="col-xs-1"><p></p></div>
<div class="border col-xs-4">
<label class="graph_caption" for="open_resolved_chart_agg">
<span class="center full">Open/Resolved Issues (Agg Team)</span><br />
<canvas id="open_resolved_chart_agg" width="400" height="400"></canvas>
</label>
<br>
<span id="open_resolved_chart_agg_legend"></span>
</div>
</div>
css contents:
.graph_caption {
text-size: 1.2em;
text-decoration: none;
}
.center
{
text-align: center;
}
.full
{
min-width: 100%;
}
Span elements are inline, not block elements, which means they don't take up the entire width. You could add display: block to full, or change it to a div element.
Also, bootstrap provides a text-center class that you should be using in lieu of custom css classes (.center)

CSS Grid System for Forms (Multi-Column)

For future reference here is the final result with pixel perfect precision:
The CSS code:
._25 {
width: 21%;
display: inline;
float: left;
margin-left: 2%;
margin-right: 2%;
}
._50 {
width: 46%;
display: inline;
float: left;
margin-left: 2%;
margin-right: 2%;
}
._75 {
width: 71%;
display: inline;
float: left;
margin-left: 2%;
margin-right: 2%;
}
._100 {
width: 96%;
display: inline;
float: left;
margin-left: 2%;
margin-right: 2%;
}
label {
width: 100%;
}
input {
border: 1px solid #B3B3B3;
width: 100%;
-moz-border-radius: 3px;
}
textarea {
border: 1px solid #B3B3B3;
width: 100%;
-moz-border-radius: 3px;
}
select {
border: 1px solid #B3B3B3;
width: 100%;
-moz-border-radius: 3px;
}
And some sample HTML code:
<div class="_50">
<p><label for="in_user">Username</label><input id="in_user" type="text" value=""/></p>
</div>
<div class="_50">
<p><label for="in_pass">Password</label><input id="in_pass" type="text" value=""/></p>
</div>
Recently I've started using CSS grid systems and I find the whole process of designing a webpage much more simpler. Now I'm trying to stylize form elements but I'm having a really hard time making forms with columns, take the following example:
div (width = 400px)
form
ul
li .half
label
input (should be 200px wide)
li .half
another label
another input (should also be 200px wide)
Basically I'm applying a class that has a width attribute of 50% but putting both inputs side by side makes the row to be bigger than 100% (400px) - I guess this is because of borders, margins and paddings.
Is there any CSS grid system that I can use to have multi-column forms while still making all the form elements have the same size (inputs, selects and textareas); eg. 1 input in 1 column should have 400px while 2 columns should have 200px each.
EDIT: Wufoo has some examples of what I'm trying to do but I'm too ignorant at CSS to understand all that code and I would appreciate if someone could give me some pointers.
First off, do not use a table. Putting form elements in a table does not solve your problem and complicates your maintenance. Using tables to supplement form presentation is a sign of incompetence and complexity. It is also entirely non-semantic. Instead you might actually have to write some CSS. Honestly, if you are going to use tables for non-tabular data then don't even bother using CSS as that multiplies the complexity of maintenance.
Here are some things to keep in mind:
1) Define all your units in "em" units. Most form elements are intended to contain text. Those elements, like text fields and textarea blocks, can be increased and decreased as a feature of accessibility. This means your pixel perfect pretty CSS grid will break the moment a user changes text size on the page.
2) Don't wrap your form element in a div. Like a div, your form is a block level element. Unless the form has peer nodes under a div parent simply direct any presentation directly to the form element and not a parent element that exists only to contain the form.
3) Group your form elements. If you are floating text fields things can get all messed up if the forms are floated independently of their respective label elements. It will be easier to put an ordered list inside your form and then wrap each form element in a list item. This way you only have to worry about defining layout of the label element relative to its form control and then layout of them together by defining presentation of the list item. This method is also semantic and informs text readers of an order upon your form controls.
4) Don't use the !important declaration. This makes for a quick fix in your CSS but completely screws up inheritance and absolutely complicates maintenance. Instead take the extra time to write your code correctly the first time, so that future maintenance is a quick and minor event.
5) Don't use position absolute, unless you really know what you are doing, even if your form is set to position relative. Position absolute results in unexpected behaviors in many cases and unexpected problems.
6) To ensure your CSS code actually defines a true grid use the Firefox MeasureIt plug in. It will help you achieve stunning accuracy and save you incredible time when making your grid.
7) Do everything correctly the first time using as little code as necessary to get the job complete and present your form perfectly. Only then test your form for cross browser accuracy. Make one correction for cross browser accuracy at a time to limit unnecessary bloating to your CSS code.
Something like this may help. This is how I did it on a form.
It will take some fine tuning though to make it work at your desired width. This might help you get started though.
The CSS:
.contact ul {margin:0; padding:0; list-style:none;}
.contact li {margin-bottom:10px; overflow:hidden;}
.contact label {display:block; margin-bottom:2px;}
.contact label span {color:#999;}
.contact .input {width:592px; border:1px solid #E0E0E0; background:#F6F6F6;}
.contact select.input {border:1px solid #E0E0E0; background:#F6F6F6;}
.contact .third {float:left; width:193px; margin-right:10px;}
.contact .third .input {width:185px;}
.contact .half {float:left; width:294px; margin-right:10px;}
.contact .half .input {width:286px;}
.contact .half select.input {width:294px;}
.contact .omega {margin-right:0;}
The HTML:
<form action="/contact-us" method="post" class="contact">
<ul>
<li>
<div class="half">
<label for="name">Name:</label>
<input type="text" id="name" name="name" class="input" />
</div>
</li>
<li>
<label for="address">Address:</label>
<input type="text" id="address" name="address" class="input" />
</li>
<li>
<div class="third">
<label for="city">City:</label>
<input type="text" id="city" name="city" class="input" />
</div>
<div class="third">
<label for="state">State:</label>
<input type="text" id="state" name="state" class="input" />
</div>
<div class="third omega">
<label for="zip">Zip:</label>
<input type="text" id="zip" name="zip" class="input" />
</div>
</li>
</ul>
</form>
Here's a basic kickoff example which may be of use:
<!doctype html>
<html lang="en">
<head>
<style>
fieldset { width: 400px; padding: 1%; }
input[type=text], select, textarea { width: 98%; }
.half { float: left; width: 48%; padding: 1%; }
.full { clear: both; width: 98%; padding: 1%; }
.right { text-align: right; }
</style>
</head>
<body>
<fieldset>
<legend>Contact form</legend>
<form>
<div class="half">
<label for="name">Name</label>
<input type="text" id="name" name="name">
</div>
<div class="half">
<label for="email">Email</label>
<input type="text" id="email" name="email">
</div>
<div class="half">
<label for="zip">Zip / Postal code</label>
<input type="text" id="zip" name="zip">
</div>
<div class="half">
<label for="country">Country</label>
<select id="country" name="country"><option></option></select>
</div>
<div class="full">
<label for="message">Message</label>
<textarea id="message" name="message"></textarea>
</div>
<div class="half">
<input type="checkbox" id="copy" name="copy">
<label for="copy">Send me a copy</label>
</div>
<div class="half right">
<input type="submit" value="send">
</div>
</form>
</fieldset>
</body>
</html>
Note that I am using left-floated div's of half-width instead of unordered list items.
As you insist in using percentages, don't expect it to be pixelperfect in all browsers. If you want to have it all pixelperfect, you really need to use pixels.
I think this is what you are looking for:
http://www.alistapart.com/articles/prettyaccessibleforms/
It should help simplify your structure a little bit. It doesn't explicitly describe how to make multiple column forms, but the technique could probably expand to that with some creativity on your part.
No need for the fluid 960 system here, unless you want the form to expand and contract with the browser.
I would recommend the regular old 960 grid system for this. 960 width is great for grids because it divides evenly by 12 and 16 which allows you to set up pixel perfect three and four column layouts.
The best way to get familiar with the 960 grid system is to look at the souce css and the source of the html demo
<div class="grid_6">
<p>
contact form
</p>
</div>
<div class="grid_3">
<p>
name
</p>
</div>
I had to do something similar and ended up setting my half-columns to 46%. It leaves an extra bit of room for the padding and gets all your input fields consistently sized.
One answer is Blueprint. I have read where you don't think it's the answer, but it's still the way I would do it. All the ease of tables with all the power of CSS.
With blueprint the math is pretty easy. Let's say your form spans 10 columns.
<div id="contact-form" class="span-10">
<h3>Contact Form</h3>
<form action="contact">
<div id="form-sec-1" class="span-5">
<label>Name</label> <br/>
<input type="text" name="name" /> <br/>
<label>ZIP code</label> <br/>
<input type="text" name="zipcode" />
</div>
<div id="form-sec-2" class="span-5 last">
<label>Email</label> <br/>
<input type="text" name="email" /> <br/>
<label>Country</label> <br/>
<input type="text" name="country" />
</div>
<div id="form-sec-3" class="span-10 last">
<label>Message</label> <br/>
<textarea name="message" />
</div>
<div id="form-sec-4" class="span-8">
<input type="checkbox" name="copy"/>
<label>Send me a copy</label>
</div>
<div id="form-sec-5" class="span-2">
<input type="submit"/>
</div>
</form>
</div>
Oh wow,i was just thinking what in the world is the matter with the css world then i saw this css grid layout editors draft,http://dev.w3.org/csswg/css3-grid-align/
I still cannot explain why the css world hasn't really been thinking along such lines,what explanation can there be for the lack of such a feature in css.

Categories