简体   繁体   English

如何显示的子元素 <li> 在100%的高度?

[英]How to display child elements of <li> at 100% height?

I am having an issue trying to make a specific element inside my <li> tag to take up 100% of the <li> height. 我在尝试在我的<li>标记内制作特定元素以占用<li>高度的100%时遇到问题。 Specifically I want an icon I added with a border on its right to fill the entire height of the <li> element. 具体来说,我希望添加一个在其右侧带有边框的图标,以填充<li>元素的整个高度。 在此处输入图片说明

as you can see from the last item in the list, the border for the download icon does not take the entire height of its <li> element. 从列表的最后一项可以看到,下载图标的边框并未占据其<li>元素的整个高度。 How can I fix this? 我怎样才能解决这个问题?

My code: 我的代码:

    <ul>
        <li>طلب المشروع من قبل الجهة المستفيدة<div class="download"><a href="#" class="active"><i class="fa fa-download"></i></a></div></li>
        <li class="list_background">وجود قرار تخصيص موقع من قبل المجلس البلدي<div class="download"><a href="#" class="active"><i class="fa fa-download"></i></a></div></li>
        <li>بكتاب الامانة العامة لمجلس الوزراء رقم 344 - 3679 المؤرخ<div class="download"><a href="#" class="inactive"><i class="fa fa-download"></i></a></div></li>
        <li class="list_background">على مهندس المشروع التأكد من استيفاء ما     يلي حسب ما جاء بكتاب الأمانة العامة لمجلس الوزراء رقم 344-3679 
         المؤرخ (مرفق صورة من الكتاب المذكور) :
         <br>- استلام متطلبات المشروع معتمدة من قبل الجهة المستفيدة.
         <br>- إعداد كراسة طلب المشروع.
         <br>- الحصول على موافقة وزارة  المالية على اعتماد ميزانية المشروع.
         <br>- شهادة خلو الموقع من العوائق.<div class="download"><a href="#"   class="inactive"><i class="fa fa-download"></i></a></div></li>
    </ul>

CSS: CSS:

ul {
  padding: 0;
  margin: 0;
  list-style: none;
  width: 100%;
}
ul li {
  direction: rtl;
  text-align: right;
  padding: 0 1rem 0 0;
  margin: 0;
  font-size: 1.1rem;
  color: #8c97b2;
  font-weight: 400;
  border-bottom-style: solid;
  border-bottom-width: 1px;
  border-bottom-color: #dadfea;
  line-height: 54px;
  height: 100%;
}
ul li .download {
  height: 100%;
  float: left;
  border-right-style: solid;
  border-right-width: 1px;
  border-right-color: #dadfea;
  display: block;
}
ul li .download i {
  font-size: 22px;
  width: 54px;
  text-align: center;
  height: 100%;
}

To achieve that you have to use table structure which mean make the li tag act as table and content act as tabel-cell and icon act as another table cell. 要实现这一点,您必须使用表结构,这意味着要使li标签充当表,内容充当tabel-cell,而icon充当另一个表单元。

also add a container for the text and never let it flow on any container 还要为文本添加一个容器,并且永远不要让它在任何容器上流动

 ul { padding: 0; margin: 0; list-style: none; width: 100%; } ul li { direction: rtl; text-align: right; padding: 0 1rem 0 0; margin: 0; font-size: 1.1rem; color: #8c97b2; font-weight: 400; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #dadfea; line-height: 54px; height: 100%; display: table; width:100%; } ul li .download { height: 100%; float: left; border-right-style: solid; border-right-width: 1px; border-right-color: #dadfea; display: tablle-cell; } ul li p{ display:table-cell; } ul li .download i { font-size: 22px; width: 54px; text-align: center; height: 100%; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/> <ul> <li><p>طلب المشروع من قبل الجهة المستفيدة</p><div class="download"><a href="#" class="active"><i class="fa fa-download"></i></a></div></li> <li class="list_background"><p>وجود قرار تخصيص موقع من قبل المجلس البلدي</p><div class="download"><a href="#" class="active"><i class="fa fa-download"></i></a></div></li> <li><p>بكتاب الامانة العامة لمجلس الوزراء رقم 344 - 3679 المؤرخ</p><div class="download"><a href="#" class="inactive"><i class="fa fa-download"></i></a></div></li> <li class="list_background">على مهندس المشروع التأكد من استيفاء ما يلي حسب ما جاء بكتاب الأمانة العامة لمجلس الوزراء رقم 344-3679 المؤرخ (مرفق صورة من الكتاب المذكور) : <br>- استلام متطلبات المشروع معتمدة من قبل الجهة المستفيدة. <br>- إعداد كراسة طلب المشروع. <br>- الحصول على موافقة وزارة المالية على اعتماد ميزانية المشروع. <br>- شهادة خلو الموقع من العوائق.</p><div class="download"><a href="#" class="inactive"><i class="fa fa-download"></i></a></div></li> </ul> 

You now need to align icon vertically to acheive that we need to add sudo element just after your .download div to align the icon vertically 现在,您需要垂直对齐图标,以确保我们需要在.download div之后添加sudo元素以垂直对齐图标

ul li .download:after{
 content:"";
 vertical-align:middle;
 display:inline-block;
 height:100%;
}
ul li .download a{
 display: inline-block;
 vertical-middle: middle;
}

Check the result HERE 这里检查结果

and check this article for a guide to align elements vertically 并查看此文章以获取垂直对齐元素的指南

Hope everything working fine with you 希望一切顺利

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

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