CSS绝对定位和调整窗口大小

时间:2016-02-06 17:25:49

标签: html css css-position

首先请允许我说,我不做很多前端设计所以请原谅我所有的内联代码......

我已经构建了这些复选框,以便在单击时包含图像。我知道它不在父类中,但我对此如何前进感到有点困惑。因为它没有父类,所以它只是查找整个网页,因为它是我认为的父类。

我觉得相当简单;当我最小化我的屏幕时,我的标签定位将自己从盒子中移除并漂浮掉。我会附加屏幕截图以便更清晰。

我试图把它们中的一些放在div中但取得了一些成功,但我并不是百分之百确定这样做的正确方法,这就是我在这里的原因。我也尝试了一些相对定位。

<div class="interests">
<div class="subHeader">Interests:</div>

<label style="background-color: #000; color:#fff; width:160px; font-family: 'itc_avant_garde_gothic_ltbold';
    font-size: 18px !important;
    text-transform: uppercase;
    color: #FFF;
    padding-top: 20px;
    display: inline-block; z-index: 5; position:absolute; left: 465px; top: 1105px;"><div style="position:relative;left:10px; bottom: 8px;">SKATE</div></label>

<label style="background-color: #000; color:#fff; width:160px; font-family: 'itc_avant_garde_gothic_ltbold';
    font-size: 18px !important;
    text-transform: uppercase;
    color: #FFF;
    padding-top: 20px;
    display: inline-block; z-index: 5; position:absolute; left: 685px; top: 1105px;"><div style="position:relative;left:10px; bottom: 8px;">SURF</div></label>

<label style="background-color: #000; color:#fff; width:160px; font-family: 'itc_avant_garde_gothic_ltbold';
    font-size: 18px !important;
    text-transform: uppercase;
    color: #FFF;
    padding-top: 20px;
    display: inline-block; z-index: 5; position:absolute; left: 906px; top: 1105px;"><div style="position:relative;left:10px; bottom: 8px;">SNOW</div></label>

<label style="background-color: #000; color:#fff; width:160px; font-family: 'itc_avant_garde_gothic_ltbold';
    font-size: 18px !important;
    text-transform: uppercase;
    color: #FFF;
    padding-top: 20px;
    display: inline-block; z-index: 5; position:absolute; left: 465px; top: 1300px;"><div style="position:relative;left:10px; bottom: 8px;"> WOMEN</div></label>


<label style="background-color: #000; color:#fff; width:160px; font-family: 'itc_avant_garde_gothic_ltbold';
    font-size: 18px !important;
    text-transform: uppercase;
    color: #FFF;
    padding-top: 20px;
    display: inline-block; z-index: 5; position:absolute; left: 685px; top: 1300px;"><div style="position:relative;left:10px; bottom: 8px;"> MUSIC/ART </div></label>

<label style="position: relative; top: 90px;">
<input type="checkbox" name="CheckBox.A address.Sk" style="z-index: 1;position: relative; top:4px;">Skate<img src="https://stuff/Images/thumb.jpg" style="position: absolute;left: 0;bottom: 0;height: 185px;width: 205px;">
</label>
<input type="hidden" name="CheckBox.A address.Sk" value="off">


<label style="position: relative; left:140px; top: 90px;">
<input type="checkbox" name="CheckBox.A address.Su" style="z-index: 1;position: relative; top:4px;">Surf<img src="https://stuff/Images/thumb.jpg" style="position: absolute;left: 0;bottom: 0;height: 185px;width: 205px;">
</label>
<input type="hidden" name="CheckBox.A address.Su" value="off">


<label style="position: relative; left:290px; top: 90px;">
<input type="checkbox" name="CheckBox.A address.Sn" style="z-index: 1;position: relative; top:4px;">Snow<img src="https://stuff/Images/thumb.jpg" style="position: absolute;left: 0;bottom: 0;height: 185px;width:205px;">
</label>
<input type="hidden" name="CheckBox.A address.Sn" value="off">

<br><br><br><br><br><br><br><br><br><br><br><br>

<label style="position:relative; top: 60px;">
<input type="checkbox" name="CheckBox.A address.Wo" style="z-index: 1;position: relative; top:4px;">Women<img src="https://stuff/Images/thumb.jpg" style="position: absolute;left: 0;bottom: 0;height: 185px;width:205px;">
</label>
<input type="hidden" name="CheckBox.A address.Wo" value="off">


