Three spans in a div, right most span take all width - html

I'd like to have a form with 3 <input>s and one textarea below. All of them are inside a container. The 2 first <input>s have min and max width and a % the 3rd input has min and % but no max width.
I would like that when I make the window big enough so that the 1st and 2nd reach their max width, the 3rd one grows to 100% instead of staying limited to 45% and the rest staying in spaces.
HTML:
.container{
width: 70%;
margin: 0px auto;
padding: 10px;
}
.form{
text-align: center;
}
#text{
margin-top: 5px;
width: 95%;
}
#iName{
width: 15%;
min-width: 45px;
max-width: 70px;
}
#iDate{
width: 30%;
min-width: 120px;
max-width: 150px;
}
#iTitle{
width: 45%;
min-width: 120px;
}
<div id="container" class="container">
<div id="form" class="form">
<input id="iDate" value="28/03/2017 13:19"></input>
<input id="iName" value="Jhon"></input>
<input id="iTitle" value="My title"></input><br>
<textarea id="text" rows="4" cols="50">
Some Text
</textarea><br>
<button id="update">Update</button>
</div>
...
</div>

This is a great case scenario to use flexbox.
https://jsfiddle.net/2nfo8exr/
As you can see, you can still set the min-width and max-width restrictions, but it will make sure to use all of the remaining space on that 3rd input to fill up the width.
Also please notice input tags are self-closed and you don't need </input> as that's not valid HTML.

Perhaps this solves the problem (if I understand the problem correctly).
#iTitle {
/*
where 95% is the width of textarea
where 150px + 70px is the max width of the other inputs
where -12px is the space (4px * 3) in between div elements
*/
width: calc(95% - (150px + 70px) - 12px);
min-width: 120px;
}

Here the pure code you can use it without any addition
HTML
<div id="container" class="container">
<div class="row">
<div id="form" class="form">
<input id="iDate" value="28/03/2017 13:19">
<input id="iName" value="Jhon">
<input id="iTitle" value="My title"><br>
<textarea id="text" rows="4">ASfadfasbncaksjb</textarea>
<br />
<button id="update">Update</button>
</div>
CSS
.container {
width: 70%;
margin:0 auto;
}
.form {
text-align: center;
}
#text {
margin-top: 5px;
width: 98%;
}
#iName {
width: 15%;
}
#iDate {
width: 40%;
}
#iTitle {
width: 40%;
}

Related

Div class min-width still resizing

Good day, so i have a login function encased in a div tag. I would just like to freeze the div if i resize. I tried adding min-width and display: inline-block but its still resizing. Any help would be appreciated. Also, using a pixel value still wont work.
the screenshot shows that min-width:300% !important; did not work.
I also placed my code in JS Fiddle: https://jsfiddle.net/wvhgsek9/
HTML:
<form class="reg_log_box login_box form-group">
<br>
<div class="row">
<div class="col-md-12">
<p>EMAIL</p>
<input type="text" placeholder="EMAIL" autocomplete="off" name="email"
value="<?php
if(isset($_POST["email"])) {
echo($_POST["email"]);
} ?>">
</div>
<div class="col-md-12">
<p>PASSWORD</p>
<input type="text" placeholder="PASSWORD" autocomplete="off" name="password">
</div>
</div>
<input type="submit" id="login" name="login" value="LOGIN" class="reg_signup">
<p class="center_font">NO ACCOUNT YET? REGISTER HERE</p>
<br>
</form>
CSS:
.login_box {
min-width: 30% !important;
display: inline-block
}
.reg_log_box {
width: 50%;
padding: 10px 70px 10px;
background: #fff;
opacity: 0.9;
border-radius: 30px;
margin: 0 auto;
}
Using
.login_box {
min-width: 30% !important;
display: inline-block
}
Is not going to work because that will mean to resize the box always to 30% of what ever the browser window's width is.
Instead, supply a pixel based value e.g.
.login_box {
min-width: 300px;
}
Edit:
To fully stop resizing completely then change your width to a pixel based value.
.reg_log_box {
width: 500px;
padding: 10px 70px 10px;
background: #fff;
opacity: 0.9;
border-radius: 30px;
margin: 0 auto;
}
You can then remove .login_box css all together...
try resize: block;
block
The element displays a mechanism for allowing the user to resize it in the block direction (either horizontally or vertically, depending on the writing-mode and direction value).
https://developer.mozilla.org/en-US/docs/Web/CSS/resize

Text-align: center, with wrapper, Input Boxes & Button not centering themselves but logo centers fine

