1

I'm trying to create a simple text slideshow and for that I need to place the elements inside the parent element next to each other so only one child element is in display at a time.

The issue that I have is that both the parent and child elements are 100% width and I NEED to keep it that way due to my design etc.

A working FIDDLE

And this is what I have for the child elements:

.some {
    width:100%;
    height:450px;
    display: inline-block;
}

Could someone please advise on this issue?

.some {
  width: 100%;
  height: 450px;
  display: inline-block;
}
<div align="center" style="width:100% white-space:nowrap; height:500px; overflow:hidden;" id="feedTxt">


  <div class="some">
    <h1>title 1</h1>
    <br>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </div>



  <div class="some">
    <h1>title 1</h1>
    <br>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </div>


  <div class="some">
    <h1>title 1</h1>
    <br>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </div>


  <div class="some">
    <h1>title 1</h1>
    <br>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </div>


</div>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Jackson
  • 800
  • 16
  • 36

3 Answers3

2

Learn about CSS flexbox.

For the alignment you want, this is all the CSS you need:

#feedTxt {
    display: flex;
    overflow-x: scroll; /* for the demo */
}

.some {
    flex: 0 0 100%;
    height: 450px;
}

Revised Fiddle


To learn more about flexbox visit:


Browser support:

Flexbox is supported by all major browsers, except IE 8 & 9. Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes. For a quick way to add prefixes, use Autoprefixer. More details in this answer.

Community
  • 1
  • 1
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
1

You could try making the child elements absolutely positioned, and just set "display:none;" on the ones that you don't want visible. This method would work in older browsers too:

.some{
width:100%;
height:100%;
position:absolute;
}    
<div style="width:100%;white-space:nowrap;height:500px;overflow:hidden;" id="feedTxt">
<div class="some" style="height:100%;background-color:pink;">
Box 1
</div>
<div class="some" style="height:100%;background-color:greenyellow;">
Box 2
</div>
<div class="some" style="height:100%;background-color:deepskyblue;">
Box 3
</div>
</div>
user3163495
  • 2,425
  • 2
  • 26
  • 43
  • this is good but the issue is that I wont be able to make a slide show out of the contents. I can show/hide them or fadein/fadeout but wont be able to slide them in/out.... – Jackson Jul 21 '16 at 19:32
0
$(document).ready(function(){    
var slideCount = 0;
start();

function start(){    
var i;  
var x = document.getElementsByClassName(".some");  
for(i = 0; i < x.length; i++){  
x[i].style.display = "none";  
}  

slideCount++;  
if(slideCount > x.length) {slideCount = 1}  
x[slideCount-1].style.display = "block";  
$(x[slideCount-1]).effect("slide", {direction:"left"});  
setTimeout(start, 5000);    
};   
});


.some{    
      display:none;    
      margin:auto;    
      }   

This is using JavaScript / jQueryUI, this will slide each div with the same class in a timed sequence.