简体   繁体   English

浮点数:向左移动,高度百分比

[英]Float:left with % height

I'm currently trying to do this. 我目前正在尝试这样做。

在此处输入图片说明

This is the code I got so far, 这是我到目前为止得到的代码,

Html HTML

<a class="home" href="home.php">
    <i id="icon" class="fa fa-home"></i>
    <p id="tag">Home</p>
</a>

Css for .home CSS for .home

width: 25%;
height: 25%;
overflow: hidden;
float: left;
background: #ea7b7b;
color: #fff;    
text-decoration: none;

And the height:25%; 高度:25%; does not work. 不起作用。 I found some fixes like adding position:absolute; 我发现了一些修复方法,例如添加position:absolute; but that messes up everything when resizing. 但这会在调整大小时弄乱所有内容。 I'm trying to find a work around to this and help would be much appreciated! 我正在尝试解决此问题,我们将不胜感激!

Try putting the elements inside a container div with an explicit height. 尝试将元素放入具有明确高度的容器div中。

<div class="header"></div>
<div class="container">
        <a class="home" href="home.php">
            <i id="icon" class="fa fa-home"></i>
            <p id="tag">Home</p>
        </a>
        <a class="contact" href="contact.php">
            <i id="icon" class="fa fa-home"></i>
            <p id="tag">Contact</p>
        </a>
</div>
<div class="footer"></div>

CSS CSS

.header, .footer
{
    height: 50px;
    background: black;
}

.home 
{    
    background: #ea7b7b;    
}

.container > a 
{
    width: 25%;
    height: 50%;
    overflow: hidden;
    float: left;
    color: #fff;
    text-decoration: none;        
}

.container 
{
     height: 600px;
     width: 100%;
}

Sorry I'm a bit late but I made this FIDDLE 对不起,我来晚了,但我做了这个FIDDLE

Hope it can help you, here is the code: 希望它能对您有所帮助,下面是代码:

HTML: HTML:

<div id="top"></div>
<div id="content">
    <div class="box"> 
        <a class="home" href="home.php">
            <i id="icon" class="fa fa-home"></i>
            <p id="tag">Home</p>
        </a>
    </div>
    <div class="box"></div>
    ...
</div>
<div id="bottom"></div>

CSS : CSS:

html, body {
    width:100%;
    height:100%;
    margin:0;
    padding:0;
}
#top, #bottom {
    position:absolute;
    height:80px;
    width:100%;
    background:grey;
    left:0;
}
#top {
    top:0;
}
#bottom {
    bottom:0;
}
#content {
    position:absolute;
    top:80px;
    left:0;
    right:0;
    bottom:80px;
}
.box {
    box-sizing:border-box;
    border:1px solid red;
    float:left;
    width:25%;
    height:50%;
}
.home {
    width:100%;
    height:100%;
    margin:0;
    padding:0;
    overflow: hidden;
    float: left;
    background: #ea7b7b;
    color: #fff;
    text-decoration: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM