javascript - 需要为小漫画制作网格

标签 javascript html css

我尝试为小漫画制作图像网格。我想制作 2 列和 3 行。但是所有的 div 都在同一个地方。我试过 display: flex 但它不起作用。而且我想让它响应,但我只能制作固定位置的图像。真的不知道如何在网格和响应中制作它。请寻求帮助。

const menu = document.querySelector('#toggle');  
const menuItems = document.querySelector('#overlay');  
const menuContainer = document.querySelector('.menu-container');  
const menuIcon = document.querySelector('i');  

function toggleMenu(e) {
    menuItems.classList.toggle('open');
    menuContainer.classList.toggle('full-menu');
    menuIcon.classList.toggle('fa-bars');
    menuIcon.classList.add('fa-times');
    e.preventDefault();
}

menu.addEventListener('click', toggleMenu, false);
@import url(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css);
@import url("https://fonts.googleapis.com/css?family=Titan+One");
body {
  background: linear-gradient(45deg, #7b00e0, #ff006a);
  margin: 0;
  height: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.container {
  width: 100%;
  height: 100vh;
  margin: 0 auto;
  overflow: hidden;
}


.menu-container {
  background-color: #E59617;
  border-radius: 100%;
  color: white;
  cursor: pointer;
  position: absolute;
  width: 250px;
  height: 250px;
  left: -120px;
  top: -120px;
  transition: all 0.3s;
}
.menu-container.full-menu {
  border-radius: 0;
  padding: 0 !important;
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  transition: all 0.3s;
}

.full-menu .menu {
  top: 40px;
  left: 40px;
}

.menu {
  color: white;
  font-size: 2em;
  position: absolute;
  top: 160px;
  left: 160px;
  z-index: 100;
  transition: all 0.3s;
}
.menu i {
  opacity: 0.7;
  transform: scale(1);
  transition: all 0.3s;
}
.menu i:hover {
  opacity: 1;
  transform: scale(1.2);
  transition: all 0.3s;
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 0%;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
}
.overlay.open {
  opacity: .9;
  visibility: visible;
  height: 100%;
  
}
.overlay.open li {
  animation: fadeInRight .5s ease forwards;
  animation-delay: .35s;
  
}
.overlay.open li:nth-of-type(2) {
  animation-delay: .4s;
}
.overlay.open li:nth-of-type(3) {
  animation-delay: .45s;
}
.overlay.open li:nth-of-type(4) {
  animation-delay: .50s;
}
.overlay nav {
  font-size: 3.2em;
  font-family: "Titan One", san-serif;
  position: relative;
  height: 70%;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 400;
  text-align: center;
}
.overlay ul {
  list-style: none;
  padding: 0;
  margin: 0 auto;
  display: inline-block;
  position: relative;
  height: 100%;
}
.overlay ul li {
  display: block;
  height: 25%;
  height: calc(100% / 4);
  min-height: 50px;
  position: relative;
  opacity: 0;
}
.overlay ul li a {
  display: block;
  position: relative;
  color: #fff;
  text-decoration: none;
  overflow: hidden;
  opacity: 0.7;
  transform: scale(1);
  transition: all 0.3s;
}
.overlay ul li a:hover, .overlay ul li a:focus, .overlay ul li a:active {
  opacity: 1;
  transform: scale(1.2);
  transition: all 0.3s;
}

@keyframes fadeInRight {
  0% {
    opacity: 0;
    left: 20%;
  }
  100% {
    opacity: 1;
    left: 0;
  }
}
h1 {
  font-size: 5em;
  font-family: "Titan One", san-serif;
  background-color: rgba(255, 0, 106, 0.4);
  border-radius: 100%;
  box-shadow: 0 0 2em 1em rgba(255, 0, 106, 0.4);
  color: white;
  margin: 30vh auto;
  position: relative;
  text-align: center;
  text-shadow: 0 8px 0 rgba(123, 0, 224, 0.4);
  transform: rotate(-12deg);
  width: 800px;
  height: auto;
  z-index: -1;
}
h1 span {
  color: #ffc901;
}

.blob {
  animation: blobby 4s infinite;
}

.blob2 {
  animation: blobby2 6s infinite;
}

@keyframes blobby {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes blobby2 {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}
svg {
  position: absolute;
  top: 0;
}

#svg-right {
  display: block;
  fill: #7b00e0;
  opacity: 0.5;
  right: 0;
  width: 60%;
  z-index: -10;
}

#svg-left {
  fill: #ff006a;
  margin: 0;
  width: 60%;
  z-index: -10;
}

@media all and (max-width: 980px) {
  h1 {
    font-size: 3em;
    font-family: "Titan One", san-serif;
  }
}
@media all and (max-width: 480px) {
  h1 {
    font-size: 2em;
    font-family: "Titan One", san-serif;
  }
  .overlay li {
    font-size: 0.5em;
  }
}

/*komix*/

.komix {
  background-color: #ffc901;
  width: 60%;
  height: 6000px;
  margin: 0 auto;
  position: absolute;
  top: 30%;
  left: 20%;
  vertical-align: middle;
}
.komix > div {
  width: 300px;
  height: 20px;
  background-color: #000;
  display: flex;
}
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Kajberšikana</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="css/style.css">  
</head>
<body>
<div class="container">
<div class="menu-container" id="toggle">
<a href="#" class="menu" ><i class="fa fa-bars" aria-hidden="true"></i></a>
</div>
</div>
  <div class="overlay" id="overlay">
  <nav class="overlay-menu">
    <ul>
      <li><a href="index.html">Domov</a></li>
      <li><a href="deti.html">Pre deti</a></li>
      <li><a href="#">Pre dospelých</a></li>
      <li><a href="#">Kontakt</a></li>
    </ul>
  </nav>
</div>
<div class="komix">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>

</body>

</html>

最佳答案

使用 flexbox 是正确的解决方案,但它比简单地添加 display:flex... 更复杂......

#container{
	/* width so things wrap. Change for responsive */
	width: 600px;
	/* flexbox stuff */
	display:flex;
	flex-wrap: wrap;
	justify-content: space-between;
}

.item {
	height: 200px;
	margin: 10px;
	background: #f7352d;
	/* how much space each takes up */
	flex-basis: calc(33.33% - 20px);
}
<div id="container">
	<div class="item"></div>
	<div class="item"></div>
	<div class="item"></div>
	<div class="item"></div>
	<div class="item"></div>
	<div class="item"></div>
</div>

如果您将图像添加到“元素”div,请确保将它们设置为 width: 100%,这样它们也可以缩放。

关于javascript - 需要为小漫画制作网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53120809/

相关文章:

html - 显示页面的背景颜色并将文本居中对齐

css - 需要帮助制作一个 CSS 径向渐变,它无缝地流过 2 个高度或宽度不同的元素

javascript - 将插入符号/光标位置设置到 contenteditable div 的末尾

html - 使用 flexbox 如何在 div 下居中文本

javascript - 获取多个元素: only return the last one

javascript - 我如何在 html 中使用动画向下/向上滚动页面

javascript - 对表格进行排序但使一列不移动

html - 根据上面的文字对齐页面上的按钮

javascript - 需要获取reactjs中非受控组件中的多个表单元素

javascript - 为什么这个函数不能多次保存信息?