Problems with a list using CSS

2

This Image:

It's from a list I'm doing but I want it to be like this And this is my CSS and HTML code:

ul{
list-style:none;
counter-reset:li;
padding:10px;
left:-8px;
width:100%;
}
li{ /* Styles of each element */
width:100%;
position:relative;
left:0;
margin:0 0 1px 12px;
padding:4px 5px;
}
ul li:before{
content: counter(li);
counter-increment: li;
position: absolute; 
left: -30px;
top: 50%;
margin-top: -13px;
background: #8E8E8E; /* background color of the numbers */
height: 1.9em;
width: 2em;
line-height: 2em;
text-align: center;
font-weight: bold;
color: #fff;
font-size: 14px;
}
ul li:after{
position: absolute;
content: '';
left: -2px;
margin-top: -.7em; 
top: 50%;
width: 0;
height: 0;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
border-left:10px solid #8E8E8E; /* background color of the right arrow*/
}
ul li a{
color: #444;
text-decoration: none;   
font-size:15px;
}
ul li {
position: relative;
display: block;
padding: .4em .4em .4em .8em;
*padding: .4em;
margin: .5em 0 .5em 0.4em;
background: #ddd;
transition: all .3s ease-out;
text-decoration:none;
transition: all .1s ease-in-out;
}
ul li:hover{
background: #eee; /* Background color on mouseover */
}   
ul li a:hover{
color:#444; /* Link color on mouseover */
margin-left:3px;
}
<div id="demo-frame">
<ul id="lista1" class="gallery">
	<li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
</ul>
<ul id="lista2">
	<li>Item5</li>
    <li>Item6</li>
    <li>Item7</li>
</ul>
</div>

Someone who can help me?

    
asked by Reinos Ric 03.08.2017 в 23:44
source

3 answers

0

Hello everyone: it turns out that the problem was the "width" because what I put as a percentage (%) really wanted it as px .

Thanks

    
answered by 04.08.2017 / 17:01
source
2

You can use the flex property that @Elberth suggested, you just have to add this piece of code:

#demo-frame{
    display: flex;
    width: 50%;  //Sólo para acortarlo
}

/*Flexbox*/
#demo-frame{
	display: flex;
	width: 50%;	
}	
  
  ul{
list-style:none;
counter-reset:li;
padding:10px;
left:-8px;
width:100%;
}
li{ /* Styles of each element */
width:100%;
position:relative;
left:0;
margin:0 0 1px 12px;
padding:4px 5px;
}
ul li:before{
content: counter(li);
counter-increment: li;
position: absolute; 
left: -30px;
top: 50%;
margin-top: -13px;
background: #8E8E8E; /* background color of the numbers */
height: 1.9em;
width: 2em;
line-height: 2em;
text-align: center;
font-weight: bold;
color: #fff;
font-size: 14px;
}
ul li:after{
position: absolute;
content: '';
left: -2px;
margin-top: -.7em; 
top: 50%;
width: 0;
height: 0;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
border-left:10px solid #8E8E8E; /* background color of the right arrow*/
}
ul li a{
color: #444;
text-decoration: none;   
font-size:15px;
}
ul li {
position: relative;
display: block;
padding: .4em .4em .4em .8em;
*padding: .4em;
margin: .5em 0 .5em 0.4em;
background: #ddd;
transition: all .3s ease-out;
text-decoration:none;
transition: all .1s ease-in-out;
}
ul li:hover{
background: #eee; /* Background color on mouseover */
}   
ul li a:hover{
color:#444; /* Link color on mouseover */
margin-left:3px;
}
<div id="demo-frame">
	<ul id="lista1" class="gallery">
		<li>Item1</li>
	    <li>Item2</li>
	    <li>Item3</li>
	    <li>Item4</li>
	</ul>
	<ul id="lista2">
		<li>Item5</li>
	    <li>Item6</li>
	    <li>Item7</li>
	</ul>
</div>
    
answered by 04.08.2017 в 02:35
1

An alternative is to wrap both listings in divs with display:inline-block .

In this way, both lists will be placed on the same line.

CSS - Inline-block

Then you can assign vertical-align:top; to both divs so that the listings are aligned from the first element.

ul{
list-style:none;
counter-reset:li;
padding:10px;
left:-8px;
width:100%;
}
li{ /* Styles of each element */
width:100%;
position:relative;
left:0;
margin:0 0 1px 12px;
padding:4px 5px;
}
ul li:before{
content: counter(li);
counter-increment: li;
position: absolute; 
left: -30px;
top: 50%;
margin-top: -13px;
background: #8E8E8E; /* background color of the numbers */
height: 1.9em;
width: 2em;
line-height: 2em;
text-align: center;
font-weight: bold;
color: #fff;
font-size: 14px;
}
ul li:after{
position: absolute;
content: '';
left: -2px;
margin-top: -.7em; 
top: 50%;
width: 0;
height: 0;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
border-left:10px solid #8E8E8E; /* background color of the right arrow*/
}
ul li a{
color: #444;
text-decoration: none;   
font-size:15px;
}
ul li {
position: relative;
display: block;
padding: .4em .4em .4em .8em;
*padding: .4em;
margin: .5em 0 .5em 0.4em;
background: #ddd;
transition: all .3s ease-out;
text-decoration:none;
transition: all .1s ease-in-out;
}
ul li:hover{
background: #eee; /* Background color on mouseover */
}   
ul li a:hover{
color:#444; /* Link color on mouseover */
margin-left:3px;
}

.inline-block-div{
  display:inline-block;
  padding: 15px;
  vertical-align:top;
}
<div id="demo-frame">
  <div class="inline-block-div">
    <ul id="lista1" class="gallery">
      <li>Item1</li>
        <li>Item2</li>
        <li>Item3</li>
        <li>Item4</li>
    </ul>
  </div>
  <div class="inline-block-div">
      <ul id="lista2">
        <li>Item5</li>
          <li>Item6</li>
          <li>Item7</li>
      </ul>
   </div>
</div>
    
answered by 04.08.2017 в 00:30