Flexbox align content - html

I have a pretty basic structure like so
<section id="portfolio">
<div class="col-lg-5 col-sm-5 vertical-center" id="portfolio-left">
<div id="portfolio-title">
<h2>Work</h2>
</div>
</div>
<div class="col-lg-7 col-sm-7" id="portfolio-right">
<div class="swiper-slide goldBG" id="cSlide2">
<div class="col-md-6 col-md-offset-3 vertical-center" id="inner">
<h3>Some title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
</section>
It has a left section and a right section. Now I wanted the content within these section to be vertically aligned in the middle, so I used flex for the first time
.vertical-center {
align-items: center;
display: flex;
}
This works well as you can see from the JSFiddle The problem I am having is with the right section. You can see that it is vertically aligned correctly, however, the items (h3 and p) inside seem to be aligned inline.
Is there any way I can get these items to display as a block? I have tried a few things that do this, but then it messes up my vertically alignment.
Any advice appreciated.
Thanks

Make you inner div a column flexbox:
#inner {
flex-direction: column;
align-items: flex-start;
justify-content: center;
}
See demo below:
#portfolio {
height: 100vh;
}
section#portfolio {
padding-bottom: 0;
padding-top: 0;
}
#portfolio-right {
height: 100%;
padding: 0;
}
#cSlide2 {
height: 350px !important;
}
#cSlide2 #inner {
height: 100%;
}
.vertical-center {
align-items: center;
display: flex;
}
#portfolio-right .goldBG {
background: #fabc2f;
}
#portfolio-left {
height: 100%;
background: #35a887;
}
#inner {
flex-direction: column;
align-items: flex-start;
justify-content: center;
}
<section id="portfolio">
<div class="col-lg-5 col-sm-5 vertical-center" id="portfolio-left">
<div id="portfolio-title">
<h2>Work</h2>
</div>
</div>
<div class="col-lg-7 col-sm-7" id="portfolio-right">
<div class="swiper-slide goldBG" id="cSlide2">
<div class="col-md-6 col-md-offset-3 vertical-center" id="inner">
<h3>Some title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
</section>

Put your <h3> & <p> inside a parent <div> (in my case its .content-holder). Because its the property to flex to inline the items.
Like:
<div class="content-holder">
<h3>Some title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
You can use flex-direction: column too but this will make each of your content wrap to next line, so its better to wrap these into a parent div.
Have a look at the snippet below:
#portfolio {
height:100vh;
}
section#portfolio {
padding-bottom: 0;
padding-top: 0;
}
#portfolio-right {
height: 100%;
padding: 0;
}
#cSlide2 {
height:350px !important;
}
#cSlide2 #inner {
height:100%;
}
.vertical-center {
align-items: center;
display: flex;
}
#portfolio-right .goldBG {
background: #fabc2f;
}
#portfolio-left {
height:100%;
background: #35a887;
}
<section id="portfolio">
<div class="col-lg-5 col-sm-5 vertical-center" id="portfolio-left">
<div id="portfolio-title">
<h2>Work</h2>
</div>
</div>
<div class="col-lg-7 col-sm-7" id="portfolio-right">
<div class="swiper-slide goldBG" id="cSlide2">
<div class="col-md-6 col-md-offset-3 vertical-center" id="inner">
<div class="content-holder">
<h3>Some title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
</div>
</section>
Hope this helps!

Related

Div not taking space

