How to left align textareas within different divs? - html

I want to left align the textareas within two different divs.
Below is what have tried, but it doesn't work.
.credentials {
margin-top: -5px;
background-color: black;
}
label {
margin-left: 20px;
color: white;
vertical-align: middle;
}
textarea {
vertical-align: middle;
height: 25px;
margin-top: 10px;
margin-left: 30px;
}
.username {
height: 50px;
}
<div class="credentials">
<div class="username">
<label>Username:</label>
<textarea></textarea>
</div>
<div class="key">
<label>Activation key:</label>
<textarea></textarea>
</div>
</div>
It outputs the following result:

Try this CSS table layout (no markup changes). Set the container div as table, and two inner divs as table-row, and label + textarea as table-cell, with some other CSS adjustments, see the comments in the code snippet.
.credentials {
display: table;
width: 100%;
background: black;
border-collapse: separate;
border-spacing: 10px; /*for spacing*/
}
.username, .key {
display: table-row;
}
label, textarea {
display: table-cell;
vertical-align: middle; /*or top/bottom*/
}
label {
width: 1%; /*small value*/
white-space: nowrap; /*prevent wrapping*/
color: white;
}
<div class="credentials">
<div class="username">
<label>Username:</label>
<textarea></textarea>
</div>
<div class="key">
<label>Activation key:</label>
<textarea></textarea>
</div>
</div>
Edit: as one of the comment below pointed out using <input> elements rather than <textarea>, and I think that makes sense. See the updated code snippet.
.credentials {
display: table;
width: 100%;
background: black;
border-collapse: separate;
border-spacing: 10px; /*for spacing*/
}
.credentials .username,
.credentials .key {
display: table-row;
}
.credentials label,
.credentials input[type="text"],
.credentials input[type="password"]{
display: table-cell;
vertical-align: middle;
padding: 4px;
}
.credentials label {
width: 1%; /*small value*/
white-space: nowrap; /*prevent wrapping*/
color: white;
}
<div class="credentials">
<div class="username">
<label>Username:</label>
<input type="text">
</div>
<div class="key">
<label>Activation key:</label>
<input type="password">
</div>
</div>

There is more than one way to achieve this, answer of Pangloss is nice but i like to suggest something different also without touching the code.
I would never use textarea for this kind of work
calc is a relative new thing check your search engine for more information
If you don't know the < selector in css i suggest to look over here
.credentials {
background-color: rgb(0, 0, 0);
color: rgb(255, 255, 255);
/*fallback color if nothing is found*/
}
.credentials > div > label {
display: inline-block;
min-width: 150px;
/*maximum width of label*/
text-align: right;
/*style*/
padding: 5px;
/*style*/
}
/*extra to make sure it never flip under label and stay inside view*/
.credentials > div > textarea {
max-width: calc(100% - (150px + 5px + 5px + 8px + 8px + 1px + 1px));
/* min-width + padding-left + padding-right + margin-left + margin-right + border-left + border right OR just 178px */
}
<div class="credentials">
<div class="username">
<label>Username:</label>
<textarea></textarea>
</div>
<div class="key">
<label>Activation key:</label>
<textarea></textarea>
</div>
</div>

Related

How to break span elements using css?

