Responsive full width input with button - html

I have the fiddle here: https://jsfiddle.net/ufLpqdtj/
My problem is trying to get my search box and button to always sit full width on the page regardless of the device it is running on.
In Javascript I could always make the text box width 100% minus the pixel width of the button (the button is always the same size) but I feel as if im missing something and that it can be done natively in CSS.
Any thoughts or suggestions?
#commonSearchContainer {
display: block;
clear: both;
width: 100%;
position: relative;
}
#commonSearchTerm {
width: 100%;
margin: 25px 0px 0px 0px;
padding: 5px;
border: 1px solid #999999;
height: 35px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.common-search-term-wrapper {
width: 90%;
display: inline-block;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.common-search-button {
background-color: #E9700D;
border: 1px solid #ccc;
display: inline-block;
margin: 25px 0px 0px 10px;
width: 80px;
color: #fff;
padding: 7px;
font-style: italic;
cursor: pointer;
}
<div id="searchSection" class="common-search-section">
<div class="common-search-term-wrapper">
<input id="commonSearchTerm" type="text" autocomplete="off" class="common-search-term">
</div>
<div id="commonSearchSubmit" class="common-search-button">
Search
<div style="clear: both;"></div>
</div>
</div>

What I typically do for that sort of layout is make a parent container around the elements (like you have) and give it position: relative and width: 100%.
Then I use position: absolute and display: inline-block on the inner elements. Set the width for the fixed-sized elements and use left or right to position all of the elements.
In your case, it would be something like this: https://jsfiddle.net/ufLpqdtj/1/

Well you shouldn't use the div as a button. There are html elements for that.
If correctly understood what you want to achieve...
form {
width: 100%;
display: inline-flex;
justify-content: center;
}
#commonSearchTerm {
width: 80%;
}
#searchButton {
width: 80px;
border-radius: 0;
background-color: red;
border: none;
padding: 2px;
color: white;
}
<form >
<input id="commonSearchTerm" type="text" autocomplete="off" class="common-search-term">
<input id="searchButton" type="submit">
</form>
This is using flexbox which is is more flexible when creating responsive stuff.

Related

Creating expandable chat text input with maximum height with no JS