On this page I have a logo (image file, with a set height to fit better) which centers itself fine in its own div. This logo is wrapped in a wrapper div with text-align: center and centers fine. There are also 2 text input boxes with a search button wrapped in a separate div from the logo's, and they're also wrapped in the wrapper div, but when I load the page that div appears on the left side of the page.
If I comment out the searchArea div so the button and boxes are surrounded only by the wrapper, everything centers fine but gets stretched out because of the width property.
How do I get everything inside the searchArea div to center under the logo without losing the set styles for the searchArea class???
HTML:
<div id="logo" class="centerWrapper">
<img id="logo" class="logo" src="img/TestAPICropped.png" alt="logo">
</div>
<div id="search" class="centerWrapper">
<div id="searchArea" class="searchArea">
<input type="text" class="inputBox" name="charName" placeholder="Character Name"><br>
<input type="text" class="inputBox" name="realmName" placeholder="Realm Name"><br>
<button type="button" class="searchButton">Search</button>
</div>
</div>
CSS:
.centerWrapper {
text-align: center;
}
.logo {
height: 46px;
}
.searchArea{
margin-top: 0.8%;
height: 125px;
width: 340px;
}
input.inputBox {
background-color: #0B122F;
border-color: #877055;
color: #4A4E5A;
margin: 5px 0px;
padding: 5px 10px 5px 10px;
width: 72%;
}
In order to horizontally center block-level elements like <div>, you're looking to the apply the margin-left and marign-right properties, both with auto values.
Normally you can use the shorthand margin: 0 auto, but considering you have a margin-top of 0.8%, you need to specify both manually for your .searchArea selector.
This can be seen in the following:
.centerWrapper {
text-align: center;
}
.logo {
height: 46px;
}
.searchArea {
margin-top: 0.8%;
height: 125px;
width: 340px;
margin-left: auto;
margin-right: auto;
}
input.inputBox {
background-color: #0B122F;
border-color: #877055;
color: #4A4E5A;
margin: 5px 0px;
padding: 5px 10px 5px 10px;
width: 72%;
}
<div id="logo" class="centerWrapper">
<img id="logo" class="logo" src="img/TestAPICropped.png" alt="logo">
</div>
<div id="search" class="centerWrapper">
<div id="searchArea" class="searchArea">
<input type="text" class="inputBox" name="charName" placeholder="Character Name"><br>
<input type="text" class="inputBox" name="realmName" placeholder="Realm Name"><br>
<button type="button" class="searchButton">Search</button>
</div>
</div>
Hope this helps! :)
To horizontally center block elements you have to use margin: 0 auto;
But there is margin-top: 0.8%;
So you can use it together:
.searchArea {
margin: 0.8% auto 0;
}
Good luck!)

How do I tell my HTML that two elements should occupy the rest of the remaining width available?