I am having a container div with selected items and select input inside it.
#container {
position: relative;
text-align: left;
width: 100%;
}
._2iA8p44d0WZ {
border: 1px solid #cccccc;
border-radius: 4px;
padding: 5px;
min-height: 22px;
position: relative;
}
._7ahQImy {
padding: 4px 10px;
background: #0096fb;
margin-right: 5px;
margin-bottom: 5px;
border-radius: 10px;
display: inline-flex;
align-items: center;
font-size: 13px;
color: #fff;
white-space: nowrap;
}
<div id="container">
<div class="_2iA8p44d0WZ">
<span class="chip _7ahQImy">This is the main label</span>
<span class="chip _7ahQImy false false">secondary label</span>
<input type="text" class="searchBox" id="search_input" placeholder="Select" autocomplete="off" value="">
</div>
</div>
Requirement:
-> I am in the need to move the selected items below the #container div to display individual chips (span tags) below one after the other.
Note:
-> There are some dynamic classes inside it for which I cannot modify the css classes for those dynamic classes.
List of dynamic classes for which css properties cannot be modified, _2iA8p44d0WZ and _7ahQImy .
List of ids/classes, I can modify the css properties are #container and .chip (span).
Things I have tried:
Added css property for span element with class chip as follows,
.chip {
position: absolute;
top: 200%;
}
.chip:after {
content: '\A';
white-space: pre;
}
But this results in the overlapping of items one on another.
If I add display: block; to .chip then that also results the same..
#container {
position: relative;
text-align: left;
width: 100%;
}
._2iA8p44d0WZ {
border: 1px solid #cccccc;
border-radius: 4px;
padding: 5px;
min-height: 22px;
position: relative;
}
._7ahQImy {
padding: 4px 10px;
background: #0096fb;
margin-right: 5px;
margin-bottom: 5px;
border-radius: 10px;
display: inline-flex;
align-items: center;
font-size: 13px;
color: #fff;
white-space: nowrap;
}
.chip {
position: absolute;
top: 200%;
}
.chip:after {
content: '\A';
white-space: pre;
}
<div id="container">
<div class="_2iA8p44d0WZ">
<span class="chip _7ahQImy">This is the main label</span>
<span class="chip _7ahQImy false false">secondary label</span>
<input type="text" class="searchBox" id="search_input" placeholder="Select" autocomplete="off" value="">
</div>
</div>
Expected Result:
---------------------------
| Input |
---------------------------
| This is the main label |
| secondary label |
Kindly please help me to modify the css of span tags (.chip) without modifying the dynamic classes (I don't have control for it in real application) to have line breaks, so that it will be visible one after the other below the container.
The problem is that you are positioning the chips absolute, of course they will end up on top of each other, if you position them all with the same top value.
Doing this the other way around would IMHO make much more sense here - position the input field absolute at the top of the container, and leave those chips in normal flow instead. Add a padding-top for the inner container element, so that they don’t go beneath the input field, but under it.
#container {
position: relative;
text-align: left;
width:100%;
}
#container > div {
padding-top: 2em;
}
._2iA8p44d0WZ {
border: 1px solid #cccccc;
border-radius: 4px;
padding: 5px;
min-height: 22px;
position: relative;
}
._7ahQImy {
padding: 4px 10px;
background: #0096fb;
margin-right: 5px;
margin-bottom: 5px;
border-radius: 10px;
display: inline-flex;
align-items: center;
font-size: 13px;
color: #fff;
white-space: nowrap;
}
#search_input {
position: absolute;
top: 0;
left: 0;
}
<div id="container">
<div class="_2iA8p44d0WZ">
<span class="chip _7ahQImy">This is the main label</span>
<span class="chip _7ahQImy false false">secondary label</span>
<span class="chip _7ahQImy">Another label</span>
<span class="chip _7ahQImy false false">even more labels labels labels labels labels labels</span>
<input type="text" class="searchBox" id="search_input" placeholder="Select" autocomplete="off" value="">
</div>
</div>
You can use in html br tag, in Css you can try
.container{
width: 100px;/*insert the px you need, make som tests*/
}
.your-stuff{
display:flex;
flex-warp: warp;
}
<body>
<div class="container">
<div class="my-stuff">stuff</div>
</div>
</body>

Active tab border bottom under the div instead in the div

