I'm trying to enlarge my list-item borders when hovered, but when I do, it shifts the other icons down.
My thought was to use position: absolute on the parent and position: relative on the li or image, but the other list-items/images are still being affected.
jsFiddle: http://jsfiddle.net/2e07Lv9y/2/
HTML:
<div class="container">
<ul class="social">
<li><img src="http://placehold.it/36x36"/></li>
<li><img src="http://placehold.it/36x36"/></li>
<li><img src="http://placehold.it/36x36"/></li>
<li><img src="http://placehold.it/36x36"/></li>
<li><img src="http://placehold.it/36x36"/></li>
</ul>
</div>
CSS:
.container {
background-color: rgb(54, 129, 245);
height: 75px;
}
.social {
width: 50%;
margin: 3%;
position: absolute;
right: 0;
}
li {
list-style: none;
display: inline-block;
margin: 0 1%;
}
img {
border: 2px white solid;
}
li:hover {
cursor: pointer;
border: 5px white solid;
position: relative;
}
What am I missing?
You could use outline instead of border. Outlinke behaves similar to border, but it is not part of the elements dimensions.
see: http://www.w3schools.com/css/css_outline.asp
li:hover {
cursor: pointer;
outline: 5px white solid;
position: relative;
}
Fiddle: http://jsfiddle.net/2e07Lv9y/7/
You are adding a border 5px wide when you hover.
You need to add a border 5px wide when not hover so that they are only changing the background colour. Something along the lines of:
li {
list-style: none;
display: inline-block;
margin: 0 1%;
border:5px solid rgb(54, 129, 245);
}
Updated DEMO
You may need to adjust the height, position, of the li
Problem is that on :hover li that display inline block, have more width including border. if you won't shifts down you need change .social width to more than 50% or place elements via text-align: right.
Add
padding: 5px;
to the normal li
and
padding: 0px;
to the li:hover
Related
I want the price of coffee to come at the right end of the coffee name i.e 1.80 price should come in line of Americano. Similarly 10.00 price should come in line of Macchiato.
ul {
list-style: none;
padding: 5px;
margin: 0;
}
ul#container {
width: 18%;
min-width: 100px;
max-width: 400px;
border: 15px solid #886633;
border-radius: 5px;
background-color: orange;
box-shadow: 4px 4px 8px rgba(0, 0, 0, .3);
}
#container li {
border-bottom: 1px dashed blue;
}
#container > li {
font-size: 2em;
border-bottom: 1px solid black;
}
em {
float: right;
position: relative;
bottom: 0px;
}
span {
width: 100px;
display: inline-block;
}
<ul id="container">
<li>DRINK MENU
<ul>
<li><span>Latte</span><em>2.79</em>
</li>
<li><span>Cappucino</span><em>2.99</em>
</li>
<li><span>Cafe Americano</span><em>1.80</em>
</li>
<li><span>Espresso</span><em>2.00</em>
</li>
<li><span>Carmel Macchiato</span><em>10.00</em>
</li>
</ul>
</li>
</ul>
As you can see i am using relative position, but its not working.
Can you solve this without absolute position and minimum changes to the code?
Just tell me why is relative position not working.
First you need to fix your html - the closing li for the DRINK MENU should be after the nested ul.
Then I would make use of display:table css:
ul {
list-style: none;
padding: 0;
margin: 0;
}
ul#container {
width: 18%;
min-width: 100px;
max-width: 400px;
border: 15px solid #886633;
border-radius: 5px;
background-color: orange;
box-shadow: 4px 4px 8px rgba(0, 0, 0, .3);
}
#container > li {
padding: 5px;
}
#container ul {
border-top: 1px solid black;
margin-top: 5px;
}
#container ul li {
border-bottom: 1px dashed blue;
display: table;
width: 100%;
}
#container span,
#container em {
display: table-cell;
vertical-align: bottom;
padding: 3px 0;
}
#container em {
text-align: right;
}
<ul id="container">
<li>DRINK MENU
<ul>
<li><span>Latte</span><em>2.79</em>
</li>
<li><span>Cappucino</span><em>2.99</em>
</li>
<li><span>Cafe Americano</span><em>1.80</em>
</li>
<li><span>Espresso</span><em>2.00</em>
</li>
<li><span>Carmel Macchiato</span><em>10.00</em>
</li>
</ul>
</li>
</ul>
UPDATE
As per your comments about overflow. There are a couple of ways to fix this:
Increase the min width of ul#container to something that will accommodate the longest line - in this case a width of 125px should suffice: Fiddle example
Add table-layout:fixed to your table li and add word-wrap:break-word to the span: Fiddle example
You can add a class to the <em>
HTML
<ul id="container">
<li>DRINK MENU</li>
<ul>
<li><span>Latte</span><em>2.79</em></li>
<li><span>Cappucino</span><em>2.99</em></li>
<li><span>Cafe Americano</span><em class="bottom">1.80</em></li>
<li><span>Espresso</span><em>2.00</em></li>
<li><span>Carmel Macchiato</span><em class="bottom">10.00</em></li>
</ul>
</ul>
CSS:
ul{
list-style: none;
padding: 5px;
margin: 0;
}
ul#container{
width: 18%;
min-width: 200px ;
max-width: 400px;
border: 15px solid #886633;
border-radius: 5px;
background-color: orange ;
box-shadow: 4px 4px 8px rgba(0,0,0,.3);
}
#container li{
border-bottom: 1px dashed blue;
}
#container > li{
font-size: 2em;
border-bottom: 1px solid black;
}
em{
float: right;
position: relative;
bottom: 0px;
}
.bottom {
position: relative;
top:15px;
}
span{
width: 100px;
display: inline-block ;
}
DEMO
Another posible solution (maybe the best practice):
CSS:
li:nth-child(3) > em, li:nth-child(5) > em{
position: relative;
top:16px;
}
DEMO
Along with your questions, I've taken your comments into consideration in preparing this answer.
First, your HTML was invalid. The list was nested improperly so I corrected that that in my answer.
In answer to your first question...
how to position the prices at the baseline
... absolute positioning will work and will not prevent your price card from adjusting to different browsers, platforms or devices. It will be as responsive as the container it is in. Of course, you should test your code to make sure it works as intended.
Note that for position: absolute to work properly you must set the parent element to position: relative. This is because absolute positioning will move the element – in this case the em – relative to its closest positioned ancestor (which in this case should be the li). If the absolutely positioned element doesn't find a positioned ancestor, it will position the element relative to the <body>. So bottom line:
To absolutely position a child element, set the parent element to position: relative.
Here's an example using your code.
DEMO
HTML
<!-- with corrections to improperly nested list -->
<div id="container">
<h2>DRINK MENU</h2>
<ul>
<li><span>Latte</span><em>2.79</em></li>
<li><span>Cappucino</span><em>2.99</em></li>
<li><span>Cafe Americano more text more text more text more text</span>
<em>1.80</em></li>
<li><span>Espresso</span><em>2.00</em></li>
<li><span>Carmel Macchiato more text more text more text more text</span>
<em>10.00</em></li>
</ul>
</div>
CSS
/* based on your original code */
#container {
width: 200px;
border: 15px solid #886633;
background-color: orange;
box-shadow: 4px 4px 8px rgba(0, 0, 0, .3);
padding: 5px;
}
h2 {
width: 99%;
border-bottom: 1px solid black;
margin: 0;
}
ul {
list-style: none;
padding: 5px;
margin: 0;
}
#container ul li {
font-size: 1em;
font-weight: bold;
border-bottom: 1px dashed blue;
position: relative;
}
span {
width: 100px;
display: inline-block;
}
em {
position: absolute;
bottom: 0;
right: 0;
}
In answer to your second question...
Just tell me why is relative position not working.
Actually, it's working fine. In the normal flow of things, it's positioned exactly where it belongs. Your descriptions are breaking to a new line because of the margin limitation you set in your span.
That being said, the em can still be positioned with position: relative. Change the value from 0. Your prices will (as defined by your style rule) move up or down as a group, depending on whether you use positive or negative numbers.
Your CSS rule:
em {
float: right;
position: relative;
bottom: 0px;
/* test these individually:
bottom: 25px;
bottom: -25px;
right: 25px;
right: -25px */
}
For more about positioning see the position article at MDN.
This is css for an unordered-list with the id "leftmenu"
#leftmenu ul li{
list-style:none;
padding:15px 0 8px 0;
border-bottom:1px dashed white;
float:left;
clear:both;
The problem is the border only goes as far as the text go. see:http://imgur.com/dhx2OKk
I want it to be like that border under "Links"
The problem is that your list-items should be displayed as regular block items. These would always scale to the full width of any container. For a <li> element that is actually the default behavior.
By setting float: left; to the <li> items, alter this behavior. The following code would achieve what you are after (also check the JS fiddle)
* {
margin: 0;
padding: 0;
}
h4 {
border-bottom: 1px solid black;
}
.menu {
width: 200px;
}
.menu>ul {
list-style-type: none;
}
.menu>ul>li {
margin-top:10px;
border-bottom: 1px dotted black;
}
http://jsfiddle.net/fhckxene/
edit: for fun play round with the jsfiddle, for example by adding float: left; or display: inline-block; to the <li> style.
I want to contain the teal hover within the borders of my social media links. I’ve tried adjusting the padding and heights and widths via CSS properties but when hovering, it still overlaps over the right border.
This is what it looks like while not hovering:
This is what it looks like when hovering:
The image sizes are each 19px × 15px.
#box {
width: 200px;
height: 50px;
background-clip: padding-box;
position: relative;
margin: 0;
left: 1.4em;
background: rgba(0, 0, 0, 1);
float: right;
z-index: 200;
}
#boxlist li {
height: 50px;
width: 20px;
position: relative;
list-style-type: none;
display: inline-block;
bottom: 1em;
margin-left: -2.5em;
float: left;
}
.imgli:hover {
background: rgba(0, 255, 255, 1);
}
.imgli {
border-left: 1px solid rgba(153, 153, 153, 1);
padding-right: 4em;
}
.imgli:first-child {
left: -0.1em;
border: none;
}
.imgli:nth-child(2) {
left: 1em;
}
.imgli:nth-child(3) {
left: 2em;
}
<header>
<div id="box">
<ul id="boxlist">
<li class="imgli"><img src="images/banner-social-icon-twitter.png" class="boximg"></li>
<li class="imgli"><img src="images/banner-social-icon-facebook.png" class="boximg"></li>
<li class="imgli"><img src="images/banner-social-icon-email.png" class="boximg"></li>
</ul>
</div>
</header>
The overlapping is happening, I believe, because of the
margin-left:-2.5em combined with the fixed width of the container, you are still experiencing overlap, despite the fact that your elements are floating.
Without doing a detailed lookover of your layout, one solution is to apply a background color to your <li>s to prevent the overlap, see the update I made to your fiddle:
http://jsfiddle.net/VVj3R/1/
I just added the background line to .imgli's definition and it seems to work.
.imgli {
border-left: 1px solid rgba(153,153,153,1);
padding-right:4em;
background-color:black;
}
You may want to change black to something else, as long as its an opaque color.
PS the images didn't show up in your fiddle because you used relative path names.
Try making your code bit simpler.. like this:
<div id="box">
<ul>
<li><div class="button" id="btn1"></div></li>
<li><div class="button" id="btn2"></div></li>
<li><div class="button" id="btn3"></div></li>
</ul>
</div>
CSS:
#box ul {
margin: 20px;
padding: 0px;
}
#box li {
float: left;
display: block;
background: #ededed;
padding: 1px;
}
#box .button {
width: 50px;
height: 50px;
background-color: #000;
}
#box .button:hover {
background-color:rgba(0,255,255,1);
}
#btn1 {
background-image: url(someicon.png);
background-repeat: no-repeat;
background-position: center center;
background-size: 40px 40px;
}
Here is fiddle:
http://jsfiddle.net/tb2Ug/
I'm trying to put some triangles made in css next to containers,
one over the container in white (imitating the background)
and one in blue on the right side.
I tried several solutions, but by using absolute positioning of triangles, when I add an element above the absolutely positioned triangles it breaks their positioning. I also tried the triangles with :after and :before, and using clear for the container, but this did not work.
CSS:
#sortables {
padding: 15px;
}
.sortable {
list-style-type: none;
background-color: #d2e0f2;
padding: 5px;
}
.sortable li {
margin: 5px;
padding: 3px;
}
.sortable li:hover {
cursor: move
}
ul{
margin:0;
}
.dimensions_container {
float: left;
display: block;
position: relative;
width: 160px;
margin:10px;
}
.triangle-right{
content: '';
display: block;
position: absolute;
top: 10px;
left: 170px;
width: 0;
height: 0;
border-color: transparent transparent transparent #d2e0f2;
border-style: solid;
border-width: 17px;
}
.triangle-left{
content: '';
display: block;
position: absolute;
top: 1px;
left: 25px;
width: 0;
height: 0;
border-color: transparent transparent transparent white;
border-style: solid;
border-width: 17px;
}
.header {
text-align:center;
padding: 3px;
width: 154px;
background-color: #d2e0f2;
}
HTML:
<div id="sortables">
<div class="dimensions_container">
<div class="header">Available groups</div>
<ul id="sortable1" class="sortable droptrue ui-sortable">
<li id="undefined" class="ui-state-default">undefined</li>
<li id="undefined" class="ui-state-default">undefined</li>
<li id="undefined" class="ui-state-default">undefined</li>
</ul>
</div>
<div class="triangle-right"></div>
<div class="dimensions_container">
<div class="header">Grouped by</div>
<ul id="sortable2" class="sortable droptrue ui-sortable"></ul>
</div>
<div class="triangle-left"></div>
<div class="dimensions_container">
<div class="header">Drill into</div>
<ul id="sortable3" class="sortable droptrue ui-sortable"></ul>
</div>
</div>
Here you go. You'll find the code in this jsFiddle: http://jsfiddle.net/xKzuX/
When using css arrows, it is better to use :before and :after pseudo selector on the parent with a position: relative on it (you had that part).
Then you absolute position the arrow (you had that part too but with wrong values).
To make it easy to reuse, I've reused your left/right classes. You can just add it wherever needed.
Finally, if your arrows render poorly in some browser, add transform:rotate(360deg); which make it do 360deg (so you won't notice the rotation at all) but it softens the edges.
You might need to use
position:relative
on the parent of your triangles (#sortables here).
I just need a little help with my CSS:
I As you can see in here http://jsfiddle.net/5crwu/ I have some space between span and ul elements, and I can't find how to lift ul up, closer to the span. I thought margin: 0; will do this, but looks like I'm missing something.
.app-technologies {
width: 200px;
padding-left: 10px;
border: 1px solid black;
}
.app-technologies span {
position: relative;
display: block;
left: 0;
font-size: 17px;
margin: 0;
border: 1px solid black;
}
.app-technologies ul{
list-style: circle;
padding-left: 18px;
margin-top: 0;
border: 1px solid black;
}
If you don't want to remove the <br>, you can give your and NEGATIVE margin. It would be margin:0px 0px -20px 0px;
The negative bottom margin on the span will pull it up.
I just removed the BR after the SPAN, and the "position: relative" from the span styledef. No more space-between.