用另一个元素推送元素

时间:2018-05-15 07:59:40

标签: html css

我有一个header,其下面是一个包含两张中等大图片的容器,当我调整页面时出现问题 {{1} }往往在我的header下面,我希望它做什么button-container推动header向下

jsfiddle: https://jsfiddle.net/Lw0pb53d/8/

通过更改button-container - > button-containerstransform:translate(-50%, -50%)有点设法让它发挥作用但是在调整transform:translate(-50%, 0%)元素的大小后,太多了通过填充边距,我把它放在中心但是然后在纵向模式下容器再次超过标题



button-container

/*Header*/

h1 {
  text-transform: uppercase;
  width: 100%;
  font-size: 9vw;
  text-align: center;
  margin-top: 4vh;
  border: 1px solid #000;
}


/*Containers*/

#button-container {
  padding: 0;
  margin: 0;
  list-style: none;
  display: flex;
  -webkit-flex-flow: row wrap;
  justify-content: space-around;
  margin-top: 35vh;
  margin-left: 50vw;
  transform: translate(-50%, -50%);
  width: 90vw;
  /*width: 90vw;
    	height: 60vh;*/
  align-items: baseline;
  background: linear-gradient(to right, transparent 0%, #fff 33%, #fff 66%, transparent 100%);
  border: 1px solid #000;
}

#button-container li {
  position: relative;
  display: inline-block;
  cursor: pointer;
}


/* Text block */

#button-container .html-text-block,
.cs-text-block {
  position: absolute;
  bottom: 4px;
  width: 100%;
  height: 30%;
  box-sizing: border-box;
  background-color: #fff;
  padding-left: 5px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
  transition: box-shadow 0.5s cubic-bezier(.25, .8, .25, 1), transform 0.5s cubic-bezier(.25, .8, .25, 1);
}


/* Logo Sizing*/

#button-container .htmllogo,
#button-container .csharplogo {
  width: 440px;
}




2 个答案:

答案 0 :(得分:0)

你的标题是一个h1元素(在语义上不正确:h1 - > h6应该用于显示标题元素,即标题),因此它具有display属性默认设置为inline

将其包裹在div中:它的display: block默认属性会将ul向下推

答案 1 :(得分:0)

通过在<div id="flex-container"> // THE CONTAINER // <ul id="button-container"> <li> <a id="html-modal-button"> <img class="htmllogo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/HTML5_Badge.svg/600px-HTML5_Badge.svg.png"> <div class="html-text-block"> <h2>HTML</h2> <p>My web projects</p> </div> </a> </li> <li> <a id="cs-modal-button"> <img class="csharplogo" src="https://camo.githubusercontent.com/0617f4657fef12e8d16db45b8d73def73144b09f/68747470733a2f2f646576656c6f7065722e6665646f726170726f6a6563742e6f72672f7374617469632f6c6f676f2f6373686172702e706e67"> <div class="cs-text-block"> <h2>C#</h2> <p>My windows projects</p> </div> </a> </li> </ul> </div>

中插入内容,可以解决此问题

所以:

<强> HTML:

#flex-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

<强> CSS

margin-top: 35vh;
margin-left: 50vw;
transform: translate(-50%, -50%);

并删除:

var aeqr;
var qrurl = new QRCode(document.getElementById("qrcode"), {
        width : 140,
        height : 140
    });
var qrdest = "text";
aeqr = document.getElementById("qrjs"); //getting ID from qrcode.js

aeqr.onload = function() {
 qrurl.drawImage(aeqr, 0, 0, 120, 120);
 var qrdataURL = qrcanvas.toDataURL();
}

qrurl.makeCode(qrdest);

jsfiddle: https://jsfiddle.net/EricTalv/Lw0pb53d/16/