I am working on a TODO kind of web app. And I have an issue
<div class="todo-list">
<div class="item">
<p> Buy Raw materials </p>
<form action="/" method="POST">
<button type="submit">X</button>
</form>
</div>
<div class="item">
<p> Cook food </p>
<form action="/" method="POST">
<button type="submit">X</button>
</form>
</div>
<div class="item">
<p> eat food </p>
<form action="/" method="POST">
<button type="submit">X</button>
</form>
</div>
<form action="/" method="post" class="add-item">
<input type="text" name="newItem" id="newItem" placeholder="New item" autocomplete="off">
<button type="submit">Add</button>
</form>
There are 2 components first is the the div with class todo-list and second is a form.
now whenever I type something in the input feild and click add, It should be added as item in todo-list div. Which I have done using node and express
Now the issue is since this is dynamic, Initially there will be no Items in div with class todo-list and the form with input will be on the top. And as we go on adding items, They should be added into the todo list div. And it so happens that after a certain number of items added, the height of the todo list increases and crosses the viewport height.
But what i want is, until there are 5 items in the todo-list it is fine, But as soon as 6th item gets added the scroll bar should appear.
So i wrote the following CSS code for todo-list div
.todo-list{
margin-top: 1rem;
background-color: #f1f1f1;
width: 100%;
height: 425.200px;
border: 2px solid grey;
border-radius: 16px;
box-shadow: 2px 2px 4px 1px gray;
overflow: auto;
}
But the overflow property doesnt work untill a height property is given to that div.
But if a certain height(say height equal to that of 5 items is given to the todo list div) then this problem occurs:
That is the height of the last element if way more than it should be!..
Can some one please help
try providing the max height property
.todo-list {
margin-top: 1rem;
background-color: #f1f1f1;
/* change this */
width: 100%;
max-height: 425.200px;
border: 2px solid grey;
border-radius: 16px;
box-shadow: 2px 2px 4px 1px gray;
overflow: auto;
}
You need to change your height styling from a fixed number to percentage.
If you think your bottom form element is too close to your search bar, give it some margin-bottom
.todo-list {
margin-top: 1rem;
background-color: #f1f1f1;
/* change this */
width: 100%;
height: 425.200px;
border: 2px solid grey;
border-radius: 16px;
box-shadow: 2px 2px 4px 1px gray;
overflow: auto;
}
Related
I have done some styling to an element that happens to be on one of the pages of my ReactJS application.
After adding the style this how it looks (and that's how it should be actually looking):
When I arrive on the page for the first time and it looks like the above image but when I do a refresh on the same page, it looks like this:
Below is the HTML code for the above-mentioned element:
<div className={Style["search-div"]}>
<input
// className="form-control"
id={Style["search-bar-input-field"]}
type="text"
placeholder="Search for Departments "
aria-label="Search"
onChange={this.processSearchBarInput}
/>
<button className={Style["search-btn"]}>Search</button>
</div>
Below is the CSS code for the above mentioned element:
.search-div {
display: inline-flex;
justify-content: space-between;
border: 2px solid green;
border-radius: 1rem;
padding: 0.5rem;
}
#search-bar-input-field {
height: 5vh;
width: 45rem;
border-radius: 1rem;
font-size: 1.25em;
border: 0.1rem solid green;
padding: 1rem;
}
#search-bar-input-field:focus{
outline: 0;
box-shadow: 0 0 0 2pt skyblue;
}
.search-btn {
border: 0.1rem solid green;
width: 6rem;
border-radius: 1rem;
font-size: 1.15rem;
margin-left: 1rem;
}
.search-btn:focus{
outline: 0;
}
I have used this same search bar element on other pages of my application and the same thing is happening on those pages as well. I'm really not sure why this is happening.
Any help would be highly appreciated. Thanks.
So after fidgetting with the code for a bit, I made a small change to my code which fixed the issue that I was facing.
The code that I was having earlier:
<div className={Style["search-div"]}>
<input
id={Style["search-bar-input-field"]}
type="text"
placeholder="Search for Departments "
aria-label="Search"
onChange={this.processSearchBarInput}
/>
<button className={Style["search-btn"]}>Search</button>
</div>
The change that I made to the above code, was that I just wrapped the input and the button tag in div as follows:
<div className={Style["search-div"]}>
<div>
<input
id={Style["search-bar-input-field"]}
type="text"
placeholder="Search for Departments "
aria-label="Search"
onChange={this.processSearchBarInput}
/>
<button className={Style["search-btn"]}>Search</button>
</div>
</div>
And that solved the issue. Not sure though regarding the cause of the issue in the first place and how adding a div tag solved the issue. Cheers!
I created a to-do list with jQuery (see CodePen). I wanted the '+' button to be joined with the input box in which you add a to-do list item and for the two to be the same height.
Getting the button to match took a lot of trial and error with the padding. Setting its height to 1.5em to match the input box didn't work, even after setting it to box-sizing: border-box.
Is there a more efficient, accurate way to achieve this?
Here is the relevant CSS:
input[type=text] {
border: 1px solid #ccc;
height: 1.6em;
width: 28.23em;
color: #666;
height: 1.5em;
}
.button {
/* Needed to display button next to input box */
display: inline-block;
vertical-align: bottom;
box-shadow: inset 0px 1px 0 0 #fff;
/* Starts at top, transitions from left to right */
background: linear-gradient(#f9f9f9 5%, #e9e9e9 100%);
border: 1px solid #ccc;
font-size: 0.7em;
font-weight: bold;
/* First value sets top and bottom padding; second value sets right and left */
padding: 0.53em 0.7em;
text-shadow: 0 1px #fff;
text-align: center;
color: grey;
}
And HTML:
<form name="listForm">
<input type="text" name="listItem"/ placeholder="Add new">
</form><!-- Comment removes gap between inline-block elements
--><button class="button">+</button>
If you are using bootstrap, you can achieve this using input-group, please see: Bootstrap 4 input groups
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Add new" aria-label="Recipient's username" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button">+</button>
</div>
</div>
If you want to implement it yourself, you need to put the input and button inside the form. To set their height to be equal, you can set the height of the button to be equal to the height input (1.6 em) + padding of the input (1px top + 1px bottom = 2px):
input[type="text"] {
border: 1px solid #ccc;
height: 1.6em;
width: 28.23em;
color: #666;
}
button.button {
margin-left: -30px;
height: -webkit-calc(1.6em + 2px);
height: calc(1.6em + 2px);
width:25px;
color: grey;
border:none;
}
<form name="listForm">
<input type="text" name="listItem" placeholder="Add new">
<button class="button">+</button>
</form>
reduce the width of the input by 1 em. And set button to float right, It should work.
I've got a static site, which is all of a sudden displaying irregular headings. This is a single page with lots of JavaScript including tabular selections at the top of the page. The site worked just fine six months ago. Now I'm seeing unexplained mis-alignment of input elements on a half of the 12 different navigation tabs:
Decorative Ends
Round to Tapered
Bracing
Round to Square
Round to Flat
Airframe Cluster
The headings contained within a form:
<form id="dte_form">
<div class="containerLeft">...</div>
<div class="containerLeft">...</div>
<div class="containerLeft">
<label title="Data can.. [hover info]">Tube O.D. (mm): </label>
<input type="text" id="dteCutTubeOD" value="31.75" size="8">
<br>
<label>Amplitude (mm):</label>
<input type="text" id="dteAmplitude" value="25.4" size="8">
<br>
<label># of Cycles:</label>
<input type="text" id="dteNumOfCycles" value="3" size="8">
<br>
</div>
<div style="clear: both"></div>
<div class="containerLeft">
<input type="button"...>
<input type="button"...>
<input type="button"...>
<input type="button"...>
</div>
</form>
The CSS is nothing fancy:
.containerLeft {
float: left;
margin: 4px 20px;
}
.containerLeft label {
float: left;
height: 21px;
margin: 8px 5px 0 5px;
}
.containerLeft input[type=text] {
float: right;
height: 15px;
margin: 4px 5px;
padding-left: 5px;
}
The heading should look like this:
Basically, in a div, I would float the label left, float the input element right, add a <br> and repeat. I can't figure out why occasionally the elements don't line up correctly. I'm sure I'm missing something silly, but I just can't see it. Any ideas what is causing the occasional misalignment?
Click here for website. Note. I'm seeing the same results in both Chrome and Firefox.
This is what happens when you use floats. They overlap following blocks and shrink line boxes.
If you want to prevent an block element from being adjacent to a float, just use clear.
.float {
float: left;
width: 50px;
height: 3em;
border: 1px solid;
background: yellow;
}
.normal, .clear {
height: 2em;
border: 1px solid;
background: pink;
}
.clear {
clear: left;
}
<div class="float">Float</div>
<div class="normal">Normal</div>
<div class="normal">Normal</div>
<br /><br />
<div class="float">Float</div>
<div class="normal">Normal</div>
<div class="clear">Clear</div>
So apparently the issue is related to element height. Note that the label and input elements have different heights. This was done for appearance. In some combinations and element lengths the float thing gets futzed up.
The corrective action was to modify the CSS style sheet in one place:
.containerLeft label {
clear: both; /* new addition to this element */
float: left;
height: 21px;
margin: 8px 5px 0 5px;
}
An alternative would be to use <div style="clear: both"></div> in lieu of the <br> elements (or use the handy CSS library classes offered up by Oriol)
I have a set of HTML elements that I need to style, which I can't change the structure of in any way (yeah, I know).
The HTML has a div that contains two nested spans. The div has padding and the overflow is hidden. The width of the div is set programatically and applied as an inline style.
I would like the text contained within the inner span to be clipped, but still retain the right hand padding as specified on the containing div.
After some research, it appears that the standard approach to this is to use a second nested div but, as I mentioned, I can't change the structure of the HTML.
Currently I have:
<!-- This is what I have to work with (I can't change the structure of this HTML!) -->
<div class="c1" style="width: 100px;">
<span class="c1-inner">
<span class="c1-inner-2">
122333444455555666666777777788888888999999999
</span>
</span>
</div>
<!-- This is how I want the HTML above to display -->
<div class="c2" style="width: 100px;">
<div class="c2-inner">
122333444455555666666777777788888888999999999
</div>
</div>
Styled by the following CSS:
.c1 {
border: 1px solid red;
border-radius: 4px;
background-color: #c0c0c0;
padding: 0 13px 0 13px;
overflow: hidden;
}
.c1-inner {
// No relevant styles here yet
}
.c1-inner-2 {
// No relevant styles here yet
}
.c2 {
border: 1px solid red;
border-radius: 4px;
background-color: #c0c0c0;
padding: 0 13px 0 13px;
}
.c2-inner {
overflow: hidden;
}
A jsFiddle is available here
I need to style the top "button" so that it looks like the second one only using CSS. I have reached the limits of my CSS skills and any help would be very much appreciated.
A simple fix. Most important bit: you can make a span have a display value of block rather than inline, which is its default.
Here's the relevant CSS you need and a working example:
.c1 {
border: 1px solid red;
background-color: #c0c0c0;
padding: 0 13px 0 13px;
}
.c1-inner {
overflow: hidden;
display: block;
}
.c2 {
border: 1px solid red;
background-color: #c0c0c0;
padding: 0 13px 0 13px;
}
.c2-inner {
overflow: hidden;
}
We want this<br>
<!-- This is what i Have to work with -->
<div class="c1" style="width: 100px;">
<span class="c1-inner">
<span class="c1-inner-2">
122333444455555666666777777788888888999999999
</span>
</span>
</div>
<!-- This displays how i want the html above to display -->
<br>
to look like this<br>
<div class="c2" style="width: 100px;">
<div class="c2-inner">
122333444455555666666777777788888888999999999
</div>
</div>
<br>
but cannot change the structure of the html!
I have a search box like below and i am using bootstrap to give a flexible layout. How can use a design like below and make sure i can get a stretchable search box.
You'd need a container to put your input box in, and put a front and end div to it. Depending on browser compatibility you might want to add a few more div's to make sure your input box is shown properly in browsers like IEX7/8 though.
So you'd have the following:
<form class="searchbox">
<input type="text" class="text" />
<input type="submit" class="submit" />
</form>
Accompanied by the following example CSS
form.searchbox { background:url(leftside_image.gif) 0 0 no-repeat; padding-left:15px; }
form.searchbox input.text { border:none; border-top:1px solid #999; border-bottom:1px solid #999; height:25px; line-height:25px; padding:0 5px; }
form.searchbox input.submit { background:url(rightside_image.gif); }
Add your Html part like this
<div class="searchbox">
<input class="lightsearch" type="text" name="s" onfocus="doClear(this)" value="">
</div>
css part, download a search box image and replace it with the name
.searchbox input.lightsearch {
background: url("images/lightsearch.png") no-repeat scroll 0 0 transparent;
border: 0 none;
color: #575757;
font-size: 11px;
height: 19px;
margin-top: 24px;
padding: 2px 5px 2px 24px;
width: 170px;
}