I can't style link 1 different from link 2. It's always forcing the style from .about a. No matter if I specific set it to another style.
<div class="about">
<div class="wrapper" style="width: 1052px;">
<h2 style="color: #fff">Title</h2>
<ul>
<li>
Text 1 - Link 1
</li>
<li>
Text 2 - Link 2
</li>
</ul></div></div>
CSS:
.about a {
margin-top: 35px;
display: block;
color: #fff;
font: 15px/52px 'sans-serif';
font-family: 'Ubuntu', sans-serif;
text-decoration: none;
text-align: center;
text-transform: uppercase;
width: 226px;
height: 52px;
border: 1px solid #fff;
border-radius: 27px;
-webkit-background-clip: padding-box;
background-clip: padding-box;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out; }
I've tried something like this:
Link
<span class="linkk" a href:#">Link</span>
Link
You're looking for the :first-of-type pseudo-class:
.about li:first-of-type a {
color: red;
}
<div class="about">
<div class="wrapper" style="width: 1052px;">
<h2 style="color: #fff">Title</h2>
<ul>
<li>
Text 1 - Link 1
</li>
<li>
Text 2 - Link 2
</li>
</ul>
</div>
</div>
Note that it needs to be on the parent <li> element, rather than simply adding it to .about a directly. This is because the :first-of-type pseudo-class pertains to siblings, rather than checking for any elements of that type in .about. Both <a> elements are the first of their type in their respective <li> parents.
Hope this helps! :)
From what I understood of this line: I can't style link 1 different from link 2, you want different style for each link.
If it is only two links, you can use first-child and last-child
.about li:first-child a {
color: red;
}
.about li:last-child a {
color: blue;
}
<div class="about">
<div class="wrapper" style="width: 1052px;">
<h2 style="color: #fff">Title</h2>
<ul>
<li>
Text 1 - Link 1
</li>
<li>
Text 2 - Link 2
</li>
</ul>
</div>
</div>
Try This:
.about li:nth-of-type(1) a {
color: red;
}
.about li:nth-of-type(2) a {
color: green;
}
.about li:nth-of-type(1) a {
color: red;
}
.about li:nth-of-type(2) a {
color: green;
}
<div class="about">
<div class="wrapper" style="width: 1052">
<h2 style="color:#fff">Title</h2>
<ul>
<li>
Text 1 - Link 1
</li>
<li>
Text 2 - Link 2
</li>
</ul>
</div>
</div>
Related
.about:hover > .left {
color: #DAFDBA;
}
HTML: >
<div class="navbar">
<!--Lines above Links-->
<hr class="left">
<hr class="middle">
<hr class="right">
<!--Links (Text)-->
<p class="about">About.</p>
<p class="projects">Projects.</p>
<p class="contact">Contact.</p>
</div>
What should be the statement between .about:hover and .left?
You can use code like this if you just want to have three links with one line above each one, and hovering over the link the line turns green
a{
color:inherit;
text-decoration: none;
border-top: 2px solid #000;
padding:.2em 0 0;
margin: 0 .2em;
}
a:hover {
border-color: #DAFDBA;
}
<nav>
About
Projects
Contact
</nav>
I'm building a list widget where I have multiple <li> with two sibling elements wrapped inside.
A <span> for the title and a <div> for the bottom line. That line must vary depending the width of their adjacent span element.
.limit-area {
width: 250px;
height: 350px;
background-color: #96ceb4;
}
.limit-area ul {
font-size: 0;
list-style-type: none;
-webkit-padding-start: 0;
}
.limit-area ul li {
background-color: #ffeead;
display: table;
margin-bottom: 20px;
}
.limit-area ul li .wrapper span {
font-size: 24px;
color: #010101;
}
.limit-area ul li .wrapper .line {
height: 6px;
margin-top: 12px;
background-color: #ff6f69;
}
<div class="limit-area">
<ul>
<li>
<div class="wrapper">
<span>One line only</span>
<div class="line"></div>
</div>
</li>
<li>
<div class="wrapper">
<span>Bigger one line only </span>
<div class="line"></div>
</div>
</li>
<li>
<div class="wrapper">
<span>Long line and go crazyyyyyy</span>
<div class="line"></div>
</div>
</li>
</ul>
</div>
Full example on jsfiddle: https://jsfiddle.net/arnauth/55josw6e/
In the upper example, I can easily accomplish my goal on the first two list items.
The trick here is to have the same effect when I have a long line that break into two or more lines - that third line on the example.
The line element must have the same width of the text, so in the example must stop near the word 'go' - not in the end of the container as displayed.
The idea is try to approach the problem using only CSS rules avoiding javascript based code.
Thanks for your attention.
Try adding this inside of your span:
border-bottom: 6px solid #ff6f69;
so that it ends up looking like this:
span {
font-size: 24px;
color: #010101;
border-bottom: 6px solid #ff6f69;
}
it should come out like this
https://jsfiddle.net/55josw6e/3/
Hope this answers your question.
I have the following code to show a division on hover. It is initially hidden and i'm trying to show one division on hover of another element.
.topNav {
padding: 1px 15%;
background: #006cb4;
color: white;
}
.mainMenu {
list-style-type: none;
}
.mainMenu li {
display: inline-block;
padding: 3px 15px;
font-size: 20px;
}
.mainMenu li a {
text-decoration: none;
color: white;
}
#item1 {
display: block;
}
#item1:hover #item1detail {
background: #444;
visibility: visible;
}
#item1detail {
position: absolute;
top: 152px;
left: 250px;
background: #ccc;
width: 750px;
height: 400px;
border: solid 1px black;
border-radius: 0 0 10px 10px;
visibility: hidden;
}
<div class="topNav">
<ul class="mainMenu">
<li><a id="item1" href=""> item 1</a>
</li>
<li> item 3
</li>
<li> item 4
</li>
<li> item 5
</li>
<li> item 6
</li>
<li> item 7
</li>
<li> item 8
</li>
<li> item 9
</li>
</ul>
<div id="item1detail">
Some random content
</div>
</div>
on hover of the list item item1 i want to show the division itemdetail. The above code is not working. What am i doing wrong?
As I see it the only solution to display the given div without touching the HTML would be Javascript... As the others suggested already...
BUT... there's a solution with one slight change to your HTML and CSS each.
The main problem is this CSS-selector:
#item1:hover #item1detail
which would translate to "id item1detail INSIDE of an hovered id item1".
You can fix this by placing the div inside of the li and change the selector to:
#item1:hover + #item1detail
Since the div is positioned absolute anyway it doesn't make a visual difference... at least for your snippet...
Updated version of your snippet:
.topNav
{
padding: 1px 15%;
background: #006cb4;
color: white;
}
.mainMenu
{
list-style-type: none;
}
.mainMenu li
{
display: inline-block;
padding: 3px 15px;
font-size: 20px;
}
.mainMenu li a
{
text-decoration: none;
color: white;
}
#item1
{
display: block;
}
#item1:hover + #item1detail
{
background: #444;
visibility: visible;
}
#item1detail
{
position: absolute;
top: 152px;
left: 250px;background: #ccc;
width: 750px;
height: 400px;
border:solid 1px black;
border-radius: 0 0 10px 10px;
visibility: hidden;
}
<div class="topNav">
<ul class="mainMenu">
<li >
<a id="item1" href=""> item 1</a>
<div id="item1detail">
Some random content
</div>
</li>
<li> item 3</li>
<li> item 4</li>
<li> item 5</li>
<li> item 6</li>
<li> item 7</li>
<li> item 8</li>
<li> item 9</li>
</ul>
</div>
You'll have to use javascript
<script>
function myFunction() {
if (document.getElementById("item1detail").hidden==false){
document.getElementById("item1detail").hidden = true;
}else{
document.getElementById("item1detail").hidden = false;
}
}
</script>
and
<div class="topNav">
<ul class="mainMenu">
<li><a id="item1" onhover="myFunction()" href=""> item 1</a>
</li>
<li> item 3
</li>
<li> item 4
</li>
<li> item 5
</li>
<li> item 6
</li>
<li> item 7
</li>
<li> item 8
</li>
<li> item 9
</li>
</ul>
<div id="item1detail">
Some random content
</div>
</div>
I would do that using jQuery.
$('#item1').hover(function(){
$('#item1detail').show();
}, function(){
$('#item1detail').hide();
});
The reason your CSS isn't working is because you're using this selector:
#item1:hover #item1detail
Which selects the element with id #item1detail occurring within the element with id #item1, if the #item1 element is hovered.
In your current markup, #item1detail is outside #item1, and so does not match the selector. Moving #item1detail should get you the behavior you want. (And there will probably be some layout work to do from that point.)
The #item1detail element is not a sibling of the #item1 element, so that is why the #item1:hover #item1detail CSS rule does not apply as you expect it to.
I believe if this is to work with CSS only (not JavaScript), then you will have to make #item1detail a sibling of #item1.
I have basically this html code:
<ul class="unordered-list">
<li class="list-item">
<div class="list-item-block">
Sometimes a wrapped link to Google
<p class="list-item-link-description">Short description of the link above</p>
</div>
</li>
</ul>
Is there a way to expand the clickable area of the link to the size of the li element by keeping the links position and the description nicely below the link?
I tried to use absolute positioning for both the link and the description but this fails if for example the link text has a line break. As you can see in this jsFiddle: http://jsfiddle.net/xgcjngvs/3/
I would love to find a solution for this problem without javascript.
EDIT: I should have mentioned that the link tag should only contain the plain text and not any other html code.
Given your new requirement there is another way that this can be achieved without changes to your existing HTML structure:
Remove the absolute positioning from .list-item-link and .list-item-link-description, position: absolute; takes the elements out of the document flow and these two need to be aware of how much space each of them take up
Add a pseudo element to .list-item-link using .list-item-link:after, make this position: absolute; and set the height and width to take up the dimensions of the container.
.unordered-list {
list-style: none;
padding-left: 0;
}
.list-item {
min-height: 50px;
position: relative;
}
.list-item-link {
width: 100%;
}
.list-item-link:after {
content: "";
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
.list-item-link-description {
margin: 0;
}
<ul class="unordered-list">
<li class="list-item">
<div class="list-item-block">
Sometimes a wrapped link to Google
<p class="list-item-link-description">Short description of the link above</p>
</div>
</li>
<li class="list-item">
<div class="list-item-block">
Sometimes a wrapped link to Google. It is very very very very very very long to demonstrate the linke break.
<p class="list-item-link-description">Short description of the link above</p>
</div>
</li>
</ul>
JS Fiddle: http://jsfiddle.net/5s44c95q/
This is possible with a few changes to your markup and css:
Change list-item-block into the a element and set it as display: block;
Change list-item-link and list-item-link-description into span elements as only inline elements are valid in a elements
Style list-item-link to look like the link
Style list-item-link-description to look like the paragraph
.unordered-list {
padding-left: 0;
list-style: none;
}
.list-item {
position: relative;
height: 50px;
}
.list-item-block {
display: block;
min-height: 100%;
text-decoration: none;
}
.list-item-link {
text-decoration: underline;
}
.list-item-link-description {
color: #000000;
display: block;
text-decoration: none;
}
<ul class="unordered-list">
<li class="list-item">
<a href="www.google.com" class="list-item-block">
<span class="list-item-link">Sometimes a wrapped link to Google</span>
<span class="list-item-link-description">Short description of the link above</span>
</a>
</li>
<li class="list-item">
<a href="www.google.com" class="list-item-block">
<span class="list-item-link">Sometimes a wrapped link to Google. It is very very very very very very long to demonstrate the linke break.</span>
<span class="list-item-link-description">Short description of the link above</span>
</a>
</li>
</ul>
If your short description will be on 1 line, you can add padding-bottom to the list-item-link and then move the description up by the same amount and also set a negative margin-bottom for the block as a whole. If you do the padding in ems, it should take care of different font sizes.
To make the short description clickable, you need to make the z-index of the link higher than the description.
.unordered-list {
padding-left: 0;
list-style: none;
}
.list-item {
margin-top:10px;
margin-bottom:-2em;
position:relative;
}
.list-item-link {
display:block;
position:relative;
border:1px #000 solid; /*to show link area */
padding-bottom:2em;
z-index:1;
}
.list-item-link-description {
position:relative;
top:-2em;
}
<ul class="unordered-list">
<li class="list-item">
<div class="list-item-block">
Sometimes a wrapped link to Google
<p class="list-item-link-description">Short description of the link above</p>
</div>
</li>
<li class="list-item">
<div class="list-item-block">
Sometimes a wrapped link to Google. It is very very very very very very long to demonstrate the linke break.
<p class="list-item-link-description">Short description of the link above 2</p>
</div>
</li>
</ul>
EDIT: I removed the paragraph tags as you have requested but I can not get it to work any other way without the span, so the span would have to stay in place.
<ul class="unordered-list">
<li class="list-item">
<div class="list-item-block">
<span class='anchor-control'><a href="www.google.com" class="list-item-link">Sometimes a wrapped link to Google</span>
Short description of the link above
</a>
</div>
</li>
<li class="list-item">
<div class="list-item-block">
<span class='anchor-control'><a href="www.google.com" class="list-item-link">Sometimes a wrapped link to Google. It is very very very very very very long to demonstrate the linke break This needs to be a longer link then .</span>
Short description of the link above
</a>
</div>
</li>
</ul>
And here's your CSS.
EDIT: New styles to match the top, it's pretty straight forward stuff
a{
text-decoration: none;
color: #000;
}
.anchor-control a{
text-decoration: underline;
width: 100%;
float: left;
color: #00f;
}
.unordered-list {
padding-left: 0;
list-style: none;
}
.list-item {
position: relative;
padding; 0;
margin: 0;
}
.list-item-link {
position: relative;
}
a .list-item-link-description {
position: relative;
color: #000;
margin: 0;
margin-bottom: 10px;
}
EDIT: This should be what you're after.
http://jsfiddle.net/xgcjngvs/9/
css
a{
text-decoration: none;
}
.anchor-control{
text-decoration: underline;
}
.unordered-list {
padding-left: 0;
list-style: none;
}
.list-item {
position: relative;
padding; 0;
margin: 0;
}
.list-item-link {
position: relative;
}
#content {
display: none;
}
#show:target #content {
display: inline-block;
}
#show:target #open {
display: none;
}
.btn-open:after,.btn-close:after{
position:absolute;
right:280px;
top:0;
}
.btn-open:after{
content: "\25BC";
}
.btn-close:after{
content: "\25B2";
}
<ul class="unordered-list">
<li class="list-item">
<span class='anchor-control'>Sometimes a wrapped link to Google</span>
<div id="show">
<div id="content">
Short description of the link above
</div>
</div>
</li>
</ul>
try this JSFIDDLE
I have written a text inside h2 and next to that i want to show a tabbed navigation but that tabbed navugation is not being placed next to it ,its going below h2 as shown in following image inside that gray box:
Following is my code for html page:
<header>
<h2>
Corporate
jobpost
</h2>
<div id='tabjob'>
<ul>
<li>
<a class='innertab selectprofile' href='#YourJobposts'>Your Jobposts</a>
</li>
<li>
<a class='innertab signupprofile' href='#OtherJobposts'>Other Jobposts</a>
</li>
<li>
<a class='innertab signupprofile' href='#Appliedfor'>Applied for</a>
</li>
</ul>
</div>
</header>
header is the thing which is in gray color in the image.Inside this header i want to show text ,next to that tabbed navigation and at the corner that button
Following is my CSS for this tabbed navigation:
#tabjob
{
padding-top:0px;
padding-left:10px;
height:0px;
}
.innertab
{
background-color: rgba(142, 194, 218, 0.3);display: block;height: 25px;
line-height: 30px;text-align: center;
width: auto;float: left;font-weight: bold;
padding-left: 8px;
padding-right: 8px;
text-shadow: #eee 0px 0px 2px;
}
#tabjob ul li
{
display:block;
}
I have already posted the answer in comments just adding the details of the answer here.
DEMO is HERE
since your h2 tag and all heading tags are block element in HTML it take the complete width available.
so to avoid h2 tag to take complete width just add {float:left} to this element
Make sure you apply this style to specific h2 only otherwise your HTML will mess up. is you have used more than one h2 tags on the page.
HTML
<h2 class="floatTag">Corporate jobpost</h2>
<div id='tabjob'>
<ul>
<li>
<a class='innertab ' href='#YourJobposts'>Your Jobposts</a>
</li>
<li>
<a class='innertab ' href='#OtherJobposts'>Other Jobposts</a>
</li>
<li>
<a class='innertab ' href='#Appliedfor'>Applied for</a>
</li>
</ul>
</div>
CSS
#tabjob
{
padding-top:0px;
padding-left:10px;
height:0px;
}
.innertab
{
background-color: rgba(142, 194, 218, 0.3);display: block;height: 25px;
line-height: 30px;text-align: center;
width: auto;float: left;font-weight: bold;
padding-left: 8px;
padding-right: 8px;
text-shadow: #eee 0px 0px 2px;
}
#tabjob ul li
{
display:block;
}
h2.floatTag{float:left;}
Use display:inline-block for both the h2 and the tabjob:
h2, #tabjob { display: inline-block }
Demo: http://dabblet.com/gist/2774902
ul and div are block elements which means they always go below whatever is before them:
a<div>x</div>
would give you two lines. Try
a<div style='display: inline'>x</div>