简体   繁体   English

水平对齐一行中的所有HTML元素

[英]Align all HTML elements in One Line Horizontally

I have a question, I have align all elements in one line. 我有一个问题,我将所有元素对齐在一行中。

Actually it should look like this. 实际上,它应该看起来像这样。 在此处输入图片说明

I created this with the help of creating tables and adding each ProgressBar as Div ELements inside table cells. 我是在创建表并将每个ProgressBar作为Div ELements添加到表单元格的帮助下创建的。 For some reason, this is not working in IE 7. 由于某些原因,这在IE 7中不起作用。

So, I wanted to create the html using Div Elements alone without any tables. 因此,我想单独使用Div元素创建html,而不使用任何表。 Now it looks like this: 现在看起来像这样:

在此处输入图片说明

Can you please tell me what I am missing? 你能告诉我我在想什么吗?

Here is the CSS code: 这是CSS代码:

div.coverage-container {
  border: 1px solid rgba(0, 0, 0, 0.13);
  width:370px;
   height:30px;   
}  

div.progressbar-content{
width: 95px;    
text-align: center;
float:left; 
border: 1px solid rgba(0, 0, 0, 0.13);
 }


div.progressbar-maindiv {
background-color: #DAE2E3;
border-radius: 13px 13px 13px 13px;    
margin: 3px -9px 3px 114px;
padding: 3px;
width: 75px;
float:left;
 }


.progressbar-percentage {
background-color: #F23F54;
border-radius: 15px 15px 15px 15px;
height: 15px;
width: 80.00%;
 }

 .progressbar-chart-icon {       margin-right: 5px; float:right;       text-align: center;     }

Here is the HTML Code: 这是HTML代码:

 <div class="coverage-container">   
<div class="progressbar-content">
    <div class="progressbar-maindiv">
        <div class="progressbar-percentage">
            <center>80%</center>
        </div>

    </div>
    <img width="21" height="21" title="Get Trends"  src="http:/localhost/newccft2/Content/images/chart-graph-icon.png" class="progressbar-chart-icon" />            
</div>

<div class="progressbar-content">
    <div class="progressbar-maindiv">
        <div class="progressbar-percentage">
            <center>80%</center>
        </div>
    </div>
    <img width="21" height="21" title="Get Trends"  src="http:/localhost/newccft2/Content/images/chart-graph-icon.png" class="progressbar-chart-icon">
</div>

<div class="progressbar-content">
    <div class="progressbar-maindiv">
        <div class="progressbar-percentage">
            <center>80%</center>
        </div>
    </div>
    <img width="21" height="21" title="Get Trends"  src="http:/localhost/newccft2/Content/images/chart-graph-icon.png" class="progressbar-chart-icon">
</div>

</div>

This should do it. 这应该做。

http://jsfiddle.net/5Q9Cv/ http://jsfiddle.net/5Q9Cv/

The primary thing I did was float all your items left, and I re-ordered where your icon is in your HTML to come before your progress bar. 我要做的主要事情是浮动所有剩余的项目,然后我重新排序了HTML中您的图标的位置,以使其位于进度栏之前。 I 0'd out all margin space on the progress bar itself. 我0进度条本身上的所有页边空白。 I also set the height of your "blocks" to the height of your container, and changed the border around the blocks to just have border-right. 我还将“块”的高度设置为容器的高度,并将块周围的边框更改为仅具有右边框。 This way there aren't double borders anywhere. 这样,任何地方都不会出现双重边界。

You'll want to mess with the widths a little bit to adjust them to your needs... Just be sure you dont make the widths too small, or you'll break it and the progress bar will fall to the next line. 您可能需要稍微弄些宽度来调整它们以适应您的需求……只要确保您不要使宽度太小,否则您会破坏它,进度条将落到下一行。 (do your math basically) (基本上算一下)

HTML: HTML:

<div class="coverage-container">   

<div class="progressbar-content">

    <img width="21" height="21" title="Get Trends"  src="http:/localhost/newccft2/Content/images/chart-graph-icon.png" class="progressbar-chart-icon" />    
    <div class="progressbar-maindiv">
        <div class="progressbar-percentage">
            <center>80%</center>
        </div>
    </div>

</div><!-- END BLOCK -->

<div class="progressbar-content">

    <img width="21" height="21" title="Get Trends"  src="http:/localhost/newccft2/Content/images/chart-graph-icon.png" class="progressbar-chart-icon" />    
    <div class="progressbar-maindiv">
        <div class="progressbar-percentage">
            <center>80%</center>
        </div>
    </div>

</div><!-- END BLOCK -->

<div class="progressbar-content">

    <img width="21" height="21" title="Get Trends"  src="http:/localhost/newccft2/Content/images/chart-graph-icon.png" class="progressbar-chart-icon" />    
    <div class="progressbar-maindiv">
        <div class="progressbar-percentage">
            <center>80%</center>
        </div>
    </div>

</div><!-- END BLOCK -->


</div>

CSS: CSS:

div.coverage-container {
    border: 1px solid rgba(0, 0, 0, 0.13);
    width:370px;
    height:30px;   
    overflow: visible;
    clear: both;
}  

div.progressbar-content {
    width: 120px;
    height: 30px;
    text-align: center;
    float:left;
    border-right: 1px solid rgba(0, 0, 0, 0.13);
}


div.progressbar-maindiv {
    background-color: #DAE2E3;
    border-radius: 13px 13px 13px 13px;    
    margin: 0;
    padding: 3px;
    width: 75px;
    float:left;
}


.progressbar-percentage {
    background-color: #F23F54;
    border-radius: 15px 15px 15px 15px;
    height: 15px;
    width: 80.00%;
}

.progressbar-chart-icon {
    margin-right: 5px;
    float: left;
    text-align: center;
}

Give this a try: http://jsfiddle.net/derekstory/RKADY/ 试试看: http : //jsfiddle.net/derekstory/RKADY/

HTML HTML

<div class="coverage-container">
    <div class="progressbar-content">
        <img width="21" height="21" title="Get Trends" src="http:/localhost/newccft2/Content/images/chart-graph-icon.png" class="progressbar-chart-icon" />
        <div class="progressbar-maindiv">
            <div class="progressbar-percentage">
                <center>80%</center>
            </div>
        </div>
          <img width="21" height="21" title="Get Trends" src="http:/localhost/newccft2/Content/images/chart-graph-icon.png" class="progressbar-chart-icon" />
        <div class="progressbar-maindiv">
            <div class="progressbar-percentage">
                <center>80%</center>
            </div>
        </div>
                <img width="21" height="21" title="Get Trends" src="http:/localhost/newccft2/Content/images/chart-graph-icon.png" class="progressbar-chart-icon" />
        <div class="progressbar-maindiv">
            <div class="progressbar-percentage">
                <center>80%</center>
            </div>
        </div>
</div>

CSS CSS

div.coverage-container {
    border: 1px solid rgba(0, 0, 0, 0.13);
    width:700px;
    height:30px;
    display: inline-block;
}
div.progressbar-content {
    width: 95px;
    text-align: center;
    border: 1px solid rgba(0, 0, 0, 0.13);
    display: inline;

}
div.progressbar-maindiv {
    background-color: #DAE2E3;
    border-radius: 13px 13px 13px 13px;
    margin: 3px 9px 20px -10px;
    padding: 3px;
    width: 75px;
    float: left;
}
.progressbar-percentage {
    background-color: #F23F54;
    border-radius: 15px 15px 15px 15px;
    height: 15px;
    width: 80.00%;

}
.progressbar-chart-icon {
    margin-right: 5px;
    float:left;
    text-align: center;  
}

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

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