I have three input fields and a search graphic in a larger DIV
<div style="vertical-text-align:center;">
<form id="search-form" action="//search" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓">
<input type="text" name="first_name" id="first_name" placeholder="First Name" class="searchField" style="width:25%; min-width: 100px;">
<input type="text" name="last_name" id="last_name" placeholder="Last Name" class="searchField" style="width:25%; min-width: 100px;">
<input type="text" name="event" id="event" placeholder="Event" class="searchField" style="width: 40%; min-width:100px;">
<input alt="Search" type="image" src="http://www.racertracks.com/assets/magnifying-glass-0220f37269f90a370c3bb60229240f2ef2a4e15b335cd42e64563ba65e4f22e4.png" class="search_button" height="40" align="middle">
</form> </div>
I would like the third search field and the magnifying glass icon to occupy the remaining width because when I try and specify a width as I do in this Fiddle — https://jsfiddle.net/stndbt2u/2/ , the magnifying glass graphic wraps to the next line even if there is enough room to display everything. How do I always keep the magnifying glass and third search field on the same line and make them occupy the rest of the available width?
Note that if there is less than 580pixels (the max-width of the parent container), its fine, and preferable, if the third search field and magnifying glass wrap to the next line.
If you're willing to settle for a CSS-only solution and sacrifice some degree of incompatibility with older browsers, the CSS flexbox solution is your best bet. Basically, we will set up two scenarios:
A: When the viewport is larger than 620px
Calculations: 580px of the max-width of the login form, and 20px each of the left and right paddings
We allow #first_name and #last_name to have the width of 20%, allow #event to grow to fill remaining space, and for the .search_button to have a fixed dimension of 40 by 40px.
This means that the following rule will work:
#search-form {
display: flex; /* Enable flexbox */
flex: 1 0 auto; /* Breakdown:
flex-grow: 1 (allow elements to grow)
flex-shrink: 0 (prevent elements from collapsing)
flex-basis: auto (allow width to determine element dimensions)
*/
}
#first_name, #last_name { width: 20%; }
#event { } /* Do not specify width to allow it to grow freely */
.search_button { width: 40px; height: 40px; } /* Predefine image dimensions to ensure proper aspect ratio */
B: When the viewport is smaller than 620px
Same calculations as above.
Flexbox does not wrap elements by default and tries to fit them on a single line. We do not want this behaviour in the narrow viewport scenario, since you requested the form be broken into multiple lines. Therefore, using flex-wrap: wrap will force wrapping (line-breaking in a sense).
We still want #first_name and #last_name to occupy full width. We can simply use width: 50% so that they will add up to 100%. Since wrapping is enabled, make sure that their sum do not exceed 100%—if you are adding borders (without using box-sizing: border-box; on the input elements) and/or margins, you will need to use width: calc(50% - x) to ensure that these extra spaces are taken care of.
On the second row, we have #events and .search_button. We still want to keep .search_button at 40px wide, but want #events to expand to fill all the space on the second row. This can be done by declaring width: calc(100% - 40px) on #events.
Remember to wrap all these in a #media query with a max-width set to 620px:
#media (max-width: 620px) {
#search-form {
flex-wrap: wrap;
}
#first_name, #last_name { width: 50%; }
#event { width: calc(100% - 40px); }
}
For a proof-of-concept fiddle, see this link: https://jsfiddle.net/teddyrised/382fhxpc/. Note that I have removed display: table and other inline CSS styles. Let's try to avoid using inline CSS if ever possible.
I have also embedded an example as a code snippet:
body {
background-color:grey;
}
#logo {
margin: 0 auto;
padding: 10px;
}
#searchForm {
padding: 20px;
}
#search-form {
display: flex;
flex: 1 0 auto;
}
#first_name, #last_name { width: 20%; }
#event { } /* Do not specify width to allow it to grow freely */
.search_button { width: 40px; height: 40px; } /* Predefine image dimensions to ensure proper aspect ratio */
#loginLogos {
margin: 0 auto;
padding: 20px;
}
#loginArea {
border-radius: 25px;
font-size: 20px;
padding: 20px;
background-color: #ffffff;
color: #000000;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
width: 100%;
max-width: 580px;
}
#media (max-width: 620px) {
#search-form {
flex-wrap: wrap;
}
#first_name, #last_name { width: 50%; }
#event { width: calc(100% - 40px); }
}
.searchField {
line-height: 40px;
font-size: 22px;
margin: 0;
padding: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
-webkit-appearance: textfield;
background-color: white;
-webkit-rtl-ordering: logical;
-webkit-user-select: text;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
text-align: start;
}
<div id="loginArea">
<div id="searchForm">
Search For Results
<br />
<div>
<form id="search-form" action="/events/search" accept-charset="UTF-8" method="get">
<input name="utf8" type="hidden" value="✓">
<input type="text" name="first_name" id="first_name" placeholder="First Name" class="searchField">
<input type="text" name="last_name" id="last_name" placeholder="Last Name" class="searchField">
<input type="text" name="event" id="event" placeholder="Event" class="searchField">
<input alt="Search" type="image" src="http://www.racertracks.com/assets/magnifying-glass-0220f37269f90a370c3bb60229240f2ef2a4e15b335cd42e64563ba65e4f22e4.png" class="search_button">
</form>
</div>
</div>
</div>
Solution: https://jsfiddle.net/stndbt2u/5/
Simply add float: left to the inputs, and a max-width for the image of 10% (as you already have 25+25+40).
If you want the third input and the image going to the next line when the form width is not enough, add clear: left to that third input on a media query.
This is the code:
#search-form input{
float:left;
}
input.search_button {
max-width:10%;
}
#media (max-width: 580px) {
input#event {
clear:left;
}
}
You need set wrapp all inputs in one wrapper(with relative position) and set width for them in percent and make absolute position for glass.
look:
body{
background:#ccc;
}
.parent-wrapper{
float:left;
width:100%;
text-align:center;
}
#searchForm, #searchForm *{
box-sizing: border-box;
outline:none;
}
#searchForm{
border-radius:5px;
background:#FFF;
padding:20px;
box-sizing:border-box;
max-width:580px;
display:inline-block;
}
#searchForm form{
width:100%;
position:relative;
}
#searchForm .input{
padding:0 5px;
float:left;
width:25%;
}
#searchForm .search-wrapper{
width:50%;
float:left;
padding-right:50px;
}
#searchForm .search-wrapper .input{
width:100%;
}
#searchForm .searchField{
float:left;
border-radius:5px;
border:1px solid #ccc;
padding:0 10px;
height:40px;
width:100%;
}
#searchForm .search_button{
position:absolute;
right:0;
}
#media (max-width: 400px) {
#searchForm .search-wrapper,#searchForm .search-wrapper .input {
width:100%;
}
#searchForm form{
padding-right:0;
}
#searchForm .input {
width:50%;
}
#searchForm .search-wrapper{
margin-top:10px;
}
}
<div class="parent-wrapper">
<div id="searchForm">
Search For Results<br>
<form id="search-form" action="/events/search" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓">
<div class="input">
<input type="text" name="first_name" id="first_name" placeholder="First Name" class="searchField">
</div>
<div class="input">
<input type="text" name="last_name" id="last_name" placeholder="Last Name" class="searchField">
</div>
<div class="search-wrapper">
<div class="input">
<input type="text" name="event" id="event" placeholder="Event" class="searchField">
</div>
<input alt="Search" type="image" src="http://www.racertracks.com/assets/magnifying-glass-0220f37269f90a370c3bb60229240f2ef2a4e15b335cd42e64563ba65e4f22e4.png" class="search_button" height="40" align="middle">
</div>
<div style="clear:both;"></div>
</form>
</div>
</div>
and wrapp inputs like in bootstraps what using columns and add box-sizing. Better just check and learn styles what I provided.
Examining the page on Fiddle using Chrome's "Inspect" function showed that the parent container (the form tag with id="search_form") has a width of 540 pixels, not 580 pixels.
Also, extra spacing appears to be added between each input text element to add another 6 pixels between these elements.
Adding up the widths of the two name inputs (2 X 135), the event input (216), the magnifying glass icon (40) and the extra spacing between these elements (3 X 6), yields a total of 544 pixels. Since this width is greater than the parent container width, the last element (the magnifying glass icon) is pushed to the next line.
I am suspicious of the display:table-cell CSS used by the class definitions of the input elements. Instead, try using display:inline-block and see if that reduces the spacing between the input elements.
If that does not work, some other width adjustment needs to be done so that the parent container can hold all of these elements on a single line.