I want my div .valorCard-content to take up space and stop sitting on top of the second section. I want it to continue with a portion on top of the image as an overlay, but I don't want it to cover the second section. How do I take up space and the second section is positioned at the bottom, not being covered by the div .valorCard-content?
#valorContent {
padding: 0;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.valorCard {
padding: 0 24px;
position: absolute;
top: 370px;
}
.valorCard-content {
border: 2px solid green;
background-color: white;
}
<section class="valor py-5 mt-4">
<div class="container pt-5" id="valorContent">
<div class="valorImagem">
<img class="img-fluid" src="https://source.unsplash.com/user/c_v_r/414x421">
</div>
<div class="valorCard text-center">
<div class="valorCard-content py-5 px-4">
<h2 class="valor-titulo mx-4">
Lorem Ipsum
</h2>
<hr>
<div class="valor-lista">
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="second">
<div>
<div>
<div>
<div>
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="col-lg-5 cardbox cardbox-dep">
<div class="p-4 pt-5 mx-2">
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
</div>
</div>
</section>
It's generally best to avoid absolute dimensional values in CSS. Instead, use percentages or other relative values. Here you could also do something like calc(100% + 10px) to give a specific top margin.
A better solution might be to nest the elements according to their visual location. If you want an element to overlay another, it should really be that element's child. Of course, you may want a document structure as you have it now for proper text flow.
Protip: Use border rather than rules for visual lines. It keeps your markup cleaner and gives more flexibility. If you're using Bootstrap, use the classes provided.
#valorContent {
padding: 0;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.valorCard {
padding: 0 24px;
position: absolute;
top: 100%;
/* <--------------------------- HERE */
}
.valorCard-content {
border: 2px solid green;
background-color: white;
}
.border-bottom {
border-bottom: 1px solid #ddd;
}
<section class="valor py-5 mt-4">
<div class="container pt-5" id="valorContent">
<div class="valorImagem">
<img class="img-fluid" src="https://via.placeholder.com/414x421">
</div>
<div class="valorCard text-center">
<div class="valorCard-content py-5 px-4">
<h2 class="valor-titulo mx-4 mb-2 border-bottom">
Lorem Ipsum
</h2>
<div class="valor-lista">
<div class="item border-bottom">
<h4 class="mx-4">Test</h4>
</div>
<div class="item border-bottom">
<h4 class="mx-4">Test</h4>
</div>
<div class="item border-bottom">
<h4 class="mx-4">Test</h4>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="second">
<div>
<div>
<div>
<div>
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="col-lg-5 cardbox cardbox-dep">
<div class="p-4 pt-5 mx-2">
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
</div>
</div>
</section>
Update as the original answer did not address the issue anymore after OP redacted the question.
To solve the issue now:
reenable .valorCard { position: absolute; top: 370px } (if you disabled it).
add #valorCard-content { margin-bottom: 250px } to move the .second section down from under #valorCard-content (or any value that fits your needs).
#valorContent {
padding: 0;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-bottom: 250px;
}
.valorCard {
padding: 0 24px;
position: absolute;
top: 370px;
}
.valorCard-content {
border: 2px solid green;
background-color: white;
}
<section class="valor py-5 mt-4">
<div class="container pt-5" id="valorContent">
<div class="valorImagem">
<img class="img-fluid" src="https://source.unsplash.com/user/c_v_r/414x421">
</div>
<div class="valorCard text-center">
<div class="valorCard-content py-5 px-4">
<h2 class="valor-titulo mx-4">
Lorem Ipsum
</h2>
<hr>
<div class="valor-lista">
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
</div>
</div>
</div>
</div>
<!-- </div> -->
</section>
<section class="second">
<div>
<div>
<div>
<div>
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="col-lg-5 cardbox cardbox-dep">
<div class="p-4 pt-5 mx-2">
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
</div>
</div>
</section>

Position div on top of another

