This question already has answers here:
CSS selector for first element with class
(23 answers)
Closed 8 years ago.
CSS
.list-group-item:first-child{
border-top: none !important;
}
HTML
<li class="list-group-item" ng-repeat="user in data">
{{user.name}}
</li>
What's wrong with my first-child?
demo here http://plnkr.co/edit/FKXdsJRc9eu4TiN9UPMY?p=preview
The :first-child selector is intended, to select the first child of a parent tag. The children have to be embedded in the same parent tag, it is not to be used with css class.
If you want to select first list item, you chould modify it to select first child of <ul> tag.
li:first-child{
border-top: none !important;
}
You could change it in two ways:
A) Use it on the li (as now) but use first-of-type
B) Nest the li's in an ul class="example" (which you are supposed to do) and do
.example:first-child{
border-top: none !important;
}
(Your example edited: http://plnkr.co/edit/QTlaDQPXfdg3W6oNYex4?p=preview)
Embed the list in <ul></ul> tags, as they are expected to, and it will work.
Remove !important from list-group-item class border-top
CSS:
.list-group-item {
padding: 6px 15px !important;
border-top: 2px solid #DDD;
padding-top: 15px !important;
}
HTML:
something here
<ul>
<li class="list-group-item ng-scope ng-binding" ng-repeat="user in data">jason</li>
<li class="list-group-item ng-scope ng-binding" ng-repeat="user in data">james</li>
<li class="list-group-item ng-scope ng-binding" ng-repeat="user in data">josh</li>
<li class="list-group-item ng-scope ng-binding" ng-repeat="user in data">joshua</li>
</ul>
LINK
You can try below code:
http://plnkr.co/edit/jqecyBMcrLfVaGtxhIaM?p=preview
<ul><li class="list-group-item" ng-repeat="user in data">
{{user.name}}
</li></ul>
You don't have any parent tag there. You should use something like this:
HTML
<ul class="list-group-item">
<li ng-repeat="user in data">
{{user.name}}
</li>
</ul>
CSS
.list-group-item li {
padding: 6px 15px !important;
border-top: 2px solid #DDD !important;
padding-top: 15px !important;
}
.list-group-item li:first-child {
border-top: none !important;
}
<ul class="First">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
If you have this kind of structure you can access the first child by giving style like this :
.First li:first-child {
/your style comes here/
}
I have tried to solve the answer in different way, Not Sure why first:child is not working
.list-group-item {
padding: 6px 15px;
border-bottom: 2px solid #DDD;
padding-top: 15px;
}
.list-group-item:last-child{
border-bottom: 2px solid #FFFFFF;
}
Related
This question already has an answer here:
Why doesn't nth-of-type/nth-child work on nested elements?
(1 answer)
Closed 3 years ago.
I've been trying to remove the last tab's border-right property... but both the nth-child property or the last-child property isn't working...
plus when i use nth-child(1) it selects all the children and doesn't work for other values
<!-- HTML Markup -->
<ul>
<a href="#">
<li>Solutions</li>
</a>
<a href="#">
<li>Industries</li>
</a>
<a href="#">
<li>Resources</li>
</a>
<a href="#">
<li>Partners</li>
</a>
<a href="#">
<li>About</li>
</a>
<a href="#" class="button">
<li>Enterprise</li>
</a>
</ul>
/* CSS Code */
ul:after{
content: "";
display: block;
clear: both;
}
li {
float: left;
padding: 10px 15px;
/* border-right: 1px solid #a5a5a5; */
color: #1F222B;
}
li {
border-right: 1px solid #ff0000;
}
li:nth-of-type(1) {
border-right: 1px solid #00b2ff;
}
li:hover {
border-right: 1px solid #F3EFF2;
background: #1F222B;
color: #F3EFF2;
}
Kindly help with the solution and the cause?
And is it possible to achieve the solution with 'li' tags inside the 'a' tag
but with the floating 'li' tags?
You can add this CSS to remove the border from the last tab
a:last-child li {
border-right: none;
}
I have a menu (ul tags) whose elements are inline. Right now, the elements wrap when they reach the width of the container:
This is what I would like is to force the menu to be on two lines:
If extra entries are added, I would like the menu to equally divide on the two lines:
I'm ideally looking for a way to do it with css only. I tried using flexbox and writing-direction without succes. I'm open to a javascript solution but would like to have soft enought solution to allow for different designs in other responsive modes.
Edit:
Here is my HTML:
<ul class="main-menu">
<li class="main-menu__entry">Le projet</li>
<li class="main-menu__entry">Les numéros</li>
<li class="main-menu__entry">Obtenir le magazine</li>
<li class="main-menu__entry">Devenir coopérateur</li>
<li class="main-menu__entry">Nous contacter</li>
<li class="main-menu__entry">Proposer un sujet</li>
</ul>
and CSS (I simplified wit honly the relevant code)
.main-menu__entry {
display: inline-block;
padding: 4px 8px;
border: 2px solid gold;
margin: 0 2px 2px 0;
color: black;
}
Thanks.
Is this what you are looking for? This is definitely a scalable solution, but should be useful for now.
.main-menu__entry {
display: inline-block;
padding: 4px 8px;
border: 2px solid gold;
margin: 0 2px 2px 0;
color: black;
width: 150px;
}
<ul class="main-menu">
<li class="main-menu__entry">Le projet</li>
<li class="main-menu__entry">Les numéros</li>
<li class="main-menu__entry">Obtenir le magazine</li>
<li class="main-menu__entry">Devenir coopérateur</li>
<li class="main-menu__entry">Nous contacter</li>
<li class="main-menu__entry">Proposer un sujet</li>
</ul>
I'm having some issues bootstrap breadcrumb displayed in tabs. I want to both items side-by-side (similar to a tab in chrome). However, unable to do this properly. Any suggestions?
<ol class="breadcrumb">
<ul class="nav nav-tabs">
<li class="active">
Zika Virus
<i class="fa fa-close"></i>
</li>
</ul>
</ol>
EDIT:
To be more precise and clear, I want both items in the same tab. In my application, I will have tabs, each containing a topic and a close icon. I'm trying to create a UI similar to that of a internet browser tabs.
If this is not possible with this format, any suggestions in designing this UI would be greatly appreciated.
It took much longer than I expected, but it works. Check out this JSFiddle
How it works:
Bootstrap turns each child of <li class="active"> into tabs. The reason you were getting 2 tabs is because each <a> was turning into a tab, even though they were in the same <li>.
The CSS I wrote overwrites this to turn the <li class="active"> into the tab, rather than the children (by turning into a tab, I mean giving it borders, padding, etc.)
.nav-tabs li {
/* Give Bootstrap CSS normally applied to children
to the tab container */
color: #555 !important;
cursor: default !important;
background-color: #FFF !important;
border: 1px solid #DDD !important;
border-bottom-color: transparent !important;
margin-right: 2px !important;
line-height: 1.42857143 !important;
border-radius: 4px 4px 0 0 !important;
position: relative !important;
display: block !important;
padding: 10px 15px !important;
text-decoration: none !important;
list-style: none !important;
}
.nav-tabs li * {
/* Overwrite Bootstrap CSS */
border: none !important;
margin-right: 0 !important;
padding: 0 !important;
/* To display on the same line */
display: inline-block !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<ol class="breadcrumb">
<ul class="nav nav-tabs">
<li class="active">
Zika Virus
<a class="custom-inline" href="#"><i class="fa fa-close"> X</i></a>
</li>
</ul>
</ol>
I have two UL's:
How can I add text to appear in the top green area.
The text needs to not be in an LI.
Every attempt I make has the text appear outside the boxes. I've had the two UL's wrapped in both a div and a span (currently a span as below) with text before the UL but but neither helped and the text was still outside.
jsfiddle: http://jsfiddle.net/gThjy/
<html>
<head>
<style>
#list_to_process, #categories {
color: blue; background-color: green; border: solid;
border-width: 4px; padding-top:40px
}
.panel { color: red; background-color: yellow;
border: solid; border-width: 4px }
ul { padding: 10px; margin: 50px; float:left; list-style:none; }
li { color: yellow; padding: 25px 80px; cursor: move; }
li:nth-child(even) { background-color: #000 }
li:nth-child(odd) { background-color: #666 }
</style>
</head>
<body>
<span class="a_list">
header1
<ul id="list_to_process">
<li class="to_process" id="left1">1</li>
<li class="to_process" id="left2">2</li>
<li class="to_process" id="left3">3</li>
<li class="to_process" id="left4">4</li>
<li class="to_process" id="left5">5</li>
</ul>
</span>
<span class="a_list">
<ul id="categories">
<li id="righta">a</li>
<li id="rightb">b</li>
<li id="rightc">c</li>
<li id="rightd">d</li>
<li id="righte">e</li>
</ul>
</span>
</body>
</html>
With your current markup this addition to CSS will work and be semantic:
#list_to_process:before, #categories:before{
content:"Read this: ";
}
Maybe this could help:
<ul id="list_to_process">
Header 1
<li class="to_process" id="left1">1</li>
<li class="to_process" id="left2">2</li>
<li class="to_process" id="left3">3</li>
<li class="to_process" id="left4">4</li>
<li class="to_process" id="left5">5</li>
</ul>
<ul id="categories">
Header 2
<li id="righta">a</li>
<li id="rightb">b</li>
<li id="rightc">c</li>
<li id="rightd">d</li>
<li id="righte">e</li>
</ul>
Well its only valid in HTML to have an <li> as a child of a <ul> or <ol> so wrapping any text in a different element isn't possible. You can simply just add text directly after the starting tag for the <ul> and it'll show up in the green area, though I'm not sure thats exactly what you're after. I'm also unsure of whether its valid to have a text-node directly after a <ul> tag, though I will try to find a source.
http://jsfiddle.net/PerfectDark/gThjy/5/
Update: Adding text before the starting <ul> tag is also invalid according to the validator:
Line 38, Column 10: Text not allowed in element ul in this context.
I think your best option is to absolutely position an element to have it appear its inside the box.
I have a left/right border on a list to create a separation effect.
Ex: Link1 | Link2 | ...
I want the lines on the border to be a bit shorter than the total height of the object -- maybe 50% of the total height and centered vertically. However, they are 100% of height. How can I set a height on a border and center it vertically?
Thanks!
<ul class="nav pull-right" style="line-height:30px;">
<li class="dropdown pull-right" style="line-height:20px;border-left: 1px solid #e3e3e3;border-right: 1px solid #e3e3e3;">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{% if notice_unseen_count %} <span class="badge badge-warning" style="line-height:15px;">{{ notice_unseen_count }}</span>{% else %}<span class="badge" style="line-height:15px;">0</span>{% endif %}
</a>
<ul class="dropdown-menu">
<li>Inbox</li>
<li class="divider"></li>
<li>Invitations</li>
<li class="divider"></li>
<li>All Notifications</li>
</ul>
</li>
Don't blow up your list with a divider-element. Try this. You can easily adjust the size/height of the border that is created by using the :after pseudo element:
Demo
Try before buy
HTML
<ul>
<li>Inbox</li>
<li>Invitations</li>
<li>All Notifications</li>
</ul>
CSS
ul {
margin: 0;
padding 0;
list-style: none;
}
ul > li {
float: left;
height: 30px;
line-height: 30px;
background: red;
}
ul > li:after {
content: '';
display:block;
float: right;
height: 15px;
width: 1px;
background: #ccc;
margin: 7px 10px 0 10px;
}
Last "border"
To remove the border from the last element, this CSS rule does the job:
ul > li:last-child:after {
content: none;
}
The border lengths will always be >= element's width/height, so you cannot set it to 50% or anything. See the box model: http://css-tricks.com/the-css-box-model/
If you want to style those separation bars, suggest using a background image.
.divider {
background: transparent url('link/to/separator.gif') right center no-repeat;
padding: auto 10px;
}
This will add separater image to the right of all the links with divider class. For the last item in the list, you don't need to apply the class.