I have made a tab wrapper with 2 tabs. Under the tabs I have a div with content.
This is my code:
.tab-wrapper {
width: auto;
padding-left: 17px;
background-color: aqua;
white-space: nowrap;
display: table-cell;
}
.content {
background-color: aqua;
}
.role-tab {
cursor: pointer;
display: inline-block;
height: 50px;
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
vertical-align: middle;
margin-right: 19px;
}
.role-tab>p {
display: table-cell;
height: 50px;
overflow: visible;
vertical-align: middle;
width: 100%;
}
.role-tab-active {
border-bottom: 3px #108DE7 solid;
font-weight: bold;
}
<div class="tab-wrapper">
<div class="role-tab role-tab-active">
<p>Role tab 1</p>
</div>
<div class="role-tab">
<p>Role tab 2</p>
</div>
</div>
<div class="content">
<p>Content</p>
</div>
The styling and everything are working good. Now I want to add some padding-top so the border-bottom will go under the div. This is a screenshot what I want:
I want that the border-bottom goes under the div instead of in the div.
I have tried margin-top, padding-top and top, but it didn't work
How can I achieve when the tab is active that the border-bottom goes under the div instead inside it?
just set the margin-bttom: -3px; for the active class and its done :
.role-tab-active {
margin-bottom:-3px;
border-bottom: 3px #108DE7 solid;
font-weight: bold;
}
see below snippet :
.tab-wrapper {
width: auto;
padding-left: 17px;
background-color: aqua;
white-space: nowrap;
display: table-cell;
}
.content{
background-color: aqua;
}
.role-tab {
cursor: pointer;
display: inline-block;
height: 50px;
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
vertical-align: middle;
margin-right: 19px;
margin-bottom:-3px;
}
.role-tab > p {
display: table-cell;
height: 50px;
overflow: visible;
vertical-align: middle;
width: 100%;
}
.role-tab-active {
margin-bottom:-3px;
border-bottom: 3px #108DE7 solid;
font-weight: bold;
}
<div class="tab-wrapper">
<div class="role-tab role-tab-active">
<p>Role tab 1</p>
</div>
<div class="role-tab">
<p>Role tab 2</p>
</div>
</div>
<div class="content">
<p>Content</p>
</div>
You can't move borders via padding and margin. It's not an element but part of the element.
Give the .tab-wrapper a static height instead of default auto. Whatever the size of your border, the containing div will adjust to it instead, so we give it a static height to allow overflow. And then make it display:flex.
.tab-wrapper {
width: auto;
padding-left: 17px;
background-color: aqua;
white-space: nowrap;
display: flex;
height: 50px;
}
You can see that both the parent and tab items are of 50px height, but that's not really the case when rendered. box-sizing: content-box being the default css property, your official active role tab height is 53px, thus, overflowing the div by 3px and giving the border an "under the div" effect
Fiddle: https://jsfiddle.net/c5u3wzv2/5/

Using a label element to display an input with inner label - Input width exceeds label in Firefox

I'm trying to put a span inside of a text input to prefix it with the "$" character, to represent a dollar amount.
To do this, I'm using a label element containing the "$" span along with the actual input, which is set to 100% width. The label element is styled to look like a text box.
This works fine in Chrome and IE, however in Firefox it seems that setting 100% width on the input does not take the span into consideration, and therefore extends past the actual label element's boundaries:
Code Example:
.container { width: 400px; }
.w70 { width: 70px; }
.input-with-label {
border: 1px solid #D9D9D9;
display: flex;
align-items: center;
background-color: #fff;
}
.input-with-label.-dollar-amount > input[type='text'] {
text-align: right;
font-weight: 600;
}
.input-with-label > input[type='text'] {
margin: 0;
border: none;
width: 100%;
}
.input-with-label > .input-label {
padding-left: 3px;
font-size: 10px;
border: none;
}
<div class="container">
<label class="input-with-label -dollar-amount w70">
<span class="input-label">$</span>
<input type="text" value="0.00" />
</label>
</div>
Doesn't setting min-width:0 to the input and making it use all available width via flex:1 solve the problem?
.container { width: 400px; }
.w70 { width: 70px; }
.input-with-label {
border: 1px solid #D9D9D9;
display: flex;
align-items: center;
background-color: #fff;
}
.input-with-label.-dollar-amount > input[type='text'] {
text-align: right;
font-weight: 600;
}
.input-with-label > input[type='text'] {
margin: 0;
border: none;
min-width: 0;
flex: 1;
}
.input-with-label > .input-label {
padding-left: 3px;
font-size: 10px;
border: none;
}
<div class="container">
<label class="input-with-label -dollar-amount w70">
<span class="input-label">$</span>
<input type="text" value="0.00" />
</label>
</div>
I used another method
.currencyinput span{
position: relative;
}
.currencyinput input{
padding-left:20px;
}
.currencyinput span{
left:15px;
top:0
position: absolute;
}
input{
border:1px solid lightgray;
line-height:30px;
}
<span class="currencyinput"><span>$</span><input type="text" name="amount"></span>