I'm trying to position my div .valorCard on top of my image. I want the div to have a piece of it on top of the end of the image, I'm using relative position on the image and absolute position on the div and a value on the bottom for that. But the div is covering my second section and I don't want that to happen. Can someone help me? I can't use absolute position in my second section because it ruins the style of it.
#valorContent {
padding: 0;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
}
.valorCard {
padding: 0 24px;
position: absolute;
bottom: -190px;
width: 150px;
}
.valorCard-content {
border: 2px solid green;
background-color: grey;
}
<section class="valor py-5 mt-4">
<div class="container pt-5" id="valorContent">
<div class="valorImagem">
<img class="img-fluid" src="https://source.unsplash.com/user/c_v_r/414x421">
</div>
<div class="valorCard text-center">
<div class="valorCard-content py-5 px-4">
<h2 class="valor-titulo mx-4">
Lorem Ipsum
</h2>
<hr>
<div class="valor-lista">
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="second">
<div>
<div>
<div>
<div>
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="col-lg-5 cardbox cardbox-dep">
<div class="p-4 pt-5 mx-2">
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
</div>
</div>
</section>
As I unserstand your explanation I thing this is the behavior that you desire.
Most in common. You already have used the flexbox with a column whih is nice.
If you would like to rearragne the elements inside the flex container there is no need to use the position: absolute. You have to just use the order: NUMBER property to order the elements inside the flex.
#valorContent {
padding: 0;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
}
.valorCard {
padding: 0 24px;
bottom: -190px;
width: 60%;
order: 0;
}
.valorImagem {
order: 1;
}
.valorCard-content {
border: 2px solid green;
background-color: grey;
}
<section class="valor py-5 mt-4">
<div class="container pt-5" id="valorContent">
<div class="valorImagem">
<img class="img-fluid" src="https://source.unsplash.com/user/c_v_r/414x421">
</div>
<div class="valorCard text-center">
<div class="valorCard-content py-5 px-4">
<h2 class="valor-titulo mx-4">
Lorem Ipsum
</h2>
<hr>
<div class="valor-lista">
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="second">
<div>
<div>
<div>
<div>
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="col-lg-5 cardbox cardbox-dep">
<div class="p-4 pt-5 mx-2">
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
</div>
</div>
</section>
If I understand your intentions correctly, you can add overflow: hidden; to the css for #valorContent to hide the overflowing part:
#valorContent {
padding: 0;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
overflow: hidden;
}
.valorCard {
padding: 0 24px;
position: absolute;
bottom: -190px;
width: 150px;
}
.valorCard-content {
border: 2px solid green;
background-color: grey;
}
<section class="valor py-5 mt-4">
<div class="container pt-5" id="valorContent">
<div class="valorImagem">
<img class="img-fluid" src="https://source.unsplash.com/user/c_v_r/414x421">
</div>
<div class="valorCard text-center">
<div class="valorCard-content py-5 px-4">
<h2 class="valor-titulo mx-4">
Lorem Ipsum
</h2>
<hr>
<div class="valor-lista">
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
<div class="item ">
<h4 class="mx-4">Test</h4>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="second">
<div>
<div>
<div>
<div>
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="col-lg-5 cardbox cardbox-dep">
<div class="p-4 pt-5 mx-2">
<p class="depoimento-txt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
</div>
</div>
</section>

Expanding a div with content without moving elements below it

I have an element on the page which, when it is hovered over, expands and reveals some previously hidden text within it. The problem is that when the element expands, it moves other content below it. I tried to use position:absolute, but it has not achieved the desired effect.
.col {
padding: 20px;
}
.col:hover {
background-color: lightgray;
}
.revealOnHover {
display: none;
/*position: absolute;*/
}
#block1:hover .revealOnHover,
#block2:hover .revealOnHover {
display: block;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
<div class="container">
<div class="row">
<div class="col" id="block1">
<img src="https://picsum.photos/100/100?random=1">
<p><b>Lorem ipsum dolor sit amet</b></p>
<i class="fas fa-caret-down" style="color: red;"></i>
<p class="revealOnHover">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="col" id="block2">
<img src="https://picsum.photos/100/100?random=1">
<p><b>Excepteur sint occaecat cupidatat non proident</b></p>
<i class="fas fa-caret-down" style="color: red;"></i>
<p class="revealOnHover">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
<p> </p>
<div style="text-align: center;">
<button type="button" class="btn btn-secondary" style="font-weight: bold; margin: 0 auto; margin-right: 2rem; color: #FFF">Click here</button>
<button type="button" class="btn btn-secondary" style="font-weight: bold; margin: 0 auto; margin-right: 2rem; color: #FFF">Click here</button>
</div>
</div>
My Code: https://codepen.io/eren5897/pen/GRqgOyd
You're not far off actually. position:absolute is the way to go, but you need a few additional styles to make it work, mainly in order to correctly position it and make it share the background color of its parent.
.col {
padding: 20px;
}
.col:hover {
background-color: lightgray;
}
.revealOnHover {
display: none;
position: absolute;
left: 0;
right: 0;
padding: 10px;
background: inherit;
}
#block1:hover .revealOnHover,
#block2:hover .revealOnHover {
display: block;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
<div class="container">
<div class="row">
<div class="col" id="block1">
<img src="https://picsum.photos/100/100?random=1">
<p><b>Lorem ipsum dolor sit amet</b></p>
<i class="fas fa-caret-down" style="color: red;"></i>
<p class="revealOnHover">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="col" id="block2">
<img src="https://picsum.photos/100/100?random=1">
<p><b>Excepteur sint occaecat cupidatat non proident</b></p>
<i class="fas fa-caret-down" style="color: red;"></i>
<p class="revealOnHover">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
<p> </p>
<div style="text-align: center;">
<button type="button" class="btn btn-secondary" style="font-weight: bold; margin: 0 auto; margin-right: 2rem; color: #FFF">Click here</button>
<button type="button" class="btn btn-secondary" style="font-weight: bold; margin: 0 auto; margin-right: 2rem; color: #FFF">Click here</button>
</div>
</div>
Add min-height to your row class
Your class becomes
.row {
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
min-height: 317PX;}
How about adding
.row {
min-height: 20rem
}
This makes sure that they don't move when the divs are being expanded.