<label style="position:relative; left: 130px; top: 60px;">
<input type="checkbox" name="CheckBox.A address.Mu" style="z-index: 1;position: relative; top:4px;">Music<img src="https://stuff/Images/music_thumb.jpg" style="position: absolute;left: 0;bottom: 0;height: 185px;width:205px;">
</label><input type="hidden" name="CheckBox.A address.Mu " value="off"> 


<label><input type="checkbox" name="CheckBox.A address.Subscribe"></label>
<div style="position:relative; left: 50px; bottom: 33px;">Subscribe</div>
<input type="hidden" name="CheckBox.A address.Subscribe" value="off">


        <input type="submit" id="submit" value="Sign Up" style="width: 280px;
    height: 45px;
    display: block !important;
    outline-style: none !important;
    outline-width: 0px !important;
    color: #fff !important;
    font-weight: normal !important;
    font-family: 'itc_avant_garde_gothic_ltbold';
    text-transform: uppercase;
    text-decoration: none;
    text-align: center;
    border: 1px solid #434242;
    background-color: #434242;
    background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#434242), to(#2f2e2e));
    background-image: -webkit-linear-gradient(top, #434242, #2f2e2e);
    background-image: -moz-linear-gradient(top, #434242, #2f2e2e);
    background-image: -ms-linear-gradient(top, #434242, #2f2e2e);
    background-image: -o-linear-gradient(top, #434242, #2f2e2e);
    -moz-box-shadow: 0 0 1px #bbb;
    -webkit-box-shadow: 0 0 1px #bbb;
    box-shadow: 0 0 1px #bbb;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
    vertical-align: middle;
    padding: 10px 0;
    line-height: 1em;
    cursor: pointer;
    line-height: 18px;
    font-size: 18px;
    margin: 40px 0;">


</div>

非常感谢任何帮助。谢谢。屏幕截图如下。

当我最小化时,标签会浮起来:

Labels are floating off when i minimize

全屏时工作正常:

Works fine when full screen

2 个答案:

答案 0 :(得分:2)

我在另一个答案中评论了一些不良做法和谎言,所以我自己必须做一个快速的例子,这是用flexbox做的一种方法(这个问题有很多解决方案,这是一个如果您不必支持过时的浏览器,那就好了:

示例:https://jsfiddle.net/um6fm744/1/

CSS:

BitmapSource

HTML

* { box-sizing: border-box; margin: 0; padding: 0; }

.interests {
  display: flex;
  flex-wrap: wrap;
}
.sub-header {
  margin: 0 0 24px;
  width: 100%;
}

.interest { 
  align-items: flex-end;
  background-color: green;
  display: flex;
  margin: 0 12px 24px 0;
  min-height: 160px;
  width: 160px;
}

.interest-info {
  background-color: black;
  display: flex;
  justity-content: space-between;
  width: 100%;
}

.interest-checkbox {
  height: 30px;
  width: 30px;
}

.interest-label {
  color: white;
  font-family: sans-serif;
  flex: 1;
  height: 30px;
  line-height: 30px;
  margin-left: 12px;
}

答案 1 :(得分:0)

请不要使用内联样式。

我会更像这样解决它:http://codepen.io/anon/pen/VeEXEv

HTML:

var getScreenshotDataUrl = function(video, canvas, type) {
    type = type || "image/jpeg";
    var context = canvas.getContext("2d");
    var w = video.videoWidth;
    var h = video.videoHeight;
    canvas.width = w;
    canvas.height = h;
    context.fillRect(0, 0, w, h);
    context.drawImage(video, 0, 0, w, h);
    video.crossorigin = "anonymous";// makes no difference
    return canvas.toDataURL(type);
}

CSS:

<ul class="items">
  <li class="item1">
    <button class="add-button">+</button>
    <span class="description">box 1</span>
  </li>
  <li class="item2">
   <button class="add-button">+</button>
   <span class="description">box 2</span>
  </li>
  <li class="item3">
   <button class="add-button">+</button>
   <span class="description">box 3</span>
  </li>
  <li class="item2">
   <button class="add-button">+</button>
   <span class="description">box 2</span>
  </li>
  <li class="item3">
   <button class="add-button">+</button>
   <span class="description">box 3</span>
  </li>
  <li class="item1">
    <button class="add-button">+</button>
    <span class="description">box 1</span>
  </li>
</ul>