CSS: When content expands I need content below it pushed down - css

Hey everyone first time posting so sorry if my format is a little off.
It took me a while but I finally found out how to cause a rollover of an image to cause my article to pop up under the picture. But the only I'm having now when when I roll over the image causing the article to appear below it, it doesn't affects the position of the images below it.
HTML
<div class="postBlock">
<img src="#.jpg" />
<article>
<h2>Check the mountains, nice.</h2>
<p>Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Tex
</p>
</article>
</div>
<div class="postBlock">
<img src="#.jpg" />
<article>
<h2>Check the mountains, nice.</h2>
<p>Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Tex
</p>
</article>
</div>
CSS
.postBlock {
position:relative;
width:250px;
height:250px;
margin:10px;
float:left;
font-family:"Verdana, Geneva, sans-serif";
border:5px solid #353432;
}
.postBlock img {
position:relative;
height:250px;
width:250px;
}
.postBlock article {
display:none;
}
.postBlock img:hover ~ article {
position:relative;
display:block;
}
.postBlock h2 {
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
So recap.
When I hover over the image box I want an article to roll out and move the image box below it down so that way you can read the article. CSS hopefully but if Javascript is needed just please explain it :) Thank you.
Here is a fiddle of it.Fiddle!

Just remove the height value from your .postBlock div and you're fine: http://jsfiddle.net/7P5RP/2/
Or if you wish, you can use min-height instead of height. The important thing is to allow the div to expand vertically.
Here is a nicer solution, I've moved the borders to the images, not the containers, I think this is what you're looking for: http://jsfiddle.net/7P5RP/3/

Related

Efect in accordion css

can someone tell me how I can achieve this effect on an accordion?
At the moment I only have this result
Linear gradient mask-image transparency (several different ways to make it). Below is one of the ways.
A helpful source for this is:
mozilla
.mask {
color: #000;
font-size: 20px;
mask-image: linear-gradient(to left, rgba(0,0,0,1), transparent);
mask-size: 100% 100%;
mask-repeat: no-repeat;
}
<div class="mask"><p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text </p></div>

Stop text from wrapping underneath image

I want to stop the text from wrapping underneath an image, without making any changes to the HTML. Can this be done solely by CSS? I know the text can be wrapped in a div but I'm not able to do that on Wordpress.
JSFiddle: https://jsfiddle.net/s01x1ere/
HTML
<div>
<p>
<img src="https://www.easycalculation.com/area/images/big-square.gif">
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
</p>
</div>
CSS
div {
width:500px;
}
img {
float:left;
height:100px;
width:100px;
}
You can try the above answer or you can just update your jsfiddle css with below css.
div {
width:500px;
position:relative;
padding-left:100px;
}
img {
height:100px;
width:100px;
position:absolute;
left:0;
}
If you know the height of the div, set margin-bottom of the image to the height minus the image's height.
For example, if the height of the div is 500px and the height of the image is 100px, then use margin-bottom: 400px.
img {
float: left;
height: 100px;
width: 100px;
margin-bottom: 400px;
}
Please attache this code
div { width:500px; }
img { float:left; height:100px; width:100px; margin-right: 15px;}
p { display: flex; }
<div>
<p>
<img src="https://www.easycalculation.com/area/images/big-square.gif">
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
</p>
</div>

Expanding div which children position is absolute

