I have a div positioned absolutely and then a ul element inside it. For some ul is not taking margin: 0 as default.
* {
box-sizing: padding-box;
display: block;
}
.userinfo {
position: relative;
width: 500px;
height: 500px;
border: 1px solid red;
cursor: default;
}
.userinfo .sprite {
position: absolute;
width: 50px;
height: 35px;
right: 21px;
bottom: 8px;
border: 1px solid red;
}
.userinfo .sprite ul {
position: absolute;
width: 42px;
height: 15px;
left: 0;
top: 0;
border: 1px solid red;
}
.userinfo .sprite ul .themes {
position: absolute;
width: 13px;
height: 14px;
left: 0;
top: 0;
background: url("http://www.w3schools.com/css/img_navsprites.gif") -23px 0;
cursor: pointer;
border: 1px solid red;
overflow: hidden;
}
.userinfo .sprite ul .user_lang {
position: absolute;
width: 20px;
height: 12px;
right: 0;
top: 0;
background: url("http://www.w3schools.com/css/img_navsprites.gif") -23px 0;
cursor: pointer;
border: 1px solid red;
overflow: hidden;
}
<a class="userinfo" href="#">
<div class="sprite">
<ul>
<li class="themes"></li>
<li class="user_lang"></li>
</ul>
</div>
</a>
My question is, why is margin for ul element not 0?
Margins are defined by default, unless specified, by your browser.
For example here is the webkit default styling: Default webkit styling
What you need to do in order to fix that is to explicitly declare the margins to a value of 0px.
Also something like this CSS snippet might help you getting all that sorted.
By default Ul has margin and padding you need to reset it
* {
box-sizing: padding-box;
display: block;
}
.userinfo {
position: relative;
width: 500px;
height: 500px;
border: 1px solid red;
cursor: default;
}
.userinfo .sprite {
position: absolute;
width: 50px;
height: 35px;
right: 21px;
bottom: 8px;
border: 1px solid red;
}
.userinfo .sprite ul {
position: absolute;
width: 42px;
height: 15px;
left: 0;
top: 0;
margin: 0;
padding: 0;
border: 1px solid red;
}
.userinfo .sprite ul .themes {
position: absolute;
width: 13px;
height: 14px;
left: 0;
top: 0;
background: url("http://www.w3schools.com/css/img_navsprites.gif") -23px 0;
cursor: pointer;
border: 1px solid red;
overflow: hidden;
}
.userinfo .sprite ul .user_lang {
position: absolute;
width: 20px;
height: 12px;
right: 0;
top: 0;
background: url("http://www.w3schools.com/css/img_navsprites.gif") -23px 0;
cursor: pointer;
border: 1px solid red;
overflow: hidden;
}
<a class="userinfo" href="#">
<div class="sprite">
<ul>
<li class="themes"></li>
<li class="user_lang"></li>
</ul>
</div>
</a>
Related
I made a curved tab list and everything looks good, but the problem is in some resolutions it break position about one pixel, I really want know why this happen technically? and how can I avoid this?
#tabs ul li {
display: inline-block;
padding: 0 10px 0 10px;
border: 1px solid gray;
border-bottom: none;
border-radius: 10px 10px 0 0;
height: 40px;
position: relative;
line-height: 40px;
top: 5px;
margin: 0 -5px 0 0;
min-width: 100px;
}
.active {
border: 1px solid #0061ff !important;
height: 50px !important;
line-height: 50px !important;
border-bottom: none !important;
top: 0px !important;
}
#tabcontent {
width: 200px;
height: 200px;
}
#tab {
border: 1px solid #0061ff;
margin-top: 75px;
border-radius: 10px;
}
#tabs {
margin-top: -68px;
}
.invRadTab1 {
width: 35px;
height: 10px;
background: white;
position: absolute;
bottom: -3px;
left: -33px;
z-index: 9999999;
overflow: hidden;
}
.invRadTab2 {
width: 35px;
height: 10px;
background: white;
position: absolute;
bottom: -3px;
right: -33px;
z-index: 9999999;
overflow: hidden;
}
.invRadTab1 span {
width: 60px;
height: 20px;
background: #fff;
position: absolute;
bottom: 2px;
right: 2px;
border: 1px solid #0061ff;
border-radius: 0 0 10px 0;
border-top: none;
border-left: none;
position: absolute;
}
.invRadTab2 span {
width: 60px;
height: 20px;
background: #fff;
position: absolute;
bottom: 2px;
left: 2px;
border: 1px solid #0061ff;
border-radius: 0 10px 0 10px;
border-top: none;
border-right: none;
position: absolute;
}
li.active::after {
content: "";
display: block;
width: 100%;
height: 2px;
background: white;
position: absolute;
bottom: -2px;
left: 0;
}
<div id="tab">
<div id="tabs">
<ul>
<li><a>Tab 2</a></li>
<li class="active"><a>Tab 1</a><span class="invRadTab1"><span></span></span><span class="invRadTab2"><span></span></span>
</li>
<li><a>Tab 3</a></li>
<li><a>Tab 4</a></li>
</ul>
</div>
<div id="tabcontent">
some content
</div>
</div>
If you want to see this problem, you should run this snippet in full page and zoom in or zoom out (for me on 125% and 90%), my screen is 1920 and another machine is 1366, I don't see any problem in 1920 resolution, but see this break in 1366 resolution also in another screens. how can I fix this issue?
I have a container which holds an image and a panel the appears when you hover over that image. I am trying to get the box shadow on the panel to appear behind the image, while the rest of the panel overlaps the image.
What I have vs. What I'd like to have
HTML:
<div class="container">
<img class="icon" src="http://placehold.it/350x350" />
<div class="sum-container left">
<img src="http://placehold.it/350x150" />
</div>
</div>
CSS:
.container .sum-container {
position: absolute;
top: 0;
bottom: 0;
border: solid 5px blue;
background-color: white;
width: 250px;
height: 200px;
max-height: 100%;
opacity: 0;
overflow: hidden;
z-index: 5;
pointer-events: none;
transition-property: opacity;
transition-duration: .250s;
}
.container .sum-container.left {
right: 100%;
margin-right: -5px;
border-right: none;
padding-right: 0px;
box-shadow: 5px 5px 0px #888888;
}
.container .icon:hover + .sum-container {
z-index: 6;
opacity: 1;
}
.container {
position: absolute;
left: 300px;
top: 20px;
}
.container img {
width: 100%;
}
.icon {
margin-left: auto;
margin-right: auto;
display: block;
width: 100%;
height: auto;
max-width: 480px;
background-color: blue;
box-shadow: 5px 5px 0px #888888;
text-align: center;
font-size: 26px;
color: white;
text-decoration: none;
padding: 5px;
cursor: pointer;
border: none;
outline: none;
user-drag: none;
}
I've included a JSFiddle as well.
Also, still new here. If anyone can suggest a better title, please let me know. I realize you can't actually set multiple z-indexes for one element, but I'm looking for a solution with a similar effect.
If I understand the end goal, you can make the shadow a pseudo element with a negative z-index and remove the z-index from .sum-container and .sum-container will be over .icon and it's pseudo element will be under both of them.
.container .sum-container {
position: absolute;
top: 0;
bottom: 0;
border: solid 5px blue;
background-color: white;
width: 250px;
height: 200px;
max-height: 100%;
opacity: 1;
pointer-events: none;
transition-property: opacity;
transition-duration: .250s;
}
.sum-container:after {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
content: '';
background: #888;
transform: translate(0,10px);
z-index: -1;
}
.container .sum-container.left {
right: 100%;
margin-right: -5px;
border-right: none;
padding-right: 0px;
}
.container .icon:hover + .sum-container {
opacity: 1;
}
.container {
position: absolute;
left: 300px;
top: 20px;
}
.container img {
width: 100%;
}
.icon {
margin-left: auto;
margin-right: auto;
display: block;
width: 100%;
height: auto;
max-width: 480px;
background-color: blue;
box-shadow: 5px 5px 0px #888888;
text-align: center;
font-size: 26px;
color: white;
text-decoration: none;
padding: 5px;
cursor: pointer;
border: none;
outline: none;
user-drag: none;
}
<div class="container">
<img class="icon" src="http://placehold.it/350x350" />
<div class="sum-container left">
<img src="http://placehold.it/350x150" />
</div>
</div>
I am trying to design a octagon with texts stuffed inside. But somehow the text is not showing. Please help!
HTML
<div class = "octagon">This is some text</div>
CSS
.octagon
{
width: 134px;
height: 100px;
background: #40174F;
position: relative;
color:white;
}
.octagon::before
{
content: "";
position: absolute;
top: 0;
left: 0;
border-bottom: 25px solid #40174F;
border-left: 25px solid #fff;
border-right: 25px solid #fff;
width: 84px;
height: 0;
color:white;
}
.octagon::after
{
content: "";
position: absolute;
bottom: 0;
left: 0; border-top: 25px solid #40174F; border-left: 25px solid #fff; border-right: 25px solid #fff; width: 84px; height: 0;
color:white;
}
The text inside the div is not showing.
Add line-height and text-align in .octagon class
.octagon {
width: 134px;
height: 100px;
background: #40174F;
position: relative;
color: white;
line-height: 6;
text-align: center;
}
How can you create two triangles next to an image?
As you can see in the jsfiddle, the triangles are not tounching the image. I want them to touch the image and the blue bar above.
I tried this post: How can I have an image float next to a centered div? didn't work.
.content {
width: 960px;
margin: 0 auto;
}
ul.producten {
margin-top: 4%;
list-style-type: none;
}
ul.producten li {
width: 315px;
}
ul.producten li img {
display: inline-block;
width: 295px;
}
.producten_top {
width: 315px;
height: 40px;
background: #3bcdff;
}
.producten_top h1 {
font-size: 30px;
color: #fff;
text-align: center;
padding: 5px 0;
}
.arrow_left {
display: inline-block;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #1c1c1d;
transform: rotate(225deg);
float: left;
}
.arrow_right {
display: inline-block;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #1c1c1d;
transform: rotate(315deg);
float: right;
}
<div class="content">
<ul class="producten">
<li>
<div class="producten_top"><h1>Test</h1></div>
<div class="arrow_left"></div>
<img src="http://assets.worldwildlife.org/photos/144/images/hero_small/Giant_Panda_Hero_image_(c)_Michel_Gunther_WWF_Canon.jpg?1345515244" alt="Plafond lampen">
<div class="arrow_right"></div>
</li>
</ul>
</div>
jsfiddle
what it needs to be:
Use position: absolute instead of display: inline-block and give 8px border for triangles instead of 5px and set display: block and margin: auto for make img center. of course you need to set position: relative; for parent (ul.producten li).
.content {
width: 960px;
margin: auto;
}
ul.producten {
margin-top: 4%;
list-style-type: none;
}
ul.producten li {
width: 315px;
position: relative;
}
ul.producten li img {
display: block;
width: 295px;
margin: auto;
}
.producten_top {
width: 315px;
height: 40px;
background: #3bcdff;
}
.producten_top h1 {
font-size: 30px;
color: #fff;
text-align: center;
padding: 5px 0;
}
.arrow_left {
width: 0;
height: 0;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-top: 8px solid #1c1c1d;
transform: rotate(225deg);
position: absolute;
left: 0;
top: 39px;
}
.arrow_right {
width: 0;
height: 0;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 8px solid #1c1c1d;
transform: rotate(315deg);
position: absolute;
right: 0;
top: 39px;
}
<div class="content">
<ul class="producten">
<li>
<div class="producten_top"><h1>Test</h1></div>
<div class="arrow_left"></div>
<div class="arrow_right"></div>
<img src="http://assets.worldwildlife.org/photos/144/images/hero_small/Giant_Panda_Hero_image_(c)_Michel_Gunther_WWF_Canon.jpg?1345515244" alt="Plafond lampen">
</li>
</ul>
</div>
This technique makes a square div with a linear gradient alpha background that resembles a triangle. As a bonus, by adjusting the distance between alpha=1 and alpha=0 (the percentages) in the gradients you can change the anti-aliasing of the diagonal line (the left arrow has more anti-aliasing in this example).
.content {
width: 960px;
margin: 0 auto;
}
ul.producten {
margin-top: 4%;
list-style-type: none;
}
ul.producten li {
width: 315px;
position: relative;
}
ul.producten li img {
display: block;
width: 295px;
margin: auto;
}
.producten_top {
width: 315px;
height: 40px;
background: #3bcdff;
}
.producten_top h1 {
font-size: 30px;
color: #fff;
text-align: center;
padding: 5px 0;
}
.arrow_left {
width: 10px;
height: 10px;
background: linear-gradient(225deg, rgba(28,28,29,1) 44%,rgba(28,28,29,0) 56%);
position: absolute;
left: 0;
top: 40px;
}
.arrow_right {
width: 10px;
height: 10px;
background: linear-gradient(135deg, rgba(28,28,29,1) 48%,rgba(28,28,29,0) 50%);
position: absolute;
right: 0;
top: 40px;
}
<div class="content">
<ul class="producten">
<li>
<div class="producten_top"><h1>Test</h1></div>
<div class="arrow_left"></div>
<div class="arrow_right"></div>
<img src="http://assets.worldwildlife.org/photos/144/images/hero_small/Giant_Panda_Hero_image_(c)_Michel_Gunther_WWF_Canon.jpg?1345515244" alt="Plafond lampen">
</li>
</ul>
</div>
I have modified your css. The changes I made are:
Set the same width for the blue header and image
Set position fixed for image and right arrow
Set the arrows degrees values in negative
Check it out...
<html>
<head>
<style>
.content {
width: 960px;
margin: 0 auto;
}
ul.producten {
margin-top: 4%;
list-style-type: none;
}
ul.producten li {
width: 315px;
}
ul.producten li img {
display: inline-block;
width: 315px;
position: fixed;
}
.producten_top {
width: 315px;
height: 40px;
background: #3bcdff;
}
.producten_top h1 {
font-size: 30px;
color: #fff;
text-align: center;
padding: 5px 0;
}
.arrow_left {
display: inline-block;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #1c1c1d;
transform: rotate(-225deg);
float: left;
position: fixed;
}
.arrow_right {
display: inline-block;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #1c1c1d;
transform: rotate(-315deg);
float: right;
}
</style>
</head>
<body></body>
</html>
I want the border div to be "hidden" behind the circle and not cross through it. I thought z-index was the way to do things like this.
Any ideas?
JSFIDDLE: http://jsfiddle.net/qs5xmege/1/
CSS and HTML
.container {
width: 15%;
height: 100px;
float: left;
position: relative;
}
.circle {
width:22px;
height:22px;
border-radius:11px;
border: 3px solid red;
background-color: #FFF;
margin: 30px auto 0 auto;
z-index: 100;
}
.border {
width: 50%;
height: 100px;
position: absolute;
border-right: thin solid black;
top: 0;
left: 0;
z-index: 1;
}
<div class="container">
<div class="border"></div>
<div class="circle"></div>
</div>
Give .circle a position:relative, z-index works only with position:relative, position:absolute or position: fixed
.container {
width: 15%;
height: 100px;
float: left;
position: relative;
}
.circle {
width:22px;
height:22px;
border-radius:11px;
border: 3px solid red;
background-color: #FFF;
margin: 30px auto 0 auto;
position: relative;
z-index: 100;
}
.border {
width: 50%;
height: 100px;
position: absolute;
border-right: thin solid black;
top: 0;
left: 0;
z-index: 1;
}
<div class="container">
<div class="border"></div>
<div class="circle"></div>
</div>
Add position:relative; to .circle.
z-index need relative, absolute or fixed vaue for position.
Set position:relative of div circle and z-index:2 ie. 1 more than border is enough
.circle {
background-color: #FFFFFF;
border: 3px solid #FF0000;
border-radius: 11px;
height: 22px;
margin: 30px auto 0;
position: relative;
width: 22px;
z-index: 2;
}
Snippet
.container {
width: 15%;
height: 100px;
float: left;
position: relative;
}
.circle {
background-color: #FFFFFF;
border: 3px solid #FF0000;
border-radius: 11px;
height: 22px;
margin: 30px auto 0;
position: relative;
width: 22px;
z-index: 2;
}
.border {
width: 50%;
height: 100px;
position: absolute;
border-right: thin solid black;
top: 0;
left: 0;
z-index: 1;
}
<div class="container">
<div class="border"></div>
<div class="circle"></div>
</div>
Try like this:
.circle {
background-color: #fff;
border: 3px solid red;
border-radius: 11px;
display: block;
height: 22px;
margin: 0 auto;
position: relative;
top: -68px;
width: 22px;
}
.border {
border-right: thin solid black;
height: 100px;
width: 50%;
}