Two elements in one line with stretching

I am trying to keep a textarea and a button in one line while having the textarea extend horizontally as much as possible:
<div class="col-md-10 form-inline">
<textarea class="form-control"></textarea>
<button>small button</button>
</div>
The "form-inline" class on the col makes both in one line, however, it shrinks the textarea. If I remove "form-inline", then the textarea stretches 100% - but the button appears in the next line.
Is it possible to have both in one line with a wide textarea?
Try doing something like this:
.form-inline { position: relative; padding-right: 160px; }
.form-inline > textarea { width: 100%; }
.form-inline > button { width: 150px; height: 35px; position: absolute; top: 0; right: 0; }
Check Demo Fiddle here.
set width for textarea in percentage
<div class="col-md-10 form-inline">
<textarea class="form-control" style="width:90%"></textarea>
<button>small button</button>
</div>
.form-control{
display: inline-block;
width: auto;
}

css width of two items in a div to 100%

I have a page that looks like this jsfiddle, code below:
html:
<div class="parent">
<div class="child">
<input type="text">
<input type="submit">
</div>
</div>
css:
.parent { width: 500px; }
.child { width: 100%; }
How do I get it so that together they take up 100% of the parent div width (with the text input stretching accordingly)?
To clarify: I want the button(s) in a row to be fixed width and the input to take up the remaining width of the parent so that together the width = parent width. In the case that there are no button in the row, I'd like the textinput to take up the whole width.
.parent { width: 500px; margin:auto; }
.child { width: 100%; }
add this to make input stretches to full width
.child input { width: 100%; }
There are many ways to do this. One way to do this is to use the display:table-x attribute.
If you wrap the input elements in a div of their own like so:
<div class="parent">
<div class="text">
<input type="text" />
</div>
<div class="button">
<input type="submit" />
</div>
</div>
Then style the parent as display:table, the wrapper div's as display:table-cell, and give a width to div.button, like so:
.parent {
width: 500px;
background-color:blue;
display:table;
}
.text {
display:table-cell;
}
.text input {
width:100%;
-webkit-appearance:none;
}
.button {
display:table-cell;
background-color:red;
width:100px;
}
Then you can achieve the result you are looking for: http://jsfiddle.net/QpCCD/9/
This is similar to #panindra's post, but it keeps both inputs on the same line.
I've added some color to the sample to be able to see the position on the screen.
<html>
<head>
<style type="text/css">
body { background-color: black; }
.parent { width: 500px; background-color: white; text-align: center; }
.child { width: 100%; position: relative; margin: 0px 0px 0px 0px; border: 0px; }
.child input { width: 49%; margin: 0px 0px 0px 0px; border: 0px; }
</style>
</head>
<body>
<div class="parent">
<div class="child">
<input type="text">
<input type="submit">
</div>
</div>
</body>
</html>
Actually, this would be closer:
.child input { width: 248px; }