简体   繁体   English

在div的底部放置一个跨度(水平位移问题)

[英]Placing a span at bottom of div (Horizontal displacement issue)

I know the general rule of thumb is research before asking questions, and I'm looking at a lot if different sources. 我知道一般的经验法则是在提出问题之前先进行研究,如果资料来源不同,我会进行很多研究。 Not to much luck here. 这里运气不太好。

My end goal is to have the text centered and at the bottom of the div. 我的最终目标是使文本居中且位于div的底部。 Simple as that. 就那么简单。

But when I use the code given by other sources, it's not centered in the actual div. 但是,当我使用其他来源提供的代码时,它不在实际的div中。

HTML: HTML:

<div class="fbox" id="breast">
        <span class="title">Breast Procedures</span>
        <ul>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
        </ul>
<span class="read">View Descriptions</span>
    </div>
    <div class="fbox" id="facial">
        <span class="title">Facial Procedures</span>
        <ul>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
        </ul>
<span class="read">View Descriptions</span>
    </div>
    <div class="fbox" id="body">
        <span class="title">Body Procedures</span>
        <ul>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
        </ul>
<span class="read">View Descriptions</span>
    </div>
    <div class="fbox" id="surgery">
        <span class="title">Non-Surgical Procedures</span>
        <ul>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
        </ul>
<span class="read">View Descriptions</span>
    </div>

CSS: CSS:

.title{
    font-size:16px;
    margin:0 auto;
text-align:center;
font-weight:600;
}
.fbox{
width: 250px;
height: 300px;
background: rgb(250, 250, 250);
-moz-box-shadow:  0px 0px 5px 1px rgb(139, 139, 139);
-webkit-box-shadow:  0px 0px 5px 1px rgb(139, 139, 139);
box-shadow:  0px 0px 5px 1px rgb(139, 139, 139);
display:inline-block;
vertical-align:top;
text-align:center;
margin:0 auto;
position:relative;
}
.main-content ul li{
    list-style-type:none;
}
.main-content ul{
    margin:0 auto;
}
.read{
    height:40px;
    width:250px;
 position:absolute;
    bottom:0;
}

JSFiddle JSFiddle

All help is appreciated! 感谢所有帮助!

You were so close! 你好亲密!

SOLUTION: 解:

Replace: 更换:

.read {
  height: 40px;
  width: 250px;
  position: absolute;
  bottom: 0;
}

With: 带有:

.read {
  height: 40px;
  width: 100%;
  position: absolute;
  left: 0;
  bottom: 0;
}

CODE SNIPPET: 代码片段:

 .title { font-size: 16px; margin: 0 auto; text-align: center; font-weight: 600; } .fbox { width: 250px; height: 300px; background: rgb(250, 250, 250); -moz-box-shadow: 0px 0px 5px 1px rgb(139, 139, 139); -webkit-box-shadow: 0px 0px 5px 1px rgb(139, 139, 139); box-shadow: 0px 0px 5px 1px rgb(139, 139, 139); display: inline-block; vertical-align: top; text-align: center; margin: 0 auto; position: relative; } .main-content ul li { list-style-type: none; } .main-content ul { margin: 0 auto; } .read { height: 40px; width: 100%; position: absolute; left: 0; bottom: 0; } 
 <div class="fbox" id="breast"> <span class="title">Breast Procedures</span> <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> </ul> <span class="read">View Descriptions</span> </div> <div class="fbox" id="facial"> <span class="title">Facial Procedures</span> <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> </ul> <span class="read">View Descriptions</span> </div> <div class="fbox" id="body"> <span class="title">Body Procedures</span> <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> </ul> <span class="read">View Descriptions</span> </div> <div class="fbox" id="surgery"> <span class="title">Non-Surgical Procedures</span> <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> </ul> <span class="read">View Descriptions</span> </div> 


JSFiddle JSFiddle

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

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