Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
130 views
in Technique[技术] by (71.8m points)

javascript - How to display two elements on the same line?

Here I want to display this slide show and the video inline. I've tried thousand different examples but they couldn't solve my problem. Any helpful suggestion will be an immense help as i'm a beginner to web developing. Thank You!

var myIndex = 0;

carousel();

function carousel() {
  var i;
  var x = document.getElementsByClassName("mySlides");

  for (i = 0; i < x.length; i++) {
    x[i].style.display = "none";
  }

  myIndex++;

  if (myIndex > x.length) {
    myIndex = 1
  }

  x[myIndex - 1].style.display = "block";

  setTimeout(carousel, 4000);
}
<div class="slideshow" style="max-width: 600px" style="display: inline" style="float: right">

  <div>
    <img class="mySlides" src="canada.jpg" style="width: 100%" alt="canada">
    <img class="mySlides" src="myanmar.jpg" style="width: 100%" alt="myanmar">
    <img class="mySlides" src="china.jpg" style="width: 100%" alt="china">
    <img class="mySlides" src="italy.jpg" style="width: 100%" alt="italy">
  </div>

  <div>
    <video width="400" controls style="float: right" style="display: inline" poster="http://via.placeholder.com/320x280?text=video">
<source src="Intro.mp4" type = "video/mp4">
</video>
  </div>

</div>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Nowadays you can use flexboxes to put two elements side-by-side. CSS-tricks has a very thorough guide on the topic, so I won't bre you with the details.

In your particular case, use something like:

.slideshow {
  display: flex;
  justify-content: space-between;
  // no float and similar here
}

.slideshow > div {
  width: 50%;
}

You may need to prefix the flex and justify-content for better cross-browser support, and you may need to add flex: 1 for IE 10 support.

You could also clean the code up a little. You don't want to use whitespace around the = sign in the attributes, and you don't need to specify the style attribute multiple times. One is enough, with semicolon-separated rules.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...