This question already has answers here:
How can I transition height: 0; to height: auto; using CSS?
(41 answers)
Closed 7 years ago.
I have a DIV with a default fixed height and an overflow:hidden property to hide content that is to broad to be contained inside it.
div
{
height:50px;
overflow:hidden;
}
I would like to autoexpand this DIV hovering it with mouse but I have the problem that CSS transition works only with a fixed height and not with an auto height.
Here a JsFiddle that illustrate two cases.
I know that reason is that for some reason browrse does not know "how many px are auto height" but is there exist a workaround (maybe using max-height property...) to avoid need of jQuery?
When you give height: auto in the animation, it doesn't know what to do. As it cannot calculate the height on the fly. So, initialize the height using jQuery this way:
$(function () {
$(".auto_height").each(function () {
$(this).data("height", $(this).height());
});
});
And in CSS, give:
height: attr(data-height);
Related
This question already has an answer here:
css how to make max-width fixed when adding padding
(1 answer)
Closed 6 months ago.
I'm learning CSS with W3school,in max width lesson, it was said the max-width is the maximum width of an element
So in this code i see this rule is not actually work!
<style>
div {
width:499px;
max-width: 500px;
height: 100px;
padding: 30px;
background-color: powderblue;
}
</style>
When i increase the padding , the width on the site will also increase.
What is the missing point in this lesson?
In what circumstances the max-width will work correctly?
The problem can be solved when you add this to your CSS code.
box-sizing: border-box;
I suggest watching some tutorials about this line of code.
This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Why is this inline-block element pushed downward?
(8 answers)
Closed 3 years ago.
Example:
https://codepen.io/229075284/pen/aboQVXZ
.outer{
background-color: pink;
}
.outer::after{
content:'';
background-color: red;
display: inline-block;
font-size: 0;
line-height: 0;
overflow: hidden;
height: 0;
/* display: table; */
}
.inner{
background-color: blue;
height: 300px;
}
<div class="outer">
<div class="inner"></div>
</div>
When I set display of outer::after to inline-block,the outer will have some extra space marked as pink, even if set font-size and line-height to 0. However, when I set display to table,the extra space disappears.
So I am wondering why the extra space appears?
I checked your codepen. It is a combination of both display: inline-block and content: "" on the ::after pseudo element. You are basically telling the browser that right after the outer element you want to reserve an element's place in the DOM.
You could see that if you remove the content: "" although you are using inline-block the extra pseudo div after the .outer element would disappear. That is because although you stated a certain display mode you practically have no content in this element and the browser ignores your element because it has no fixed size in pixels and no actual content within it.
The reason .outer is growing is that its height is set to auto in default, if you would give it a fixed height in pixels it might not show the spare div.
Your question has nothing to do with line-height or `overflow'.
Me personally I prefer not to use pseudo-classes like ::after and ::before in production. I prefer using regular divs and have my code more readable and understandable by other developers, anyway I hope I helped out. Feel free to discuss further if you have more questions.
This question already has answers here:
Bootstrap 4 square grid
(2 answers)
Maintain the aspect ratio of a div with CSS
(37 answers)
Closed 4 years ago.
I'm building some global button classes for a CSS framework, and I'm wondering if there's any way to set an element's width to be the same as the height without hard-coding it.
Here's an example of how it would work:
HTML
<button class="button square-button">OK</button>
<div class="container">
<button class="button large-button square-button">OK</button>
</div>
CSS
.button {
height: 50px;
padding: 0 20px;
}
.square-button {
width: (always-same-as-height);
padding: 0; // Disable padding so it becomes a square
}
...
.container {
height: 100px
.button {
height: inherit;
}
}
In some scenarios I want to be able to set the height depending on the container height, and have all the buttons with the square-button class dynamically resize to that height while still staying a perfect square shape.
Is this possible using only CSS?
You can make use of CSS variables modules to achieve that. However, the browser support for CSS variables is not so good. So, proceed with caution by first checking if the browser versions you wish to support have implemented CSS modules or not.
This question already has an answer here:
Removing spacing under the image
(1 answer)
Closed 6 years ago.
i have this code (https://jsfiddle.net/26gvaekf/1/) and want that A height was exactly at IMG boundaries. However, there is small space after IMG
can anybody explain, why this happens? and which css property i should use (only not float one).
DEMO
css
img {
vertical-align:top /* img are default bottom aligned make it to top */
}
/* for demonstration purpose */
a {
display: inline-block /* to cover your img completely */
}
This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 7 years ago.
Im trying to center a (pumpkinvector.jpg) image inside a .div using this classic trick:
.pumpkin{
position: relative;
top:50%;
left:50%;
transform: translate(-50%,-50%);
}
It seems to work fine on the very bottom div where background is red.
However, that was just a test, it is not were I need the image to center.
I need to center pumpkinvector.jpg image up top in "grid2" div that inside "grid 6 october" div. October div has additional code and inner class to give background image and make it resize proportionally in height and width %. Using the same centering code above, the pumpkinvector.jpg now flows to the next line and starts to position outside of the .october div. Can someone why this is?
Please bear with me here. I thought the addition of images helps you visualize my problem so I uploaded to my own site instead of js.fiddle.
Here is the link:
http://jingsportfolio.com/october.html
Please view source to view code. Thanks.
This question is different because it asks how to center div in the context that its parent div has complex markup that makes any traditional centering off and throws in on a new line below parent div.
Check this little example probably will be useful, how to center a image inside a div
The html code:
<div class="parent">
<img src="http://45reu03dndd711szsx3satxn.wpengine.netdna-cdn.com/wp-content//uploads/2015/08/Top-10-best-CSS-development-tools-2015.png"/>
</div>
The css code:
.parent {
text-align: center;
width: 100%;
border: 1px solid #ccc;
}
img .picture {
width: 40px;
height: 40px;
}
This code is running here
Horizontal alignment is really easy with CSS:
the item you want to align has to have "margin: auto"
And the item wrapping has to have a fixed width.
Vertical alignment is a little more tricky:
This trick only works if your wrapper has a fixed height and your content to align is a textual tag like span or p or h1
use the line-height css attribute of the wrapper andset its value to its own height and it's done.
OR
if your content to align has a height of 300px use margin-top: calc(50% - 150px)
change 'margin-top' for absolute "position" and "top" attribute if needed