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`
Related
I have been tasked with styling a website, where I have encountered a hurdle regarding the horizontal alignment of elements inside list items.
I have replicated the structure of the menu in question with this JSFiddle.
I want to know how I can keep the position of the green divs (as shown from the start) when I expand the menu, using the button in the fiddle. I need them to keep horizontal alignment with the first <a> element in their respective <li> element, when the submenus are displayed.
you can do it like this for example:
<html>
<script>
function clickFunction(){
var elements = document.getElementsByClassName("submenu");
for(var i = 0; i < elements.length; i++){
elements[i].classList.toggle("display-sublist");
}
}
</script>
<style>
ul{
list-style-type: none;
margin: 0px;
padding: 0px;
}
ul li{
width: 100%;
background-color: blue;
}
.submenu{
display: none;
}
.display-sublist{
display: block;
}
ul li a{
width: 95%;
background-color: red;
}
.main-test {
display: inline-block;
float: left;
width: 90%;
}
.cancel-test{
display: inline-block;
background-color: green;
float: right;
width: 10%;
}
.expand-button{
clear: both;
display: block;
}
</style>
<body>
<ul>
<li>
<a class="main-test" href="#">Something</a>
<a class="cancel-test">x</div>
<ul class="submenu">
<li>
Sub-Something
</li>
<li>
Sub-Something
</li>
<li>
Sub-Something
</li>
</ul>
</li>
<li>
<a class="main-test"href="#">Something</a>
<a class="cancel-test">x</a>
<ul class="submenu">
<li>
Sub-Something
</li>
<li>
Sub-Something
</li>
</ul>
</li>
<li>
Something
</li>
<li>
Something
</li>
</ul>
<button onclick="clickFunction()" class="expand-button">Expand</button>
</body>
</html>
Can someone help me understand how can I vertical align this?
JSFIDDLE
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/2.0.46/css/materialdesignicons.css"
></link>
<aside class="menu column is-2 full-height">
<ul class="menu-list">
<li>
<a href="#" class="">
<i class="mdi mdi-file-document-box mdi-48px"></i>
<span>Document</span>
</a>
</li>
<li>
<a href="#" class="">
<i class="mdi mdi-file-document-box mdi-48px"></i>
<span>Document</span>
</a>
</li>
</ul>
</aside>
I need align icon and text next to it?
there is some more css since I'm using bulma.io and something custom but not so relevant I think
You can delete that css and create new one if it is not ok
There's a few options at your disposal, depending on your needs.
Updated jsFiddle
Use display: inline-block; on the element(s) that are next to each other and need to be aligned. Then you can use vertical-align: [top|middle|baseline] as needed for each element
i, span {
display: inline-block;
vertical-align: middle;
}
If that alignment doesn't work for you, then you should set the vertical-align to top, to get them positioned how you like, and then you can use line-height to fine-tune the vertical positioning of each element. Example:
i, span {
display: inline-block;
vertical-align: top;
}
i {
line-height: 39px;
}
span {
line-height: 39px;
}
You can add display: flex and align-items: center rules to li a
fiddle
aside {
background-color: #0067ad;
height: 100%;
}
li a {
display: flex;
align-items: center;
}
.menu-list {
list-style: none;
}
i {
color: white;
}
a:hover,
a:active,
.router-link-active {
background-color: black;
}
span {
color: white;
}
}
a {
color: white
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/2.0.46/css/materialdesignicons.css" rel="stylesheet"/>
<aside class="menu column is-2 full-height">
<ul class="menu-list">
<li>
<a href="#" class="">
<i class="mdi mdi-file-document-box mdi-48px"></i>
<span>Document</span>
</a>
</li>
<li>
<a href="#" class="">
<i class="mdi mdi-file-document-box mdi-48px"></i>
<span>Document</span>
</a>
</li>
</ul>
</aside>
On my custom shopify site when the main menu is in responsive mode, the links get all wonky and out of line, but only in a short area that seems to be random depending on browser.
Here is how they are supposed to look:
Here is how they look when they are breaking:
According to all of the responsive code, they are set up all the same.
Here is the code:
li a {
display: block;
padding: 7px 10px !important;
text-align: left !important;
}
li ul li:first-child {
display: none !important;
}
li ul li {
font-size: 13px !important;
clear: left !important;
text-align: left !important;
display: block !important;
}
<li class="site-nav--has-dropdown" aria-haspopup="true">
<a href="/pages/studios" class="site-nav__link">
STUDIOS
<span class="icon icon-arrow-down" aria-hidden="true"></span>
</a>
<ul class="site-nav__dropdown">
<div>
<li>
STUDIOS
</li>
<li>
LOCATIONS
</li>
<li>
UPCOMING CLASSES
</li>
<li>
EVENTS
</li>
</div>
<span class="arrow"> </span>
</ul>
</li>
I have a menu icon that when I click on it my list items appear;
but it pushes down other elements. I want to set my z-index to it hasn't any effect on other element. but it doesn't work.
<div class="dropdown hidden-md hidden-lg ">
<ul>
<li>
<div class="dropbtn">
<span class="bar1"></span>
<span class="bar2"></span>
<span class="bar3"></span>
</div>
</li>
<li class="dropdown-content">
<ul>
<li>خانه</li>
<li>توانایی ها</li>
<li> <a href='products.php'>محصولات</a></li>
<li><a href='projects.php'>پروژه ها</a></li>
<li><a href='aboutus.php'>درباره ما</a></li>
<li><a href='contactus.php'>تماس با ما</a></li>
</ul>
</li>
</ul>
</div>
CSS:
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
clear: both;
float: right;
direction: rtl;
background-color: #f9f9f9;
min-width: 75px;
font: 1.2em Yekan;
}
.dropdown {
position: relative;
z-index: 999999999999;
float: right;
text-align: right;
}
JS
$(".dropbtn").on("click",
function() {
$(".dropdown-content").toggle();
}
);
z-index is a relative property that display your index according to the order where you put your element in your page.
<div>here the z-index is equal to 1</div>
<div>here the z-index is equal to 2</div>
If you want to be sure that your z-index is take in consideration you can put an absolute position to your html element but you break the index stack of your element.
For sample in your case if you want to do that your .dropdown is still above all the other element you can do :
.dropdown {
position: absolute;
z-index:999999999999;
float: right;
text-align: right;
}
But it's will also run with a relative element position and in than case you have to be careful of teh impact because you break the "z-index stack". One advice is that case is to set all the z-index of all your element impact by your design.
First, I put your code on embed and add some style to see your btn.
Second, I fix your bug by replacing position:relative by position:absolute
$(".dropbtn").on("click", function(){
$(".dropdown-content").toggle();
});
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display:none;
clear: both;
float: right;
direction: rtl;
background-color: #f9f9f9;
min-width: 75px;
font:1.2em Yekan;
}
.dropdown {
position: absolute;
z-index:999999999999;
float: right;
text-align: right;
}
ul {
list-style-type:none
}
.dropbtn {
cursor:pointer;
}
.bar {
display:block;
height: 4px;
width: 24px;
background: black;
margin-bottom: 5px;
border-radius: 2px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dropdown hidden-md hidden-lg ">
<ul>
<li>
<div class="dropbtn">
<span class="bar1 bar"></span>
<span class="bar2 bar"></span>
<span class="bar3 bar"></span>
</div>
</li>
<li class="dropdown-content">
<ul>
<li>خانه</li>
<li>توانایی ها</li>
<li> <a href='products.php'>محصولات</a></li>
<li><a href='projects.php'>پروژه ها</a></li>
<li><a href='aboutus.php'>درباره ما</a></li>
<li><a href='contactus.php'>تماس با ما</a></li>
</ul>
</li>
</ul>
</div>
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