CSS - SearchBox overlapping divs' padding - html

I had this problem quite a few times and never were able to solve it.
I basically just have a div with 20px padding and would like to fit the searchbox 100% relative to the divs' possible width (including the padding). But the searchbox keeps overlapping the padding from the div. Can anybody help me there?
<div class='content'>
<form id='submit' action='' method=''>
<input type='text' autofocus='on' placeholder='Search with DuckDuckGo' autocomplete='off' id='searchBox'>
</form>
<p>Lorem</p>
<p>Lorem</p>
<p>Lorem</p>
</div>
 
.content { # This is the main div!
background-color: rgba(240,240,240, 1);
padding: 20px;
display: inline-block;
text-align: center;
margin-top: 25%;
width: 40%;
box-shadow: 0px 0px 20px 3px #101010;
}
#searchBox { # This here is the search box that keeps overlapping the padding from the content div...
width: 100%;
height: 30px;
padding: 10px;
font-size: 20px;
border: 1px rgba(10,10,10, 0.2) solid;
#border: none;
color: rgba(10,10,10, 0.5);
font-family: 'Roboto', 'Tahoma', 'sans-serif';
}
Here is a JS fiddle example to visualize it a little bit better.

You can remove the padding property for #searchBox and explicitly set the padding-top and padding-bottom property to 10px (Which will remove left and right padding).
#searchBox {
width: 100%;
height: 30px;
padding-top: 10px;
padding-bottom: 10px;
font-size: 20px;
border: 1px rgba(10,10,10, 0.2) solid;
color: rgba(10,10,10, 0.5);
font-family: 'Roboto', 'Tahoma', 'sans-serif';
}
https://jsfiddle.net/0e2Ljgr8/1/
An alternative solution would be to reduce the width of #searchBox to 90% width, as shown in this JSFiddle:
https://jsfiddle.net/0e2Ljgr8/3/

Related

Increase textarea width space evenly inside container, when over its width limit - css

I'm trying to increase the size of this textarea evenly. But when I change it from 100% width to higher than that, it increases only to the right. I tried margin auto and display block but doesnt work.
Here is my css:
textarea[form="chform"] {
width: 100%;
height: 230px;
background: transparent;
border: 1px solid rgba(255,255,255,0.6);
border-radius: 2px;
color: grey;
font-family: 'Exo', sans-serif;
font-size: 16px;
font-weight: 400;
padding: 4px;
margin-top: 10px;
resize:none;
}
.profile__form{
padding: 15px;
margin: auto;
border-radius: 50%;
}
.profile_container {
width: 400px;
margin: 120px auto 120px;
/*background: linear-gradient(270deg, rgba(223,190,106,0.8), rgba(146,111,52,0.8), #f0f0f0, rgba(223,190,106,0.7));*/
padding: 0 20px 20px;
border-radius: 6px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
box-shadow: 0 2px 5px rgba(0,0,0,0.075);
-webkit-box-shadow: 0 2px 5px rgba(0,0,0,0.075);
-moz-box-shadow: 0 2px 5px rgba(0,0,0,0.075);
text-align: center;
}
jade:
extends layout
block content
body(style='background-color:black')
link(href='http://fonts.googleapis.com/css?family=Great+Vibes', rel='stylesheet', type='text/css')
div.right
if(user)
a Welcome #{user.name}
| &nbsp
a(href='/main') Home
| &nbsp
a(href='/profile') Profile
| &nbsp
a(href='/logout') Logout
else
a(href='/main') Home
| &nbsp
a(href='/register') Register
| &nbsp
a(href='/login') Login
div.profile_container
form.profile__form(role='form', action="/add-chapters",id="chform" method="post", style='max-width: 800px;')
.profile__form-heading Add Chapter
input.form-control(type='number', min="1" name="chapterNumber", id="inputChapterNumber" placeholder='Chapter Number')
br
input.form-control(type='text', name="chapterTitle", id="inputChapterTitle", placeholder='Title')
textarea(name='chapterStory', cols='30', rows='5', form="chform", placeholder="Enter Story")
br
button.chform(type='submit') Save
HERE IS IMAGE of what I see so far after increasing width. I just want a bigger textarea and centered:
https://i.stack.imgur.com/xSBdL.jpg
Edit: ok added parent css
IMAGE NOW FIXED:
https://i.stack.imgur.com/dbtiY.jpg
So I fixed it by increasing width of parent container the profile form and profile container. Then position relative, display block, and margin auto. Simple!
textarea[form="chform"] {
width: 70%;
height: 500px;
background: transparent;
border: 1px solid rgba(255,255,255,0.6);
border-radius: 2px;
color: grey;
font-family: 'Exo', sans-serif;
font-size: 16px;
font-weight: 400;
padding: 4px;
resize:none;
position: relative;
display:block;
margin:auto;
margin-top: 10px;
}