I'm trying to implement the following design (For now I'm just worried about the text box):
When typing:
Maximum height:
Notice the top and bottom paddings were decreased.
Now, this is what I have so far:
.chat-wrapper {
width: 100%;
}
.message-text {
resize: none;
box-sizing: border-box;
height: auto;
min-height: 41px;
max-height: 97px;
width: 387px;
border: 1px solid #e4e7ec;
border-radius: 20px;
background-color: #f9fafb;
outline: none;
padding: 0 24px 0 24px;
overflow: hidden;
}
textarea {
resize: none;
box-sizing: border-box;
height: auto;
min-height: 41px;
max-height: 97px;
width: 387px;
border: 1px solid #e4e7ec;
border-radius: 20px;
background-color: #f9fafb;
outline: none;
padding: 0 24px 0 24px;
overflow: hidden;
}
<div class="chat-wrapper">
<p>
Using div with contentEditable:
</p>
<div class="message-text" contentEditable></div>
<br/>
<p>
Using regular textarea:
</p>
<textarea></textarea>
</div>
Now for the input text box, I have two solutions:
Using div with contentEditable attribute, it works and it is expandable to a certain height. But the text is not centered vertically (I'm trying to avoid using Flex, just to make sure old browsers are compatible, not very strict about that though)
Using textarea, it is more semantic IMHO, but it doesn't expand automatically.
I want also to detect the keypress event (I don't think it is a problem in both solutions).
Which solution do you think is the web standard? If both are good, how do make the div centers the text, and shrink the paddings when it grows? Or in the case of textarea, how do I make it expand without JS?
Also if you have any better suggestions, let me know.
UPDATE:
I just realized how messy is the option (div with contentEditable):
As you can see, first I can't wrap the text to lines when the text is more than the width.
Second, the text inside the div, is not clean ! Especially when copy-pasting. I need it to be pure text so when I use JS to get the content, I get just the text not the html tags.
I'm assuming that you want your padding preserved and it that case you could do something like this with contenteditable.
Add the wrapper around the .message-text:
<div class="chat-wrapper">
<p>
Using div with contentEditable:
</p>
<div class="message-wrapper">
<div class="message-text" contentEditable></div>
</div>
</div>
Update CSS:
.chat-wrapper {
width: 100%;
}
.message-text {
min-height: 1em; /* prevent height collapsing when there is no text */
max-height: 97px;
width: 100%;
align-content: center;
outline: none;
overflow: hidden;
}
.message-wrapper {
width: 387px;
border: 1px solid #e4e7ec;
border-radius: 20px;
background-color: #f9fafb;
padding: 24px; /* the container will keep the padding untouched */
max-height: 145px; /* added padding to the height of the .message-text */
}
Check the snippet:
.chat-wrapper {
width: 100%;
}
.message-text {
min-height: 1em; /* prevent height collapsing when there is no text */
max-height: 97px;
width: 100%;
align-content: center;
outline: none;
overflow: hidden;
}
.message-wrapper {
width: 387px;
border: 1px solid #e4e7ec;
border-radius: 20px;
background-color: #f9fafb;
padding: 24px; /* the container will keep the padding untouched */
max-height: 145px; /* added padding to the height of the .message-text */
}
textarea {
resize: none;
box-sizing: border-box;
height: auto;
min-height: 41px;
max-height: 97px;
width: 387px;
border: 1px solid #e4e7ec;
border-radius: 20px;
background-color: #f9fafb;
outline: none;
padding: 0 24px 0 24px;
overflow: hidden;
}
<div class="chat-wrapper">
<p>
Using div with contentEditable:
</p>
<div class="message-wrapper">
<div class="message-text" contentEditable></div>
</div>
<br/>
<p>
Using regular textarea:
</p>
<textarea></textarea>
</div>
max-height: 145px for the .message-wrapper is actually the height of content box, and that helps with pushing the .message-text with padding from the top and bottom.
I hope I got the right idea of what you want to achieve,let me know if this helps.

Two different widths on two different browsers

hello guys i have a div which contains a link and a div , i gave a width of 70% to the link and a width of 30% to the div (summing it up to 100%). its working fine in chrome , but its not working in safari ..the width property of the link is not taking any effect in safari.Please help
.rec-p-b {
width: 70%;
background-color: #fff;
border-radius: 0px;
padding: 7px 10px;
}
.rec-p-b1 {
width: 30%;
background-color: #02020294;
border: 1px solid #034039;
border-radius: 0px;
padding: 0px 5px;
}
<div class="recomment_profile_b_view">
<a target="_blank" href="" class="recomment_pro_button rec-p-b">Profile View</a>
<button class="recomment_button rec-p-b1">
<img src="images/recommend.png" alt="recomment">
</button>
</div>
The link tag is an inline element, so you should set it display: block, or inline-block, or float: left to floating it as block element.
You had added the padding beside adding the width, the total size will be equal padding + width. To fix it, you should add box-sizing: border-box; to your css to merge the with as 100% of the size:
.rec-p-b {
float: left;
width: 70%;
background-color: #fff;
border-radius: 0px;
padding: 7px 10px;
box-sizing: border-box;
}
.rec-p-b1 {
float: left;
width: 30%;
background-color: #02020294;
border: 1px solid #034039;
border-radius: 0px;
padding: 0px 5px;
box-sizing: border-box;
}
I think the problem is the padding you add. Try use box-sizing: border-box
* { box-sizing: border-box }
.rec-p-b {
width: 70%;
background-color: #fff;
border-radius: 0px;
padding: 7px 10px;
}
.rec-p-b1 {
width: 30%;
background-color: #02020294;
border: 1px solid #034039;
border-radius: 0px;
padding: 0px 5px;
}
<div class="recomment_profile_b_view">
<a target="_blank" href="" class="recomment_pro_button rec-p-b">Profile View</a>
<button class="recomment_button rec-p-b1">
<img src="images/recommend.png" alt="recomment">
</button>
</div>
Apply display: block to anchor tag
Apply following properties to both(anchor & div):
box-sizing: border-box;
float: left;

How can I make curved form text inputs in HTML & CSS?

I have a project to create a website designed in PhotoShop. I want to create a to textbox in HTML and CSS which looks like this:
As you can see, there is no problem with the background or fonts; the problem is the textbox. How can I create textboxes with these curves?
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
div {
background: #444;
direction: rtl;
width: 300px;
padding: 20px;
}
label {
width: 100%;
color: #fff
}
input {
border-radius: 0 2em;
padding: 0 10px;
width: 100%;
border: none;
line-height: 2em;
margin-bottom: 20px;
}
textarea {
border-radius: 0 4em;
padding: 0 10px;
width: 100%;
border: none;
line-height: 2em;
margin-bottom: 20px;
}
input[type="submit"] {
max-width: 100px;
}
<div class="wrapper">
<label>Name</label>
<input type="text" />
<label>Email</label>
<input type="text" />
<label>Message</label>
<textarea></textarea>
<input type="submit" value="Submit" />
</div>
This is how to get the shape in your image. You will need to learn a bit about border-radius.
The following is an example:
div#test {
border: thin solid #666;
width: 8em;
height: 2em;
border-radius: 0 2em 0 2em;
}
<div id="test"> </div>
The border-radius property is responsible for rounding corners. It can be very sophisticated, but the simple one here will do the job. You will just need to adjust some of the values.
The four values in the border-radius property represent the radius of the individual borders, clockwise from the top-left corner.

Input form overrides padding?

I got an input form that is supposed to be 100% wide inside my .content class and have 20px padding inside that class and 8px padding to the left inside of that input form. The problem is that the left padding inside the input form overrides the padding inside the .content class to the right.
JS: http://jsfiddle.net/8AsxX/1/
CSS:
.content {
min-height: 100%;
background-color: #000;
padding: 20px;!important
}
input.text.big {
background-color: #ffffff;
height: 30px;
width: 100%;
border: solid 1px #cccccc;
padding-left: 8px;
color: #333;
}
HTML:
<div class="content">
<input class="text big" name="url" type="url" placeholder="Example: http://www.facebook.com/FANPAGE-URL" required="">
</div>
The whole width is calculated like 100% + 8px for the input element, so it is overlapping parent div with padding:20px. You can fix it using calc for the input :
width: calc(100% - 8px);
Example
Box sizing should do the trick.
.content {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
I believe the behaviour is by design. You can compensate for it by increasing the right-padding of the container:
.content {
min-height: 100%;
background-color: #000;
padding: 20px 28px 20px 20px;
}

Firefox button and text input bug

I have this really weird problem, button and input have a same CSS (except background), but Firefox renders those differently. There are no problems in IE or Chrome.
#searchInput {
width: 80%;
margin: 0 auto;
display: block;
height: 40px;
border: 1px solid #D8D8D8;
font-size: 1rem;
padding: 10px;
text-align: center;
}
#searchButton {
width: 80%;
margin: 4px auto;
display: block;
height: 40px;
border: 1px solid #D8D8D8;
font-size: 1rem;
padding: 10px;
text-align: center;
background: #F2F2F2;
cursor: pointer;
}
I have also included container CSS, where they both are.
.section {
width: 100%;
display: inline-block;
margin: 10px auto;
background-color: #FAFAFA;
border-radius: 5px;
border: 1px solid #D8D8D8;
padding: 30px;
position: relative;
}
.toggleIcon {
width: 28px;
height: 20px;
top: 0;
right: 10px;
position: absolute;
border-radius: 5px;
background: #FAFAFA;
margin-top: 10px;
padding: 10px;
border: 1px solid #D8D8D8;
cursor: pointer;
box-sizing: content-box;
}
HTML:
<div id='search' class='section'> <a href="#sidebarNav" class='toggle'><img class = 'toggleIcon' src = 'img/icons/glyphicons_158_show_lines.png' alt = 'Open navigation'></a>
<img id='logo' src='img/logo.png'>
<form id='searchForm'>
<input type='text' id='searchInput' name='searchInput'>
<button type='submit' id='searchButton' name='searchButton' value='Search'>
<img src='img/icons/glyphicons_027_search.png' alt='Search'>
</button>
</form>
<div id='searchResults'></div>
</div>
NB! I use PageSlide for navigation and search is using AJAX
Based on your last comment...
Margin doesn't cause my problems, problem is that input is much wider
and higher
You have to add box-sizing:border-box property to your input#searchInput
Like:
#searchInput {
....
box-sizing: border-box;
-moz-box-sizing: border-box; /* Firefox */
}
Working Example: http://jsfiddle.net/XLyBR/1/
Your margin differs in the searchInput and searchButton css classes
Also what about the default css line-height on these elements - do they differ - try specifying line-height.
Wing
BTW - it would help if you tell us how the rendering differs