css default vertical-align with inline-block

Here is the code.
I have typical form with label, input and helper:
The code:
html:
<div class="container">
<span class="label">Label:</span>
<div class="el">
<input>
<span>helper helper helper</span>
</div>
</div>
css:
.container {
outline: 1px solid black;
width: 200px;
height: 100px;
}
.label{
display: inline-block;
width: 30%;
}
.el{
display: inline-block;
width: 60%;
}
input{
width: 50%;
}
The problem is that Label: aligned opposite second row. I know how to fix that: i can use float: left; or vertical-align: top; in the .label class, but i want to know, why is that happening? Why Label: jump to second row?
p.s. Sorry for my english.
This is because the default value for vertical-align is baseline, which...
Aligns the baseline of the element with the baseline of its parent
For reference, here is the article on Mozilla Developer Network
Please try this one;
.inner {
display: inline-block;
vertical-align: middle;
background: yellow;
padding: 3px 5px;
}
DEMO
I think due to the display:inline-block defined is creating this situation..
Better use display:inline
This will solve your problem...
And here is the code
CSS
.container {
outline: 1px solid black;
width: 250px;
height: 100px;
}
.label{
display: inline;
width: 50%;
}
.el{
display: inline;
width: 60%;
}
input{
width: 50%;
}
HTML
<div class="container">
<span class="label">Label:</span>
<div class="el">
<input />
<span>helper helper helper</span>
</div>
</div>

Set fix width of each Column DIV Control

I have written tabular structure using DIV controls. It shows data correct only when column values have same length of characters. If column values have different number of characters then column gets enlarge itself to accommodate all characters in a column. How to set FIX width of each column DIV?
I have following HTML DIV structure:
<body>
<div class="ParentContainer">
<div id="row1" class="row">
<div>
<label id="row1_to" class="divLabel">contact1#test.com
</label>
</div>
<div>
<label id="row1_from" class="fromLabel">test1#something.com
</label>
</div>
<div>
<label id="row1_subject" class="subLabel">Need to create new organization1
</label>
</div>
</div>
<div id="row2" class="row">
<div>
<label id="row2_to" class="divLabel">contact2#test.com
</label>
</div>
<div>
<label id="row2_from" class="fromLabel">test2#something.com
</label>
</div>
<div>
<label id="row2_subject" class="subLabel">Need to create new organization2
</label>
</div>
</div>
</div>
</body>
Following is the CSS:
.ParentContainer
{
margin: 0 auto;
width: 960px;
table-layout:fixed;
}
.row
{
background-color: #FFFFFF;
border-bottom-style: solid !important;
border-bottom-width: 1px !important;
border-color: #CFD4DA;
font-size: 12px;
}
.row > div
{
display: inline-block;
}
.row:hover
{
background-color: #CEE3F6 !important;
}
.rowSelected
{
background-color: #CEE3F6;
}
.fromLabel
{
position: relative;
left: 64px;
}
.subLabel
{
position: relative;
left: 120px;
}
Please suggest.
You forgot to style those div as table:
Relevant CSS:
.ParentContainer {
display: table;
...
}
.row {
display: table-row;
...
}
.row > div {
display: table-cell;
...
}
Demo: http://jsfiddle.net/abhitalks/824hw/1/
Make your div display as a table cell and assign width for the table cell. Remove position relative property for your labels.
Update your css like below.
.ParentContainer
{
margin: 0 auto;
width: 960px;
table-layout:fixed;
}
.row
{
background-color: #FFFFFF;
border-bottom-style: solid !important;
border-bottom-width: 1px !important;
border-color: #CFD4DA;
font-size: 12px;
display:table-row;
}
.row > div
{
display: table-cell;
width:33%;
}
.row:hover
{
background-color: #CEE3F6 !important;
}
.rowSelected
{
background-color: #CEE3F6;
}
.fromLabel, .subLabel, .divLabel
{
text-align:left;
}
JSFIDDLE DEMO