Textarea resize window - html

Go to http://kennethhedegaard.com/html2/index.html
Try to resize the window.
Can't figure out why the textarea is not scaling...
Kenneth

You should read this to make your textarea filling properly its parent.
In the code you posted the textarea has 100% width and padding which, with default values, means that you are going over with the padding. Moreover the div which contains the textarea has overflow set to hidden and that's why you cant se right border
EDIT (in case link suddently dies):
You have to add this class or rules to your textarea:
.boxsizingBorder {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
Cheers

Related

Textarea inside fieldset results in different margin/padding [duplicate]

This question already has answers here:
Textarea to fill a parent container exactly, with padding
(4 answers)
Closed 4 years ago.
I would like a textarea inside a fieldset to expand to the full width:
HTML
<fieldset>
<legend>Legendary</legend>
<textarea>I'm supposed to fill the fieldset, but the padding/margin isn't the same.</textarea>
<div></div>
</fieldset>
CSS
textarea{width: 100%;}
https://jsfiddle.net/gL8bjtv9/4/
However, the left/right gaps (padding/margin) between the elements are different (Firefox, Chrome).
Why does this occur, and how can it be fixed?
Also: if I change the textarea's width from "100%" (1588px computed) to "1588px" in Firefox's Inspector, it seems OK.
Solution (browser-specific rules): https://stackoverflow.com/a/6796064/1619432
box-sizing: border-box;
Seems to work for Firefox, too.
Mozilla web docs explains box-sizing best: https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
box-sizing: border-box;
width: 100%;
border: solid #5B6DCD 10px;
padding: 5px;
You can also play around with their great box-sizing visual tool to assist in understanding the CSS property better.
You could try doing this
textarea {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
or just adjust the rows attribute till it fits
<textarea rows="10" cols="4">I'm supposed to fill the fieldset, but the padding/margin isn't the same.</textarea>

How to make a border which wraps around text

I would like to make a text element have a border around it like this in an upcoming ghost dashboard: Ghost blog
I have done this:
border: 10px solid #ffffff;
however that works for the height but not the width. The width is a lot wider. I know I could set the width to something however I would like the width to update when the text is changed, so there is always a certain amount of space between the text and box on each side.
I'm not sure how to do this or if it needs JS or if it can be done with pure CSS.
You are going to want to use padding and display:inline-block; on a span element in order to do this. For example:
HTML
<span>GHOST</span>
CSS
span {
padding: 10px;
border: 10px solid white;
display: inline-block;
}
This will allow the border around the text to shrink and grow depending on the length. It will also keep 10px of space between the border and the letters no matter the size.
Here is a fiddle: http://jsfiddle.net/ZDzn2/
If I understood you correctly, you want the border-width to be included in the css-width?!
you should then try the box-sizing attribute via CSS:
box-sizing: border-box
The box-sizing CSS property is used to alter the default CSS box model used to calculate widths and heights of elements. It is possible to use this property to emulate the behavior of browsers that do not correctly support the CSS box model specification.
[Source: https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing]
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
[Source: http://css-tricks.com/box-sizing/]

HTML div child nodes aren't aligning

I'm editing a basic Wordpress template and looking to have a multi-column front page (showing 2 sets of articles per row). I've done the following in CSS:
.front-page-container article:nth-child(odd) {
width:50%;
float:left;
clear:both;
}
.front-page-container article:nth-child(even) {
width:50%;
float:right;
}
where front-page-contaner is the class of a containing div. The HTML structure is:
<div class="front-page-container">
<article id="post-1"></article>
<article id="post-2"></article>
<article id="post-3"></article>
<!-- etc -->
</div>
I want to align post 1 & 2 in the same line, and have post 3 (and 4) on the next row.
While the CSS sort of works, the two posts I want together don't line up as shown is this picture. I've tried adjusting the widths in case there was some sort of overlap but it doesn't fix the issue (even though they get visibly smaller).
Any help/pointers would be appreciated :)
.front-page-container::after { clear: both }
.front-page-container * {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
.front-page-container article:nth-child(odd) {
width:50%;
float:left;
}
.front-page-container article:nth-child(even) {
width:50%;
float:right;
}
That should do it. Box sizing makes the divs width the calculation of width minus padding and borders. So no padding or bordering will add to the declared width. (I think thats the best way to explain it). The ::after pseudo-element clears any floats after the container.
As a bonus I will add that this article helped me immensily with this subject:
http://css-tricks.com/dont-overthink-it-grids/
You posted code works as expected. See http://jsfiddle.net/XqDn6/1/
The issue is most likely some margin/padding on the article elements causing the width of each element to exceed 50% and so not being able to fit 2 in a row..
One way to solve this problem is to use box-sizing: border-box which means that border/paddings are included in the width value.
.front-page-container article{
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
Demo with border/paddings and box-sizing: http://jsfiddle.net/XqDn6/2/
It works just fine for me: http://codepen.io/skimberk1/pen/6127d1c3a4961de1f9c1ef20d5400d0f.
I have no idea what could be going wrong in your case. Maybe some other CSS is affecting it?
Using the CSS box-sizing: border-box; might help, as it makes it so that the maximum width (including padding and border) is the width you defined (in this case 50%);
The problem is clear: both, as read in CSS schools,
No floating elements allowed on the left or the right side of a specified paragraph.
Here's an exampleo f how clear can be used: Understanding the CSS Clear Property.
Though float is an old solution used for stretching the container, as can be seen here: Clearing floats.
Solution: delete that if you can or edit the question for saying why its there (and cannot be taken off) so we can help you further.

CSS padding while retaining the defined size?

According to the standard, adding padding to a HTML element in CSS will grow the element by the amount defined. For example:
.elem {
width: 100px;
height: 100px;
padding: 20px;
}
will add 20 pixels to the .elem's sides, causing the actual width and height to be 140px total.
Since this is actually pretty impractical in web design (having to calculate and keep track of the resulting sizes), I was wondering if it was somehow possible to do the reverse instead. I set a padding, and the inner text area shrinks instead. So the element stays at 100*100px, has the padding of 20px inside it, and I don't have to worry about messing up my design while experimenting with the padding.
Is this possible? Perhaps through a language that compiles to CSS (haven't looked into that much)? And perhaps a more minor question: why does it work this way in the first place?
Use box-sizing:
elemSelector {
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
This value for the property declares that the declared size of the element will include the border and the padding.
References:
box-sizing at: 'CSS Basic User Interface Module Level 3 (CSS UI)'.
box-sizing at MDN.
It is currently impossible to perform what you are after. You'll have to account for padding in total width before you attempt to define what your css 'width' value will be. For more information on this, see the CSS Box Model. This is the only method to guarantee correct sizing in all web-capable devices, CSS3 compatible and not.

Setting TEXTAREA and INPUT fields to 100% width inside TD truncates right margin

Please help me fix this issue. I would like to set the width of INPUT and TEXTAREA elements to 100% so that they entirely fit the table cell but I noticed that the right border is truncated.
I tried to wrap the INPUT inside a DIV and set 'overflow' to 'hidden' as I read on other answers but it does not work:
<div style="overflow:hidden">
<input class="input_field" type="text" />
</div>
I also set margins and paddings, and width=95% too but the right border is always truncated even if it is well inside the TD.
Please see the HTML and CSS code at jsFiddle. Look carefully to the right border of the elements, you will see they are truncated. Set 'table border=0' to see better.
Use box-sizing: border-box (and the corresponding browser-specific versions):
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
See http://jsfiddle.net/trwut/4/
Related reading: http://paulirish.com/2012/box-sizing-border-box-ftw/
The CSS specification states that the width of an element does not include the border; which could be argued as wrong and complicates the width in scenarios like yours.
Funnily enough, Internet Explorer went against this CSS specification and used what was known as the box model (width including the border) - which caused a headache at the time, but can now be applied to other browsers using the following CSS:
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
To support my answer (as the upvote was removed), you can read the following article:
Revenge of the IE Box Model by Jeff Kaufman