.child-div overflows .parent-div

guys!
I'm making an own portfolio website. The idea is to make full height pages. So regarding this, I got 2 questions.
How can I make .child-div not larger than its .parent-div?
How can I make p-elements height not larger than its .child-div?
Thinking that there is some (maybe the same) solution to both problems.
Overflow is not an option, because it just hide the rest of element.
I tried to set .parent as display: table and .child as display: table-cell but I didn't succeed.
UPD: Also tried to make an table-row div between .parent and. child width width: 100% and height: 33%. Unfortunately without expected result..
Here is the example how it should look like, but .child overflows the .parent.
html {
height: 100%;
}
body {
height: 100%;
max-width: 960px;
margin: 15px auto;
}
.parent {
height: 100%;
border: 1px solid red;
}
.child-30 {
min-height: calc(100%/3);
width: 27%;
margin: 10px;
border: 1px solid green;
}
.child-70 {
min-height: calc(100%/3);
width: 67%;
margin: 10px;
border: 1px solid green;
}
.left {
float: left;
}
.right {
float: right;
}
#media only screen and (max-width: 750px) {
.child-30, .child-70 {float: left; width: 100%;}
}
<div class="parent">
<div class="child-30 left"></div>
<div class="child-70 right"></div>
<div class="child-70 left"></div>
<div class="child-30 right"></div>
<div class="child-30 left"></div>
<div class="child-70 right"></div>
</div>
And here is the link how it should look like with paragraphs
Same problem here
You assign a relative min-height size to the container to each element.
If you're sure you'll have 3 rows of blocks, you can use the min-height with just a small fix: min-height: calc(100% / 3 - 22px)
Why -22 ?
- 10 for each margin (top and bottom)
- 1 for each border (top and bottom) = 22
This is a problem at resize because you will have 6 rows of blocks with 100%/3 (which is 200% instead of 100%). So you need to do a min-height: calc (100% / 6 - 22px) in order to get 100% of the total size of the blocks.
Find bellow the modified code with the Kamil Pikula suggestions for the width.
BUT, if the size of your blocks are dynamic and you do not want to use overflow or ellypsis, it will not work with min-height. You'll have to use dynamic height and make line breaks for each line with a system like boostrap clearfix.
html {
height: 100%;
}
body {
height: 100%;
max-width: 960px;
margin: 15px auto;
}
.parent {
height: 100%;
border: 1px solid red;
}
.child-30 {
height: auto;
min-height: calc(100%/3 - 22px);
width: 27%;
margin: 10px;
border: 1px solid green;
}
.child-70 {
min-height: calc(100%/3 - 22px);
width: 67%;
margin: 10px;
border: 1px solid green;
}
.left {
float: left;
}
.right {
float: right;
}
#media only screen and (max-width: 750px) {
.child-30, .child-70 {
float: left;
width: calc(100% - 22px);
min-height: calc(100%/6 - 22px);
}
}
<div class="parent">
<div class="child-30 left"></div>
<div class="child-70 right"></div>
<div class="child-70 left"></div>
<div class="child-30 right"></div>
<div class="child-30 left"></div>
<div class="child-70 right"></div>
</div>
I have an answer to the first question:
#media only screen and (max-width: 750px) {
.child-30, .child-70 {float: left; width: calc(100% - 20px);}
}
Why width: calc(100% - 20px)? Because you use margin for .child-30 and .child-70 (margin: 10px is margin-top, margin-right, margin-bottom, margin-left = 10px and on width's summed margin-right and margin-left -> so 20 pixels.
Check this out, although it is better if it is full page.
https://jsfiddle.net/indefinite/g7aqvkoy/33/
I removed height:100% in your .parent
and added
.parent::after{
content: "";
clear: both;
display: table;
}
html {
height: 100%;
padding:10px;
}
body {
height: 100%;
max-width: 960px;
margin: 15px auto;
padding:10px;
}
.parent {
border: 1px solid red;
}
.child-30 {
min-height: calc(100%/3);
width: 27%;
margin: 10px;
border: 1px solid green;
}
.child-70 {
min-height: calc(100%/3);
width: 67%;
margin: 10px;
border: 1px solid green;
}
.left {
float: left;
}
.right {
float: right;
}
.parent::after{
content: "";
clear: both;
display: table;
}
#media only screen and (max-width: 750px) {
.parent{
display:flex;
flex-direction:column;
}
.child-30 {
width: 97%;
}
.child-70{
width:97%;
}
.parent::after{
content: "";
clear: both;
display: table;
}
}
<div class="parent clearfix">
<div class="child-30 left">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
<div class="child-70 right">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
<div class="child-70 left">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
<div class="child-30 right">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
<div class="child-30 left">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
<div class="child-70 right">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<br/><br/>

