Not a huge deal but posed an interesting question for me so curious how I can do it
I have a basic form here:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/7HAnU.png
As you can see my error messages's left side does not line up with the edge of the input labels.
How can I get a child element to align with it's parent's sibling using flexbox?
Here's a simplified version of the issue:
<div class="flex-container">
<div class="inputs">
<label> input1 </label>
<input />
<div>
<ul> <li> errors </i> </ul>
<div class="inputs">
<label> input1 </label>
<input />
<div>
<div>
where:
.flex-container {
display: flex;
flex-direction: column;
margin: auto;
}
.inputs {
margin: auto;
}
Now as you can see the ul actually does align BUT the internal items li do not align. I'm trying to do this without pixel pushing (manually moving using margin or padding).
But I also have no choice in how the errors come out meaning I have to use <ul> and <li> elements.
I am using Django templates and this is my code:
<style>
.errorlist {
list-style-type: none;
display: flex;
padding: 0;
justify-content: space-around;
}
</style>
<div style="padding:25px;text-align: center;">
<p>{% translate "Please enter your new password twice so we can verify you typed it in correctly." %}</p>
<form method="post">{% csrf_token %}
<fieldset class="module aligned" style="margin-bottom:15px;margin-left:auto;margin-right:auto">
<input style="display: none;" class="hidden" autocomplete="username" value="{{ form.user.get_username }}">
<div style="margin:auto;display:flex;flex-direction: column;">
<div class="form-row field-password1" style="display:block;">
<div style="text-align:left;color:red;list-style-type: none;">{{ form.new_password1.errors }}</div>
<div>
<label for="id_new_password1">{% translate 'New password:' %}</label>
{{ form.new_password1 }}
</div>
</div>
<div class="form-row field-password2" style="display:block;">
<div style="text-align:left;color:red;list-style-type: none;">{{ form.new_password2.errors }}</div>
<div>
<label for="id_new_password2">{% translate 'New password:' %}</label>
{{ form.new_password2 }}
</div>
</div>
<input style="display: block; width: 200px;margin-top:25px;margin:auto;color:white;" type="submit" value="{% translate 'Change my password' %}">
</div>
</fieldset>
</form>
Flexbox can only align flex items, which are defined as the direct children of a flexbox container:
The direct children of a Flex Container (elements with display: flex or display: inline-flex set on them) become flex items.
The spacing issue in this case is a product of ul styling, not flexbox. Since you have no control over the list, you can remove any offsets it introduces:
ul.errors {
padding: 0;
list-style-type: none;
}
where your error list would look something like this:
<ul class="errors>
<li> error1 </li>
<li> error2 </li>
</ul>
Related
I created a angular dropdown component "app-ec-dropdown" using https://www.npmjs.com/package/#ng-select/ng-select
<div class="inline required">
*
</div>
<div class="input-container inline">
<ng-select
class="custom"
[items]="items"
bindLabel="Name"
bindValue="Id"
(focus)="focus()"
(close)="close()"
(clear)="clear()"
(blur)="blur()"
placeholder="Select"
[(ngModel)]="selectedId"
[required]="required"
>
</ng-select>
<div *ngIf="!validatationPassed()">
<div class="row alert alert-danger alert-div">
<span>
Required field
</span>
</div>
</div>
</div>
CSS for above component
.input-container {
width: 95%;
}
.inline {
display: inline;
}
.required {
vertical-align: top;
color: red;
width: 2%;
}
Now i am using above component in parent component
<div class="col-sm-4">
<app-ec-dropdown
name="RegionId"
[items]="regions"
(onChange)="onRegionChange($event)"
[selectedId]="state.RegionId"
[required]="regionDropDownValidator.required"
[ecDropDownValidator]="regionDropDownValidator"
[(ngModel)]="regionDropDownValidator.selectedId"
ngDefaultControl
> </app-ec-dropdown>
</div>
for Region Dropdown, I want red asterisk, to be placed as in "State Name" textbox and then dropdown and validation message in the adjacent div.
Screen grab:
After playing around with your code, I thought about the way that I would do it.
I noticed that the actual label isn't included in your example above, so I assume that it's being included within a column to the left of the <div class="col-sm-4"> element where you're consuming the <app-ec-dropdown> component which I assume that you have defined with the first code block.
My advice which will be the easiest and most correct (in my opinion), would be to add the label as an #Input property in your code for the <app-ec-dropdown> component.
Then you can place it closer to the asterisk character.
So add this to your EcDropdownComponent TypeScript:
#Input()
public label: string = '';
Then add the input attribute where you consume your component:
<app-ec-dropdown
name="RegionId"
[items]="regions"
label="State Name"
(onChange)="onRegionChange($event)"
[selectedId]="state.RegionId"
[required]="regionDropDownValidator.required"
[ecDropDownValidator]="regionDropDownValidator"
[(ngModel)]="regionDropDownValidator.selectedId"
ngDefaultControl>
</app-ec-dropdown>
Then you can use the CSS grid to define the layout within your component:
<div class="row">
<!-- Label -->
<div class="col-sm-4">
<div class="label">
{{label}}
<span class="inline required"> * </span>
</div>
</div>
<!-- Select Input -->
<div class="col-md-8">
<div class="input-container inline">
<ng-select
class="custom"
[items]="items"
bindLabel="Name"
bindValue="Id"
(focus)="focus.emit()"
(close)="close.emit()"
(clear)="clear.emit()"
(blur)="blur.emit()"
placeholder="Select"
[(ngModel)]="selectedId"
[required]="required">
</ng-select>
<div *ngIf="!validatationPassed()">
<div class="row alert alert-danger alert-div">
<span>
Required field
</span>
</div>
</div>
</div>
</div>
</div>
The nice thing about this approach is that you have a completely self-contained component which doesn't need to worry about anything outside of it's scope.
If you're concerned about variable widths using Bootstrap and the grid system.
You can also pass the grid column style in as an #Input property to the component so that you're providing more control to the consuming component.
I have a multiple selection and would like to be able to click on it to manage the answers on a /getmatch page. At the moment I have no visual cue that I have selected things:
[]]1
So how to make the selection of multiple items responsive?
Here is the code from the page that gives these buttons:
{% extends "todo/base.html" %}
{% block content %}
<style>
.elements {
display: block;
}
ul.items {
display: flex;
margin: 0;
padding: 0;
list-style: none;
}
li.item {
flex: 1 0 20%;
padding: 8px;
margin: 2px;
border-radius: 8px;
border: 1px solid rgba(61, 86, 233, 0.3);
text-align: center;
}
.col {
display: flex;
flex-direction: column;
align-items: center;
}
</style>
<!-- Header -->
<header class="intro-header">
<div class="container">
<div class="col-lg-5 mr-auto order-lg-2">
<h3><br>Tell me something about you... </h3>
</div>
</div>
</header>
<!-- Page Content -->
<section class="content-section-a">
<div class="container">
<dt>
<span>Pick the keywords you want to express when wearing perfume</span>
</dt>
<form action = "/getmatch" method="POST">
{% for keyword in keywords %}
<div class="elements">
<ul class="items ">
<li class="item col-xs-6 col-sm-3 col-md-3 col-lg-3">
<div class="box">
<div data-toogle="buttons" class="col">
<span>{{ keyword.title }}</span>
</div>
</div>
</li>
</ul>
</div>
{% endfor %}
{% csrf_token %}
<button type="submit">Envoyer</button>
</form>
</div>
</section>
<!-- Bootstrap core JavaScript -->
<script src="static/vendor/jquery/jquery.min.js"></script>
<script src="static/vendor/popper/popper.min.js"></script>
<script src="static/vendor/bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.min.css" type="text/css" >
{% endblock %}
I tried to add things in the balisa .
button:hover{background-color:orange;}
button:focus{background-color:red;}
But it didn't modified anything
I can't add a comment since i don't have the required rep points (new to stack overflow, sorry if this isn't allowed), but I am not sure what you're trying to do, if you want to give a visual cue that a button has been selected for more than one button at a time, you need to grab the list of buttons, add an event listener on click that toggles a class on/off, then add styling to that class, so that when the item has that class it has a specific style.
Edit on how to do that:
P.S i've never used Django, but i think you should do this, since the way you're doing it is generating a ul for each keyword
<form action = "/getmatch" method="POST">
<div class="elements">
<ul class="items ">
{% for keyword in keywords %}
<li class="item col-xs-6 col-sm-3 col-md-3 col-lg-3">
<div class="box">
<div data-toogle="buttons" class="col">
<span>{{ keyword.title }}</span>
</div>
</div>
</li>
{% endfor %}
</ul>
</div>
{% csrf_token %}
<button type="submit">Envoyer</button>
</form>
Now you need to select the list elements, an easier way to do this would be something called event delegation https://javascript.info/event-delegation
so create a script tag/or file and import it, inside your script you neeed the following :
//Select the UL list
const myItemsList = document.querySelector(".items");
//function passed to event listener as callback, toggles the selected class if the target is a list
const toggleListClass = (event) => {
let target = event.target;
if (target.tagName !== "li") return;
target.classList.toggle("highlight");
};
//Add an event listener to the ul list
myItemsList.addEventListener("click", toggleListClass);
Now in your css add a selector for class hightlight
.hightlight {
color: whatever
}
I have the following HTML definition.
(I'm using Knockout)
<ul data-bind="foreach: itemList">
<li>
<span data-bind="text: displayName"></span>
<span class="right" data-bind="text: measurement"></span>
<input type="checkbox" />
</li>
</ul>
I would like these to display aligned as the following
Item1 measurement1 Checkbox1
Item2 measurement2 Checkbox2
Item3 measurement3 Checkbox3
I would like this to be aligned the following way:
Column 1 is floated to the far left.
Column 3 (The input checkbox) is floated to the far right.
Column 2 is is on the far right, but to the left of Column3
I've tried working with DIVs and the float/display attributes.
I haven't been able to achieve the desired visual behavior.
How would I accomplish this?
float and text-align ?
li {
display:block;
text-align:right;
width:200px;/* whatever width you set here or in parent */
}
li :first-child {
float:left;
}
input {
vertical-align:middle;/* ? */
}
<ul data-bind="foreach: itemList">
<li>
<span data-bind="text: displayName">item</span>
<span class="right" data-bind="text: measurement">measure</span>
<input type="checkbox" />
</li>
</ul>
One option might be to use Bootstrap's grid system — you would be able to specify the proportional width of each column. Additionally, it becomes easier to handle its responsiveness to screensize.
In your case, you might use it like this:
<div class="container-fluid">
<ul data-bind="foreach: itemList">
<li>
<div class="row">
<div class="col-xs-6">
<span data-bind="text: displayName"></span>
</div>
<div class="col-xs-3">
<span class="right" data-bind="text: measurement"></span>
</div>
<div class="col-xs-3">
<input type="checkbox" />
</div>
</div>
</li>
</ul>
</div>
See more grid examples here.
--
If you are trying to present tabular data, you might also consider using HTML tables and specifying its percentage column width.
Might I recommend a flex-box? I put a growing spacer in to push the middle column over to the right. Modifying GCyrillus' answer:
li {
display: flex;
justify-content: space-between;
width: 90%;
/* whatever width you set here or in parent */
}
li .spacer {
flex-grow: 1;
}
<ul data-bind="foreach: itemList">
<li>
<span data-bind="text: displayName">item</span>
<span class="spacer"></span>
<span class="right" data-bind="text: measurement">measure</span>
<input type="checkbox" />
</li>
</ul>
So after some digging I am not sure what the issue is here. I have a text field that is overlaid with a div. The div contains a ul with multiple li representing currently applied filters to a table. The overlay is supposed to catch the clicks to open a menu and hold any new filters.
EDIT:
To clarify the need is for IE9 specifically. For some reason the overlay is not what comes to the foreground. I can click on specifically the li and get the behavior I am expecting but there are space between and at the end that the overlay appears not to be present.
--My code--
HTML:
<!-- Start filter row-->
<div class="row collapse">
<div class="small-3 medium-2 large-1 columns">
<span class="prefix">Current Filters:</span>
</div>
<div class="small-9 medium-10 large-11 columns">
<div id="manager_filter_overlay" class="filter_overlay">
<ul>
<li class="filter_item">Status: Active</li>
<li class="filter_item">Start Date: 07/MAR/2014</li>
<li class="filter_item">End Date: 07/APR/2014</li>
</ul>
</div>
<input type="text" onkeydown="return false;" style="z-index:0;">
</div>
<div class="filter-menu">
<div class="arrow-up"></div>
<div class="filter-menu-container">
<ul>
<li>
<label>Status:
<select>
<option>
Active
</option>
<option>
Deleted
</option>
</select>
</label>
</li>
<li>
<label>Start Date:
<input type="text" placeholder="DD/MMM/YYY">
</label>
</li>
<li>
<label>End Date:
<input type="text" placeholder="DD/MMM/YYY">
</label>
</li>
</ul>
<div class="row">
<div class="large-12 center columns">
<input type="button" class="button tiny blue" value="Search">
<input type="button" class="button tiny blue" value="Reset">
<input type="button" class="button tiny blue" value="Save">
</div>
</div>
</div>
</div>
</div>
<!-- End filter row-->
CSS:
.filter_overlay{
position:absolute;
height:37px;
width:100%;
/*border:1px solid black;*/
}
.filter_overlay:hover{
cursor:pointer;
}
.filter_overlay ul{
margin:0;
list-style: none;
margin-left:5px;
}
.filter_overlay ul li{
display:inline-block;
/*border: 1px solid blue;*/
margin-top:10px;
padding-right:5px;
font-size:12px;
}
All browsers except IE9 seem to be doing what I would expect. When hovering over the text box anywhere my cursor is a pointer I click and my drop down show (JS not included it is very basic and not anything I think is impacting the issue). In IE9 however when hovering only a pointer is shown when over an li and when outside of that it is able to get to the text field.
Not sure what exactly you're talking about, but I moight, lol.
Anyway, if you want the default cursor everywhere, try this:
*:hover {
cursor: default;
}
or if just over the bullet points, try:
li:hover {
cursor: default;
}
Hope this works :D
After some further looking into this appears to be related to the background. Without it based on the two threads below there are z-index issues. While they suggest using
background:white; filter:alpha(opacity=1);
I was not able to see an results from this.
All I did was added the background and a 1px border.
IE z-index trouble on element with transparent background
z-index problem in IE with transparent div
How can I make the following search bar and its button at left of a page and the pagination at right, at the same line, please ?
Here is the template that I'm working on : http://jsfiddle.net/ht97t/1/
<form role="search" method="get" action="/Accueil/Rechercher">
<div class="col-xs-8">
<input type="text" name="rech" class="form-control" placeholder="Rechercher">
</div>
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button><br />
<label style="margin-left:20px;"><input type="radio" name="type" value="nomPoste" /> Nom du poste de travail</label><label style="margin-left:12px;"><input type="radio" name="type" value="nomAppMetier" checked /> Nom de l'application métier</label>
</form>
<ul class="pagination pagination-sm" style="float:right;">
<li class="disabled">«</li>
<li class="active">1 <span class="sr-only">(current)</span></li>
<li>2 </li>
<li>3 </li>
<li>4 </li>
<li>5 </li>
<li>»</li>
</ul>
I've tried this, but, this haven't work : http://jsfiddle.net/ht97t/2/
Note : I'm using bootstrap.
Thanks a lot !
From the the bootstrap CSS;
.pagination {
border-radius: 4px;
display: inline-block;
margin: 20px 0;
padding-left: 0;
}
You will need to override that margin, for now just set an inline style on your UL to confirm;
<ul class="pagination pagination-sm" style="float:right; margin: 0!important;">
Edit
You should use the Bootstrap grid as documented (http://getbootstrap.com/css/), that is to define a row and then to specify the placement of content within that row by setting div classes.
For example if you wanted to have a search box top left and a pagination control top right of a row then try this:
<div class="row">
<div class="col-xs-8"><!--search here --></div>
<div class="col-xs-4"><!--pagination here --></div>
</div>
If you want to leave some space between the left and right content then use the offset class:
<div class="row">
<div class="col-xs-6"><!--search here --></div>
<div class="col-xs-4 col-xs-offset-2"><!--pagination here --></div>
</div>
In your original example you had a Search Box left, Radio buttons middle and Pagination right, so you might just be best to go with a 4 4 4 grid:
<div class="row">
<div class="col-xs-4"><!--search here --></div>
<div class="col-xs-4"><!--radio buttons here --></div>
<div class="col-xs-4"><!--pagination here --></div>
</div>
One possible solution for this is to make the .pagination absolute and move it accordingly.
Example Fiddle
CSS:
body {position: relative;}
.pagination {
position: absolute;
right: 0px;
top: 0px;
margin: 5px 0;
}
In this case I set the body to have position:relative; but you probably would want to switch that to the closest containing element.
You have several options to do this.
The quickest fix would be just to do a margin top of like 18px
<form role="search" method="get" action="/Accueil/Rechercher">
<span style="float:left; margin:18px 0 0 10px;">