Is there any option to prevent parent element be overflowed by children element when children element position is absolute and hight of children is higher than parent? I don't want to hide overflowing part by overflow: hidden, I want to force parent div.alert height to be not lower than its children. As you can see I am using position:absolute and transform:tranlateY(-50%) to put the content of div in the middle independently of the content length. Unfortunately when content is higher than minimum height of parent it goes outside of parent.
<div class="alert">
<span>
text text text text text text text text text text text text
</span>
</div>
<div class="alert">
<span>
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
</span>
</div>
<div class="alert">
<span>
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
</span>
</div>
CSS:
body{
background: #000;
}
.alert{
position: relative;
margin: 35px 5px;
background: #4679BD;
color: #fff;
padding: 10px 15px;
min-height: 40px;
}
span{
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
JS FIDDLE
Thanks in advance.
Absolute positioning is used for exactly the opposite of what you're trying to achieve. You never clarified whether it has to be and why does it need to be absolute.
You can easily achieve the same effect using padding on the inside element:
body{
background: #000;
}
.alert{
position: relative;
margin: 35px 5px;
background: #4679BD;
color: #fff;
padding: 10px 15px;
min-height: 40px;
}
span{
padding: 12px 0;
display: inline-block;
}
<div class="alert">
<span>
text text text text text text text text text text text text
</span>
</div>
<div class="alert">
<span>
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
</span>
</div>
<div class="alert">
<span>
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
</span>
</div>
http://jsfiddle.net/rnq046wg/4/
Using the flex approach (be careful with older browsers):
body{
background: #000;
}
.alert{
position: relative;
margin: 35px 5px;
background: #4679BD;
color: #fff;
padding: 10px 15px;
min-height: 40px;
display: flex;
align-items: center;
}
span{
display: inline-block;
}
<div class="alert">
<span>
text text text text text text text text text text text text
</span>
</div>
<div class="alert">
<span>
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
</span>
</div>
<div class="alert">
<span>
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
</span>
</div>
There is no easy way to deal with this because position: absolute; is intended to "go out" from the parent's model.
What you can do to solve your problem is using another approach to vertically center:
.alert{
margin: 35px 5px;
background: #4679BD;
color: #fff;
padding: 10px 15px;
min-height: 40px;
display: table;
table-layout: fixed;
width: 100%;
box-sizing: border-box;
}
span{
display: table-cell;
vertical-align: middle;
}
Fiddle
If it a static text that not changed from time to time then give the min-height more space to contain the text.
Assign fix padding: 20px 0; it will always populate content in middle, instead of using absolute position and all other junk.

Lists: Centering a custom bullet with first line of text

possibly (hopefully) a simple question:
I'm using a png as a bullet in an unordered list using code found on here :
li {
background:url(../images/bullet.png) 0 0 no-repeat;
list-style:none;
padding-left:10px;
}
The only variation I've made to this is to set the vertical background position to 50% so that the bullet stays centred regardless of the size of text etc (and/or to avoid the need for different sized bullet pngs depending on text size).
The only problem with this is that if the text in the list moves onto a second line, the bullet centres with the two-line width of text (in other words the bullet sits somewhere near the space between the two lines).
Is it possible to keep the bullet centered with the font height, but of the first line only ?
Cheers in advance for any tips.
Maybe try setting a relative line-height to the element and use pseudo element to hold the bullet. This works with any text size:
ul {
line-height: 1.25;
font-size: 16px;
}
ul li {
list-style:none;
position: relative;
}
ul li:before {
position: absolute;
content: '';
width: 1em;
height: 1em;
margin-left: -1.5em;
margin-top: .2em;
line-height: inherit;
background:url(../images/bullet.png) 50% 50% no-repeat;
list-style:none;
padding-left:10px;
}
Demo Fiddle
Seems to work here:
HTML
<ul>
<li>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text </li>
</ul>
CSS
ul {
list-style:none;
}
li {
background:url(http://drjohnart.com/wp-content/uploads/2011/11/bullet-point.gif) 0 0 no-repeat;
padding-left:20px;
margin:0;
}

Wrapping text around a div (in the middle of the text) using css

How can I wrap a text around a div. Leaving the div at the middle of the text body using css?
Sketch:
text text text text
text text text text
text text text text
text text text text
+-------+ text text
+ + text text
+ div + text text
+ + text text
+-------+ text text
text text text text
text text text text
text text text text
text text text text
NOTE: From the HTML point of view, the div goes before the text.
<div></div> [... text...]
The other answers are correct in that you'll need to float the <div> (e.g. div { float: left; margin: 10px 0 10px 10px; }, however, keep in mind that in order for the <div> to appear in the middle of you content, it will have be in the content itself.
When using a float like this, you have to just remember that you have to insert the <div> right before the content that you want to wrap around it. So, in this case, have a paragraph of text, insert the <div>, then have a couple more paragraphs. When you float the <div>, it will appear in the middle of your content.
You need to float your div. For example you could style the div like this:
float:left;
margin:10px; //To leave a gap around the div
what you need is the float property. Try this example below:
.youDiv {
float: left;
}

Resources