I have a list and I want to apply border bottom to it, here is what I want
here is what I have so far.
here is jsfiddle: https://jsfiddle.net/Mwanitete/vr1c8tgo/10/
.data-right-bottom ul li {
margin: 10px;
list-style-type: none;
display: flex;
width: 400px;
border-bottom: 1px solid green;
}
.data-right-bottom ul li span {
flex: 1 0 0;
width: 400px;
}
<div class="data-right-bottom">
<ul>
<li style="display: none;">
<span>Total wrapping (tax incl.)</span>
<span id="total_wrapping_right" class="total_wrapping_right">0,00 zł</span>
</li>
<li>
<span>Total products (tax incl.)</span>
<span id="total_product_right" class="total_product_wt_right">210,00 zł</span>
</li>
<li>
<span>Total shipping (tax incl.)</span>
<span class="total_shipping_right">
12,00 zł
</span>
</li>
<li class="order-subtotal">
<span>Total (tax excl.)</span>
<span class="total_price_without_tax_right">182,73 zł</span>
</li>
<li class="order-discounts" style="display:none">
<span>Total discounts</span>
<span class="total_discount_right">0,00 zł</span>
</li>
<li class="order-tax">
<span>Total tax</span>
<span class="total_tax_right">39,27 zł</span>
</li>
<li class="order-total">
<span>Total</span>
<span class="total_price_right">222,00 zł</span>
</li>
</ul>
</div>
what am i missing here? any help will be apreciated
Another option besides Lazar Nikolic's one is to use a CSS table instead of a flexbox. After all, that's what it is; it displays tabular data.
To make it responsive as you wanted, you can always use a media query to turn it back into a series of blocks so that everything is displayed underneath each other.
.data-right-bottom ul {
display: table;
}
.data-right-bottom ul li {
list-style-type: none;
display: table-row;
}
.data-right-bottom ul li span {
display: table-cell;
border-top: 1px solid green;
}
.data-right-bottom ul li span:last-child {
padding-left: 10px;
text-align: right;
}
#media all and (max-width: 17em) {
.data-right-bottom ul li {
display: block;
border-top: 1px solid green;
}
.data-right-bottom ul li span {
display: block;
border-top: none;
}
}
<div class="data-right-bottom">
<ul>
<li style="display: none;">
<span>Total wrapping (tax incl.)</span>
<span id="total_wrapping_right" class="total_wrapping_right">0,00 zł</span>
</li>
<li>
<span>Total products (tax incl.)</span>
<span id="total_product_right" class="total_product_wt_right">210,00 zł</span>
</li>
<li>
<span>Total shipping (tax incl.)</span>
<span class="total_shipping_right">
12,00 zł
</span>
</li>
<li class="order-subtotal">
<span>Total (tax excl.)</span>
<span class="total_price_without_tax_right">182,73 zł</span>
</li>
<li class="order-discounts" style="display:none">
<span>Total discounts</span>
<span class="total_discount_right">0,00 zł</span>
</li>
<li class="order-tax">
<span>Total tax</span>
<span class="total_tax_right">39,27 zł</span>
</li>
<li class="order-total">
<span>Total</span>
<span class="total_price_right">222,00 zł</span>
</li>
</ul>
</div>
The problem is within your css class for
.data-right-bottom ul li span. Delete it.
Also, under display: flex in .data-right-bottom ul li you should say justify-content: space-between to separate two spans that you have inside. This will give you borders that are as long as your content is. I suppose you used flex: 1 0 0; in order for your list to be responsive, but it could not be done considering that you said that the width of your list item should be 400px.
It looks like that you're trying to create a table - aren't you? If yes, you should use an HTML table instead of a list.
Especially if you want that the content in the last column has text-align: left; but the whole column be aligned to the right border of your block.
List items (li inside ul) are independent of each other and you can't make one span inside li to have the same variable width depend on the width of the span in other li. Table row, in contrast, changes the width based on its content.
table {
width: 400px;
border-collapse: collapse;
}
td {
border-top:1px solid green;
padding: 10px 0;
}
.price {
text-align: left;
width: 1%;
white-space: nowrap;
}
<div class="data-right-bottom">
<table>
<tr>
<td>Total products (tax incl.)</td>
<td class="price">
210,00 zł
</td>
</tr>
<tr>
<td>Total shipping (tax incl.)</td>
<td class="price">
12,00 zł
</td>
</tr>
</table>
</div>
Maybe you should change the width of your span to 200px (Span are two inside a "li").
Related
I have an HTML page with a list of items and their descriptions. The styling is done exclusively in CSS, in the pursuit of keeping information separate from layout.
Is it possible to use only CSS so that for every other row, the columns are reversed? I'd like to avoid using an HTML table, or manually reversing the columns in HTML, and I'd like to keep using <ul> and <li>, since it matches the kind of data that is displayed.
What I have:
img {
max-width: 50px;
height: auto;
}
ul {
list-style-type: none;
border-collapse: collapse;
display: table;
}
.item-name, .item-details {
display: table-row;
}
.item-pic, .item-text {
display: table-cell;
vertical-align: top;
padding: 10px;
}
.item-name {
font-weight: bold;
}
<html>
<body>
<ul>
<li><span class="item-pic"><img src="green.gif"></span>
<span class="item-text">
<span class="item-name">Green</span>
<span class="item-details">This is a green item</span>
</span>
</li>
<li><span class="item-pic"><img src="red.gif"></span>
<span class="item-text">
<span class="item-name">Red</span>
<span class="item-details">This is a red item</span>
</span>
</li>
<li><span class="item-pic"><img src="blue.gif"></span>
<span class="item-text">
<span class="item-name">Blue</span>
<span class="item-details">This is a blue item</span>
</span>
</li>
<li><span class="item-pic"><img src="yellow.gif"></span>
<span class="item-text">
<span class="item-name">Yellow</span>
<span class="item-details">This is a yellow item</span>
</span>
</li>
</ul>
</body>
</html>
What I would like:
You can use the following CSS code. It uses display:flex on the li tags, with reverse order on every second one (:nth-child(even)) , and display: block on the two text spans to make them go across the whole width of their parent and therefore place them below each other. Other details see below:
(The width of the container can be adjusted as desired, it could as well be 100% to span the whole width of its parent)
img {
max-width: 50px;
height: auto;
}
ul {
list-style-type: none;
display: block;
width: 200px;
padding: 0;
}
ul>li {
display: flex;
justify-content: space-between;
align-items: flex-start;
}
ul>li:nth-child(even) {
flex-direction: row-reverse;
}
.item-text > * {
display: block;
}
.item-pic,
.item-text {
padding: 10px;
}
.item-name {
font-weight: bold;
}
<html>
<body>
<ul>
<li>
<span class="item-pic"><img src="green.gif"></span>
<span class="item-text">
<span class="item-name">Green</span>
<span class="item-details">This is a green item</span>
</span>
</li>
<li><span class="item-pic"><img src="red.gif"></span>
<span class="item-text">
<span class="item-name">Red</span>
<span class="item-details">This is a red item</span>
</span>
</li>
<li><span class="item-pic"><img src="blue.gif"></span>
<span class="item-text">
<span class="item-name">Blue</span>
<span class="item-details">This is a blue item</span>
</span>
</li>
<li><span class="item-pic"><img src="yellow.gif"></span>
<span class="item-text">
<span class="item-name">Yellow</span>
<span class="item-details">This is a yellow item</span>
</span>
</li>
</ul>
</body>
</html>
You can do it with a combination of nth-child and flex. With nth-child, you can easily target alternating rows with odd or even keywords. Then it just a matter of setting the li to flex and changing the order for even row. (EDIT: updated this to use row reverse instead as it is indeed easier)
I removed all the able related styles
img {
max-width: 50px;
height: auto;
}
ul {
list-style-type: none;
border-collapse: collapse;
}
.item-pic,
.item-text {
padding: 10px;
}
.item-name {
font-weight: bold;
display: block; // no need for this if you use a div
}
li {
display: flex;
}
li:nth-child( even ) {
flex-direction: row-reverse;
}
<html>
<body>
<ul>
<li><span class="item-pic"><img src="green.gif"></span>
<span class="item-text">
<span class="item-name">Green</span>
<span class="item-details">This is a green item</span>
</span>
</li>
<li><span class="item-pic"><img src="red.gif"></span>
<span class="item-text">
<span class="item-name">Red</span>
<span class="item-details">This is a red item</span>
</span>
</li>
<li><span class="item-pic"><img src="blue.gif"></span>
<span class="item-text">
<span class="item-name">Blue</span>
<span class="item-details">This is a blue item</span>
</span>
</li>
<li><span class="item-pic"><img src="yellow.gif"></span>
<span class="item-text">
<span class="item-name">Yellow</span>
<span class="item-details">This is a yellow item</span>
</span>
</li>
</ul>
</body>
</html>
I have a menu, with one of the menu items being a logo. I would like to center the menu so the logo item stays in the center of the page. The goal is to have a menu, split by a logo, that stays centered on the logo. The location of the logo is calculated by number of menu items / 2 + 1 and round down if needed. Example: with 6 menu items, logo is in spot 4; with 5 menu items, logo is in spot 3.
Complications: 1) menu items do not have a set width - this is meant to be responsive, and I am avoiding set pixel widths at every juncture, 2) I do not want to use JavaScript
EDIT: HTML
<ul class="nav-menu">
<li class="menu-item">
<a href="/link-1">
<span>Link 1</span>
</a>
</li>
<li class="menu-item-logo">
<div id="logo">
<a href="http://example.com/">
<img src="https://pbs.twimg.com/profile_images/581134293931548673/8R33fIjl.png"/>
</a>
</div>
</li>
<li class="menu-item">
<a href="/link-2">
<span>Link 2</span>
</a>
</li>
<li class="menu-item">
<a href="/link-3">
<span>Link 3</span>
</a>
</li>
</ul>
CSS
<style>
.nav-menu {
display: flex;
justify-content: space-between;
width: 85%;
}
.nav-menu .menu-item {
display: inline-block;
margin: .25rem 2rem;
text-align: center;
}
#logo {
max-width: 15vw;
}
#logo img {
width: 100%;
}
</style>
jsfiddle # https://jsfiddle.net/szamxv2u/
I am trying to indent the text from an inline block on safari. It only indents in chrome.
I have tried using margin left. This works in chrome but in safari i have to adjust the margin-left to another number for them to look the same.
I tried the text-indent and the inline-block is not wrapping properly now.
html
<nav>
<ul>
<li><a href="#" >Home</a></li>
<li type="checkbox" class="sub">
<input type="checkbox" />
<a href="#" >Profile</a>
<!-- Begin-->
<ul class="submenu">
<li >
<a target = "box">Profiles</a>
</li>
</ul>
</li>
<!-- end-->
<li class="sub">
<input type="checkbox" />
<a href="#" >Logs</a>
<!-- Begin-->
<ul class="submenu">
<li >
<a target = "box" >View Logs</a>
</li>
<li >
<a target = "box" >Testing a long test</a>
</li>
</ul>
</li>
</li>
</ul>
</nav>
CSS in chrome
nav .submenu a {
*zoom: 1;
*display: inline;
display: inline-block;
max-width: 122px;
margin-left: 55px;
padding: 3px 1px 3px 0px;
}
CSS in safari
nav .submenu a {
*zoom: 1;
*display: inline;
display: inline-block;
max-width: 122px;
margin-left: 65px;
padding: 3px 1px 3px 0px;
}
I tried putting important on the variables to see anything overrides it too and that didn't help them look the same.
I also tried
text-indent: 50px;
Make a table with no content and put it ahead of your text.
<table>
<tbody>
<tr>
<td width="65px"> <!--this is the indent, don't forget to style it so it becomes invisible.--></td>
</tr>
</tbody>
</table>
I have navigation created using nav tabs.
I wan't to set color on hover, but I can't
I tried this, but not working .
.tab2:hover {
background-color: green;
}
.tab3:hover {
background-color: green;
}
HTML
<div class="col-md-10">
<nav class="row">
<ul class="nav nav-tabs">
<li class="tab1"> <span class="glyphicon glyphicon-user"></span> Name    <span class="glyphicon glyphicon-chevron-down"></span> </li>
<li class="tab1"><span class="glyphicon glyphicon-flag"></span>Text Link </li>
<li class="tab1"> <span class="glyphicon glyphicon-envelope"></span> Message </li>
<li class="tab1"> <span class="glyphicon glyphicon-oil"></span>10 </li>
<li class="tab1"><span class="glyphicon glyphicon-asterisk"></span>   </li>
<li class="tab1"><span class="glyphicon glyphicon-home"></span>  </li>
<li class="tab2"> <span class="glyphicon glyphicon-chevron-down"></span>     KATEGORIJE </li>
<li class="tab2">RADNJE</li>
<li class="tab2">VOZILA</li>
<li class="tab2">NEKRETNINE</li>
<li class="tab2">NAJNOVIJE</li>
<li class="tab2">HITNO</li>
<li class="tab2">USLUGE</li>
<li class="tab2">        <span class="glyphicon glyphicon-chevron-down"></span>     OSTALI LINKOVI </li>
</ul>
</nav>
</div>
CSS
* {
margin: 0;
padding: 0;
}
.nav>li>a {
padding: 10px 3px;
font-weight: bold;
color:white;
font-size: 13px;
}
.tab1 {
background-color:#324255;
height: 42px;
}
.tab2 {
background-color:#405072;
height: 42px;
}
.tab3 {
background-color: #405072;
height:42px;
}
.nav-tabs li {
border-left: 1px solid #52617b;
border-right: 1px solid #52617b;
}
ul {
background-color: #405072;
height:43px;
}
.tab2:hover {
background-color: green;
}
.tab3:hover {
background-color: green;
}
I'll try to be as specific as I can so you understand it all.
1. When I pasted your html and css in the fiddle, I forgot to add the link for bootstrap stylesheet in the html as well. Bootstrap uses a CDN as you might know and it allows you to link with their stylesheet without downloading it and actually placing it in your website folders.
This is the link I am referring to:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
I just added this above all the html in the fiddle.
To answer your original question. Bootstraps stylesheet is overwriting your stylesheet.
Your <li> is working fine and has a green background. But the <a> has a background color of its own which is coming from bootstrap.
See fiddle here https://jsfiddle.net/otuy1foo/3/. And in the css I placed the css code in comments at the bottom.
/*This is the css you need to add*/
.nav-tabs>li>a:hover, .nav>li>a:focus, .nav>li>a:hover {
border-color: transparent !important;
background-color: transparent !important;
}
i have a list:
<ul>
<li>
<span class="first">the dog jumped over the fox</span>
<span class="second">1</span>
<span class="third">Edit</span>
</li>
<li>
<span class="first">cat and mouse</span>
<span class="second">1</span>
<span class="third">Edit</span>
</li>
<li>
<span class="first">doggie</span>
<span class="second">1</span>
<span class="third">View report</span>
</li>
</ul>
and i want to set the width of the first <span> in each <li> to be equal to the one with the longest text. in this case, the longest text is "the dog jumped over the fox" so i want all the other <span class="first">s to match it. i also want to apply the same logic to any additional <span>s within the <li>. basically, all the <span class="first"> have the same length, all the <span class="second"> have the same length, and all the <span class="third"> have the same length. here's what i want to achieve:
-------------------------------------------
the dog jumped over the fox |1|Edit |
-------------------------------------------
cat and mouse |1|Edit |
-------------------------------------------
doggie |1|View report|
-------------------------------------------
thanks!
Apply CSS like below.
ul{display:table; width:100%; padding:0;}
li{display:table-row;}
li span{display:table-cell; text-align:left;}
DEMO
What about using <table>?
See this fiddle.
HTML
<table>
<tr>
<td>the dog jumped over the fox</td>
<td>1</td>
<td>Edit</td>
</tr>
<tr>
<td>cat and mouse</td>
<td>1</td>
<td>Edit</td>
</tr>
<tr>
<td>doggie</td>
<td>1</td>
<td>View report</td>
</tr>
</table>
You have to set the li to display: block; and float at least the first span, then give it a certain width. Haven't tested for crossbrowser compatibility, but it should work. Demo: http://jsfiddle.net/fdhu0w07/
`
ul {
display: block;
}
ul li {
display: block;
}
ul li span {
display: inline-block;
}
ul > li > span:first-of-type{
float: left;
width: 220px;
}`
Put your list in a table in your html.
<table>
<ul>
<li>
<span class="first">the dog jumped over the fox</span>
<span class="second">1</span>
<span class="third">Edit</span>
</li>
<li>
<span class="first">cat and mouse</span>
<span class="second">1</span>
<span class="third">Edit</span>
</li>
<li>
<span class="first">doggie</span>
<span class="second">1</span>
<span class="third">View report</span>
</li>
</ul>
</table>
Then in your CSS
table{
table-layout: fixed;
width: 300px;
}
The Pixel Width can be up to you!
Good Luck!