HTML textarea shows dynamic text half the height

HTML <textarea> shows dynamic text half its height when it first loads [when the page loads] like this:
When you focus and start typing or pushing left or right arrow keys, then it shows the text to its full height as it should like this.
How to make the dynamic text appear at its full height when it first loads without having to focus on the <textarea> and push right/left arrow keys? Here is the HTML and CSS codes:
textarea {
height: 55px;
background-color: #009688;
font-size: 55px;
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
<textarea id="location" style="overflow:hidden"></textarea>
Thank you.
I think it is because the padding/margin you have added. Try running by removing the padding/margin and see if that works for you.
You want the height to include the padding and border size as you have used box-sizing so your height should be the size of the font plus top and bottom padding and border
In this case that is 55px (font) + 24px (12px top and 12px bottom padding) + 2px (border - you have no top and 2px bottom) = 81px
textarea {
height: 81px;
background-color: #009688;
font-size: 55px;
line-height:55px; /* added this just to ensure the line height is the same as the font size */
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
<textarea id="location" style="overflow:hidden">someText</textarea>
Please check the updated one. Added line-height and updated attribute to rows=1 instead of giving height to textarea.
textarea {
min-height: 55px;
background-color: #009688;
font-size: 55px;
line-height: 60px;
width: 100%;
padding: 0 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
<textarea id="location" rows="1" style="overflow:hidden"></textarea>
Just increase height as height and font-size is same:
textarea {
height: 80px;
background-color: #009688;
font-size: 55px;
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
Adjust font-size and padding like
padding: 12px 12px;
and
font-size: 40px;
Try this: I just remove the padding. You can also add the padding just add more height
Explanation:
The size of font and the height of textarea is the same PLUS you have a padding.
textarea {
height: 55px;
background-color: #009688;
font-size: 55px;
width: 100%;
/*padding: 12px 20px;*/
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
<textarea id="location" style="overflow:hidden">Prefilled</textarea>

<div> padding auto increasing when using table-cell

I created two tables using table,table-cell. But when I increase padding on first cell it also increasing padding on second cell also vice versa. What is the reason and how to solve it.
.desc-one{
width: 100%;
margin-bottom: 20px;
display: table;
}
.desc-one-one{
width: 350px;
background-color: #ffffff;
display: table-cell;
padding-right: 10px;
border-radius: 10px;
vertical-align: top;
box-shadow: 0px 2px 1px #888888;
}
.quick-heading{
font-size: 20px;
font-family: opensans-semibold;
color: #2199e8;
padding-left: 10px;
padding-top: 5px;
}
.row-two-one{
max-width: 1200px;
border-radius: 10px;
background-color: #ffffff;
box-shadow: 0px 2px 1px #888888;
}
.desc-one-two{
display: table-cell;
padding-left: 20px;
}
.recent-heading{
color: #2199e8;
font-size: 20px;
font-family: opensans-semibold;
}
<div class="desc-one">
<div class="desc-one-one">
<h1 class="quick-heading">
Quick links
</h1>
</div>
<div class="desc-one-two">
<div class="row-two-one">
<h1 class="recent-heading open-semibold">
Low Stock Distributors
</h1>
</div>
</div>
</div>
In CSS code: If I increase padding-top / padding-bottom of my first table cell heading, the second cell elements also taking the padding mentioned in first cell (vice versa)
I have tried your code and found that only the first heading gets the padding top. Maybe you have another bit of code on your page somewhere that is adding this extra padding.
.desc-one {
width: 100%;
margin-bottom: 20px;
display: table;
}
.desc-one-one {
width: 350px;
background-color: #ffffff;
display: table-cell;
padding-right: 10px;
border-radius: 10px;
vertical-align: top;
box-shadow: 0px 2px 1px #888888;
}
.quick-heading {
font-size: 20px;
font-family: opensans-semibold;
color: #2199e8;
padding-left: 10px;
padding-top: 100px;
}
.row-two-one {
max-width: 1200px;
border-radius: 10px;
background-color: #ffffff;
box-shadow: 0px 2px 1px #888888;
}
.desc-one-two {
display: table-cell;
padding-left: 20px;
}
.recent-heading {
color: #2199e8;
font-size: 20px;
font-family: opensans-semibold;
}
<div class="desc-one">
<div class="desc-one-one">
<h1 class="quick-heading">
Quick links
</h1>
</div>
<div class="desc-one-two">
<div class="row-two-one">
<h1 class="recent-heading open-semibold">
Low Stock Distributors
</h1>
</div>
</div>
</div>
Your code works just fine, as the other answers say..
However, in one comment you remark that it works the way you describe if you remove the vertical-align:top from the style of the first cell.
Then why did you have this property in there in the first place? It confuses the matter to people who want to answer.
The answer is, if you don't specify any vertical-align property, it defaults to 'baseline`. That means that both cells align their contents to one another, on the bottom of the first line of text in each of them. That's simply how table cells behave; they work together.
The solution, therefore, is to put vertical-align:top in, which causes the cells to align their contents to their tops.

Maintaining border size

I have this CSS class:
.numberCircle {
border-radius: 30%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
width: 36px;
height: 36px;
padding: 0px 5px 0px 5px;
background: #fff;
border: 2px solid #333;
color: #333;
text-align: center;
font-size: large;
font-weight:bold;
}
I want to keep the same border width even when the number changes, from 10 to 9.
Right now, the border expands when the number changes.
Here's a JFiddle of what I mean.
I've already tried changing the padding attribute but I can't make it work.
Try this. Add display:inline-block and then line-height to vertically align the numbers. By setting this the box will expand. adjust the height & width as per your need. If so, do not forget to adjust the line-height relative to height of the box.
.numberCircle {
border-radius: 30%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
line-height:36px; /*vertcally center the numbers*/
width: 36px;
height: 36px;
padding: 0px 5px 0px 5px;
display:inline-block; /* Added */
background: #fff;
border: 2px solid #333;
color: #333;
text-align: center;
font-size: large;
font-weight:bold;
}
<span class='numberCircle'>10</span>
<span class='numberCircle'>9</span>
You can just explicitly set the width. I suggest a unit of mesure that's relative to the font size (namely ems)
Edit: it seems all you were missing was display:inline-block. You can't set the width of an inline element. Adding it will probably get you most of the way there.
.numberCircle {
border-radius: 30%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
/*width: 36px;
height: 36px;*/
padding: 0px 5px 0px 5px;
background: #fff;
border: 2px solid #333;
color: #333;
text-align: center;
font-size: large;
font-weight:bold;
display: inline-block;
width: 1.5em;
height: 1.5em;
line-height: 1.5em;
}
<span class='numberCircle'>10</span>
<span class='numberCircle'>9</span>
Check out these properties:
line-height:20px; /*this will center your numbers inside the border*/
width: 20px; /*set the same as line-height and height in order to give a square shaped border*/
height: 20px; /*set the same as line-height and width in order to give a square shaped border*/
display: inline-block;
line-height, width and height will shape your box. While the new display property will help to align the elements in a "one after the other" fashion. :)

CSS float attribute for a sidebar (I can use tables if necessary)

Ok I am having trouble with a school project where we must create a website with 5 pages, and publish it one of the requirements is a sidebar on every page, but the problem is we are not allowed to use absolute positioning only float and tables can be used to do this.
Here is my External CSS
/* CSS Document */
body{
background-color: #181818;
color: #E60000;
}
#header{
text-align: center;
background-color: #000080;
padding: 20px 0px 0px 0px;
}
#body{
/*this is here for only a certain part of the body*/
background-color: #000080;
border: 5px inset #C0C0C0;
margin-left: 0.7%;
margin-right: 39%;
padding: 10px 5px 10px 0px;
}
#sidebar{
background-color: #000080;
border: 5px inset #C0C0C0;
margin-right: 0.7%;
margin-left: 65%;
padding: 10px 5px 10px 0px;
text-align: center;
height: 100%;
float: right;
}
p{
line-height: 160%;
font-family: Verdana, Arial, Helvetica, sans-serif;
Padding: 5px 10px 5px 10px;
}
/*Navigation bar*/
ul{
background-color: #000080;
margin: 10px 10px 0px 10px;
list-style-type: none;
padding: 5px 0px 5px 0px;
text-align: center;
border: 5px inset #C0C0C0;
}
ul li{
display: inline;
padding: 5px 20px 5px 20px;
text-align: center;
}
ul li a:link, ul li a:visited{
color: darkred;
border-bottom: none;
font-weight: bold;
}
ul li.selected{
background-color: #181818;
}
and here is my HTML
<div id="body">
<h1 id="header">About me</h1>
<p>some stuff
<br>
<br>other stuff</p>
<h2 style="text-align: center;">Me</h2>
<ol>
<li></li>
<li></li>
</ol>
<p style = "text-align: center;">
stuff<br>
br>Much more stuff</p>
</div>
<div id="sidebar"><h1>Name here</h1>
<p>Even more stuff</p>
</div>
Alright that is all the code I used for this I hope this helps
(sry this isn't codded correctly based on the websites standards but I couldn't get it to work sry)
alright Now Either I can get both #sidebar and #body's divs to appear in the same location; however one of there text will be below the other div container or one div will appear below the other on one side of the page, and I know this isn't very good CSS it's just a rough outline, but this is the biggest problem that stands out to me that will be hard to fix, so if anyone can help I would appreciate it.
I believe this is what you are looking for.
You can set the main content section - i believe you use #body - to have a width of e.g 70% and then the sidebar to have a width of 30%. Then use float: left; on both the elements.
Keep in mind that the 70/30 does not factor in padding or margins, which you will need to account for.
the code could look like this
> #body{ width: 60%; background-color: blue; float: left; height: 200px; }
> #sidebar{ width: 20%; background-color: red; float: left; height: 200px; }
>
>
>
> <div id="body"></div> <div id="sidebar"></div>
So i tried to reproduce your issue in a Fiddle here: DEMO
You have quite a few CSS issues:
if you want to use float for your layout, both can be float left with widths set
you are mixing percentages in your margin (which i converted to width
values) and pixel values in your padding
you can use the universal selector to set the box-sizing to
'border-box' which does not add the padding values to the width
values (* { box-sizing: border-box; }) -- if you don't use this CSS
you need to be careful that your padding doesn't cause your elements
to become wider than 100% of the page (their parent element
Here is your CSS after my modifications.
* {
box-sizing: border-box;
}
#header{
text-align: center;
background-color: #000080;
padding: 20px 0px 0px 0px;
}
#body{
/*this is here for only a certain part of the body*/
background-color: #000080;
border: 5px inset #C0C0C0;
width: 65%;
padding: 10px 5px 10px 0px;
float: left;
}
#sidebar{
background-color: #000080;
border: 5px inset #C0C0C0;
width: 35%;
padding: 10px 5px 10px 0px;
text-align: center;
height: 100%;
float: left;
}
JS Fiddle demo
CSS
body{
background-color: #181818;
color: #E60000;
}
#header{
text-align: center;
background-color: #000080;
padding: 20px 0px 0px 0px;
}
#body{
/*this is here for only a certain part of the body*/
background-color: #000080;
border: 5px inset #C0C0C0;
margin-left: 10px;
margin-right: 20px;
float:left;
width:70%;
padding: 10px 5px 10px 0px;
}
#sidebar{
background-color: #000080;
border: 5px inset #C0C0C0;
padding: 10px 5px 10px 0px;
text-align: center;
width:20%;
height: 100%;
float: right;
}
p{
line-height: 160%;
font-family: Verdana, Arial, Helvetica, sans-serif;
Padding: 5px 10px 5px 10px;
}
I'm assuming body is where you're putting your content (not the html body tag with an id of body)
Anyways when you have two side by side containers you will want both with the same float.
Example
#body, #sidebar {
Float: right;
Padding: 2%;
}
#body {
Width: 70%;
}
#sidebar {
Width: 15%;
}
example values just make sure the width + margins + padding don't don't exceed 100% or the parent container max pixel width.
Box-sizing: Border-box;
can help with containers growing with padding or borders.