I am putting horizontal line after each li. What I want to do is hr should be in the same distance to li(s).
This is my css to put hr
.divider {
content: "";
display: block;
height: 1px;
width: 100%;
background: #ccc;
}
This one of the li(s)
<li style="width:210px;padding:10px 0 10px 0" class="memberElement">
<div class="MemberImageHolder" style="float:left">
<a href="#">
<img class="mediumMemberPicture" src="picture.php?action=display&contentType=members&id=20&quality=medium" alt="" />
</a>
</div>
<div class="memberDetails" style="float:right">
Mert Metin<br>
<span id="title">
Administrator<br><br>
</span>
<span id="unit">
<b>University of Ottawa</b>
<br>
</span>
</div>
<span class="divider"></span>
</li>
However, this is how it looks:
Why it looks like that?
Try clearing your floats before the <span class="divider"> element. Since sibling <div> elements are floated, you'll need to clear the float before placing an element below them.
See also: clearfix
Also, CSS content applies to ::before and ::after pseudo-elements. I have removed it as it is not useful here.
.divider {
...
clear: both;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
.divider {
display: block;
height: 1px;
width: 100%;
background: #ccc;
clear: both;
}
<ul>
<li style="width:210px;padding:10px 0 10px 0" class="memberElement">
<div class="MemberImageHolder" style="float:left">
<a href="#">
<img class="mediumMemberPicture" src="http://dummyimage.com/100x100/000/fff" alt="">
</a>
</div>
<div class="memberDetails" style="float:right">Mert Metin<br><span id="title">Administrator<br><br></span><span id="unit"><b>University of Ottawa</b><br></span>
</div><span class="divider"></span>
</li>
<li style="width:210px;padding:10px 0 10px 0" class="memberElement">
<div class="MemberImageHolder" style="float:left">
<a href="#">
<img class="mediumMemberPicture" src="http://dummyimage.com/100x100/000/fff" alt="">
</a>
</div>
<div class="memberDetails" style="float:right">Mert Metin<br><span id="title">Administrator<br><br></span><span id="unit"><b>University of Ottawa</b><br></span>
</div><span class="divider"></span>
</li>
</ul>
You might want to add after:
.divider:after {
content: "";
display: block;
height: 1px;
width: 100%;
background: #ccc;
}
Related
Anyone knows, why does it happen? It looks like images and links in list items are separated. I can't really understand it, because it looks really strange. I have always seen list items that include both images and links under one border. Thx in advice.
html {
box-sizing: border-box;
}
*,
*::after,
*::before {
box-sizing: inherit;
}
body {
background: #070A1B;
font-size: 16px;
line-height: 120%;
font-weight: 400;
color: #fff;
font-family: 'Roboto Condensed', sans-serif;
}
a {
text-decoration: none;
color: inherit;
}
.header__top {
justify-content: space-between;
height: 100px;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 10px;
}
.header {}
<header class="header">
<div class="container">
<div class="header__top">
<button class="header__nav">
<img class="header__nav-img" src="images/menu-btn.svg" alt="menu botton">
</button>
<a href="#" class="logo">
<img src="images/logo.svg" alt="logo" class="logo__img">
</a>
<ul class="list">
<li class="list_item">
<a href="#" class="list__link">
<img src="images/twitter.svg" alt="twitter" class="list__img">
</a>
</li>
<li class="list_item">
<a href="#" class="list__link">
<img src="images/google.svg" alt="google" class="list__img">
</a>
</li>
<li class="list_item">
<a href="#" class="list__link">
<img src="images/facebook.svg" alt="facebook" class="list__img">
</a>
</li>
</ul>
</div>
</div>
</header>
idk why, but here we go...
What you're seeing is the default vertical-align value of baseline affecting the img elements. Setting this to middle will allows them align better with the text.
let imgData = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmVyc2lvbj0iMS4xIj48cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSJncmVlbiIgLz48L3N2Zz4=';
document.querySelectorAll('img').forEach(img => img.src=imgData);
img {
vertical-align: middle;
border: 1px solid black;
}
<button><img></button>
<img>
<ul>
<li><img></li>
<li><img></li>
<li><img></li>
</ul>
The link will still affect the whole image if that´s your concern.
Anyway, you can solve this by changing the "display" value in css.
Try adding "display:block;" or "display:inline-block;" to the "a" element and this way it will cover the whole image.
CodePen is here: http://codepen.io/anon/pen/BKVMoY
ul {
width: 40%;
border: 1px solid black;
list-style: none;
padding: 0;
}
span:last-of-type {
float: right;
}
<ul>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
</ul>
Why isn't the floated element underlined?
How can I make it clickable for space between the spans?
Why isn't the floated element underlined?
16.3.1 Underlining, overlining, striking, and blinking: the 'text-decoration' property
Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables.
To fix that, you can set text-decoration: inherit on the floated span.
span:last-of-type {
float: right;
text-decoration: inherit;
}
How can I make it clickable for space between the spans?
You can set the <a> to display:block, it will the occupies the entire width available.
a {
display: block;
}
ul {
width: 40%;
border: 1px solid black;
list-style: none;
padding: 0;
}
a {
display: block;
}
span:last-of-type {
float: right;
text-decoration: inherit;
}
<ul>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
</ul>
I think you can just add display: block; to the anchor tags in order to make the entire row clickable. I'm not exactly sure why the floated element removes the underline.
<ul class="whole-row-link">
<li>
<span>New York</span>
<span>$489</span>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
</ul>
ul.whole-row-link li {
position: relative;
}
ul.whole-row-link li a {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0
}
I was able to make the space between the link clickable but it stillls looks weird when you dont have underline.
I used the flexbox to acheive the effect of the clickable.
`http://codepen.io/Ebeldev/pen/BKVMwP`
I have a wordpress recently viewed products widget. I would like the name of the product to show up over the image, when you hover over it.
I have it working elsewhere, the difference is than with this widget, the li do not have a class attached. I know the line I need to fix is:
.product_list_widget ul li .attachment-shop_thumbnail:hover span.product_title {
I just don't know what it should be changed to, to show the span when the image is hovered!
For the first time I got a fiddle to work!
Any ideas?
.recent_view_prod ul.product_list_widget li {
width: 22%;
margin-right: 2%;
}
.recent_view_prod ul.product_list_widget li img {
width: 100%;
float: left;
}
.recent_view_prod ul.product_list_widget li {
display: inline-block;
}
.recent_view_prod span.product-title {
display: none;
}
.product_list_widget ul li .attachment-shop_thumbnail:hover span.product_title {
display: block!important;
z-index: 100;
position: absolute;
font-size: 1vw;
line-height: 1.5em;
text-align: left;
padding-left: .5em!important;
padding-right: .5em!important;
color: white;
background-color: rgba(160, 163, 162, 0.8);
left: 0px;
bottom: 25px;
width: 75%;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
<div class="wpb_widgetised_column wpb_content_element recent_view_prod">
<div class="wpb_wrapper">
<div id="woocommerce_recently_viewed_products-3" class="widget woocommerce widget_recently_viewed_products">
<h3 class="widget-title element-title">Recently Viewed Products</h3>
<ul class="product_list_widget">
<li>
<a href="http://uc.petekirkwood.co.uk/shop/opulent-bloom-card-holder/" title="Opulent Bloom Card Holder">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/TedBaker_CardHolderOpulentBloom_2-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="TedBaker_CardHolderOpulentBloom_2"> <span class="product-title">Opulent Bloom Card Holder</span>
</a>
<span class="amount">£19.95</span>
</li>
<li>
<a href="http://uc.petekirkwood.co.uk/shop/store-ms/" title="Store-M's Nesting Food Boxes">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/StoreMs1-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="StoreMs1"> <span class="product-title">Store-M's Nesting Food Boxes</span>
</a>
<span class="amount">£11.95</span>
</li>
<li>
<a href="http://uc.petekirkwood.co.uk/shop/happy-jackson-crackers-tin/" title="Happy Jackson Crackers Tin">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/HappyJCrackersTIn-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="HappyJCrackersTIn"> <span class="product-title">Happy Jackson Crackers Tin</span>
</a>
<span class="amount">£6.99</span>
</li>
<li>
<a href="http://uc.petekirkwood.co.uk/shop/happy-jackson-snack-box-set/" title="Happy Jackson Snack Box Set">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/SnackBoxSetx4_2-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="SnackBoxSetx4_2"> <span class="product-title">Happy Jackson Snack Box Set</span>
</a>
<span class="amount">£9.99</span>
</li>
</ul>
</div>
</div>
</div>
If you want to use css only solution, you could use adjacent selector:
img.attachment-shop_thumbnail.wp-post-image:hover + span {
display: block;
position:absolute;
}
This targets element immediately after your img element, and you don't need to know the class of your span for that.
Only requirement, you'll need to stick to, is that span has to be immediately after imgin your markup.
Another alternative might be sibling combinator selector:
img.attachment-shop_thumbnail.wp-post-image:hover ~ span {
display: block;
position:absolute;
}
which only require your span element to be after img but not necessary immediately.
Here is the JSFiddle with that.
You should use following selector:
ul.product_list_widget li .attachment-shop_thumbnail:hover span.product-title {
//styles as above
}
Your <ul> tag has class "product_list_widget" so following selector:
.product_list_widget ul li .attachment-shop_thumbnail:hover + span.product-title
wouldn't work, because that would require <ul> to be inside element that has class "product_list_widget".
I have two overlapping backgrounds with absolute positioning and I'm trying to styling them such that they overlap and one is on top of the other. This is the CSS I wrote so far.
.answered {
position: absolute;
top: 0;
}
.asked {
position: absolute;
top: 0;
}
h1{
display: block;
position: relative;
width: 120px;
border-radius: 5px 5px 0px 0px;
border: 1px solid black;
}
.in-back {
display: block;
background: grey;
z-index: -1;
}
.in-front {
display: block;
z-index: 1;
background: tan;
}
<section class="history">
<div class="asked">
<h1 class="user-show-tab-title in-front">Questions</h1>
<div>
<ul class="question-index-false in-front">
<li>
<a class="question" href="http://localhost:3000/#questions/1">what train runs faster from wycoff?</a>
</li>
<li>
<a class="question" href="http://localhost:3000/#questions/5">What is the history of the Block Island Ferry?</a>
</li>
<li>
<a class="question" href="http://localhost:3000/#questions/78">What are the major human features in New York City?</a>
</li>
<li>
<a class="question" href="http://localhost:3000/#questions/199">How much do greyhound bus tickets from California to Phoenix Arizona?</a>
</li>
</ul>
</div>
</div>
<div class="answered">
<h1 class="user-show-tab-title in-back">Answers</h1>
<div>
<ul class="question-index-false in-back">
<li>
<a class="question" href="http://localhost:3000/#questions/129">What is the state bird of New York?</a>
</li>
</ul>
</div>
</div>
</section>
The grey keeps appearing on top of the tan even though its z-index is lower. I don't understand why.
The elements are not positioned absolute, only their parents .asked and .answered. The position property is not inherited by child elements. Both <ul> have the default position: static; which is always applied unless you specify a different value for the position property. So adding position: relative; makes your z-index way work the way you expect.
.answered {
position: absolute;
top: 0;
}
.asked {
position: absolute;
top: 0;
}
h1 {
display: block;
position: relative;
width: 120px;
border-radius: 5px 5px 0px 0px;
border: 1px solid black;
}
.in-back {
display: block;
background: grey;
position: relative;
z-index: -1;
}
.in-front {
display: block;
z-index: 1;
position: relative;
background: tan;
}
<section class="history">
<div class="asked">
<h1 class="user-show-tab-title in-front">Questions</h1>
<div>
<ul class="question-index-false in-front">
<li>
<a class="question" href="http://localhost:3000/#questions/1">what train runs faster from wycoff?</a>
</li>
<li>
<a class="question" href="http://localhost:3000/#questions/5">What is the history of the Block Island Ferry?</a>
</li>
<li>
<a class="question" href="http://localhost:3000/#questions/78">What are the major human features in New York City?</a>
</li>
<li>
<a class="question" href="http://localhost:3000/#questions/199">How much do greyhound bus tickets from California to Phoenix Arizona?</a>
</li>
</ul>
</div>
</div>
<div class="answered">
<h1 class="user-show-tab-title in-back">Answers</h1>
<div>
<ul class="question-index-false in-back">
<li>
<a class="question" href="http://localhost:3000/#questions/129">What is the state bird of New York?</a>
</li>
</ul>
</div>
</div>
</section>
Below is my code:
#sam_ul li {
height: 41px;
border-bottom: 1pt solid #DEDEDE;
background-color: #F8F8F8;
}
#sam_ul li {
list-style-type: none;
}
#u_l_add:before {
content: '\0FBF';
}
<ul id="sam_ul" style="margin:0px;">
<li>
<a href="#">
<span id="u_l_add" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Add</div>
</a>
</li>
<li>
<a href="#">
<span id="u_l_sear" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Search Artifact</div>
</a>
</li>
</ul>
The content pseudo element is displayed differently in both IE and mozilla. By different I mean in IE it is displaying correctly while in mozilla it is adding some extra padding and displaying the content.
check the difference between the first li element and the second li element.
Can anyone help me with this?
Add padding:0 to unordered list
#sam_ul{
padding:0
}
#sam_ul li {
height: 41px;
border-bottom: 1pt solid #DEDEDE;
background-color: #F8F8F8;
list-style-type: none;
}
#u_l_add:before {
content: '\0FBF'; }
#u_l_sear:before {
content: '\0FBF'; }
<body>
<ul id="sam_ul" style="margin:0px;">
<li>
<a href="#">
<span id="u_l_add" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Add</div>
</a>
</li>
<li>
<a href="#">
<span id="u_l_sear" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Search Artifact</div>
</a>
</li>
</ul>
</body>
Try to normalize everything. HTML and body has default margin and padding for every browser that could ruin your design. Almost all block elements has that.
Try:
html,body{
margin: 0;
padding:0;
}
Or download and add normalize.css