I need help placing 3 div's next to each other with a text hover

I am trying to place 3 images next together in a div. To add to this complication is that I need to hid the image and reveal text when the mouse hovers over the image.
Here is my HTML code:
<div class="TopRow">
<div class="TP">
<div class="TitleM">
TP
</div>
<div class="showcase">
<img src="image" alt="TPM"/>
<p >Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. >> Shop </p>
</div>
</div>
<div class="SF">
<div class="TitleM">
Stearns & Foster
</div>
<div class="showcase">
<img src="image" alt="TPM"/>
<p >Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. >> Shop </p>
</div>
</div>
<div class="VS">
<div class="TM">
VS
</div>
<div class="showcase">
<img src="image" alt="TPM"/>
<p >Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. >> Shop </p>
</div>
</div>
Here is my CSS
<style type="text/css">
div.showcase {height: 241px; width: 300px; border: solid 1px #939598;}
div.showcase p {display: none;}
div.showcase:hover img {display: none;}
div.showcase:hover p {display: block;}
}
.TopRow {
height: auto;
width: 95%;
margin-right: auto;
margin-bottom: 10px;
margin-left: auto;
}
.TP {
Float:left;
height: auto;
width: 33%;
.V3 {
margin:0;
height: auto;
width: 33%;
.SF {
Float:right;
height: auto;
width: 33%;
}
.TM {
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 125%;
background-color: #dce1e9;
text-align: left;
margin-bottom: 3px;
padding-left:0px;
padding-top:5px;
padding-bottom:5px;
height: auto;
width: 100%;
border: solid 1px #939598;
text-indent: 5px;
}
I know my issue is in the set size in showcase div, however I can not get things to line up correctly. Any help would be appreciated.
I've attempted to solve your problem in this fiddle: Click me for Fiddle
I've also tried to clean your code up a bit as there were quite a few errors.
HTML
<div class="TopRow">
<div class="TP">
<div class="TitleM">
TP
</div>
<div class="showcase">
<img src="http://osric.com/8ball/images/eight-ball.png" alt="TPM"/>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. >> Shop </p>
</div>
</div>
<div class="SF">
<div class="TitleM">
Stearns & Foster
</div>
<div class="showcase">
<img src="http://osric.com/8ball/images/eight-ball.png" alt="TPM"/>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. >> Shop </p>
</div>
</div>
<div class="VS">
<div class="TM">
VS
</div>
<div class="showcase">
<img src="http://osric.com/8ball/images/eight-ball.png" alt="TPM"/>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. >> Shop </p>
</div>
</div>
</div>
CSS
div.showcase {
border: solid 1px #939598;
}
div.showcase p {
visibility:hidden;
}
div.showcase:hover img {
visibility:hidden;
}
div.showcase:hover p {
visibility: visible;
}
body {
margin:0;
}
.TopRow {
width: 99%;
margin-bottom: 10px;
}
.TP {
width:33%;
display:inline-block;
}
.VS {
width:33%;
display:inline-block;
}
.SF {
width: 33%;
display:inline-block;
}