I'm building a fairly interestingly shaped navigation for a site at the moment. The shape each menu item needs to be is illustrated below:
The final nav will look like an extended version of this:
I thought it would be an interesting experiment to do these shapes in CSS. The CSS and HTML for one of the arrow shapes is here:
.arrowEndOn {
font-size: 10px; line-height: 0%; width: 0px;
border-top: 11px solid #FFFFFF;
border-bottom: 11px solid #FFFFFF;
border-left: 5px solid transparent;
border-right: 5px solid #FFFFFF;
float: left;
cursor: pointer;
}
.arrowBulkOn {
height: 20px;
background: #FFFFFF;
padding: 2px 5px 0px 0px;
float: left;
color: #000000;
line-height: 14pt;
cursor: pointer;
}
.arrowStartOn {
font-size: 0px; line-height: 0%; width: 0px;
border-top: 11px solid transparent;
border-bottom: 11px solid transparent;
border-left: 5px solid #FFFFFF;
border-right: 0px solid transparent;
float: left;
cursor: pointer;
}
<div id="nav" class="navArrow" style="position: relative;">
<div class="arrowEndOn" id="nav"> </div>
<div class="arrowBulkOn" id="nav">NAV</div>
<div class="arrowStartOn" id="nav"> </div>
</div>
Each nav item has a negative offset applied to it (which I've left out of the demo) as it's rendered to get them all flush with each other.
I'm handling the rollovers and on states with Javascript.
My problem is getting the nav to stretch all the way across the width of the page. At the moment I have to set the nav container to a much larger width to accommodate it all.
I've tried setting overflow to hidden but the last item is dropping down a level rather than carrying on and just having the end cut off.
I've set an example up here - http://jsfiddle.net/spacebeers/S7hzu/1/
The red border has overflow: hidden; and the blue doesn't.]
My question is: How can I get the boxes to all float in a line that fills the width of the containing div without them dropping down a level.
Thanks
Add a negative margin to each arrow:
.navArrow {
float: left;
margin-left: -8px;
}
Demo: http://jsfiddle.net/S7hzu/2/
Flexbox
You can use this example
https://codepen.io/WBear/pen/pPYrwo
it works on new browsers, to support old ones some changes needed.
HTML:
<div class="content">
<div class="as1">
NAV
</div>
<div class="as2">
NAV
</div>
<div class="as3">
NAV
</div>
</div>
CSS:
.content {
margin-top: 10px;
width: 100%;
display: inline-flex;
}
.as1, .as2, .as3 {
height: 70px;
min-width: 8%;
max-width: 100%;
background-color: black;
position: relative;
display: inline-flex;
text-align: center;
flex-wrap: wrap;
flex-grow: 1;
}
.as1 a, .as2 a, .as3 a {
text-decoration: none;
display: inline-flex;
color: white;
margin: auto;
font-size: 14pt;
}
.as1:after {
content: "";
position: absolute;
right: 4px;
border-top: 35px solid transparent;
border-left: 25px solid black;
border-bottom: 35px solid transparent;
z-index: 2;
}
.as2 {
background-color: grey;
margin-left: -29px;
}
.as2:after {
content: "";
position: absolute;
right: 4px;
border-top: 35px solid transparent;
border-left: 25px solid grey;
border-bottom: 35px solid transparent;
z-index: 3;
}
.as3 {
background-color: #A9A9A9;
margin-left: -29px;
}
Related
This question already has answers here:
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 1 year ago.
I am trying to implement tabs in our application. I've got a CSS problem where somehow I am adding padding or magin to the right of every tab-item
See my problem in here: JSFiddle
As you can see in the Fiddle, the first tab-item is currently active. However, there is some padding to the right of the item. Because of this padding/margin, the bottom border starts a few pixels too soon.
What am I doing wrong here?
.tabs2 {
border-bottom: 1px solid red;
}
.tabs2-wrap {
margin-bottom: -1px;
position: relative;
}
.tablist {
transform: translateX(0px);
border: 1px solid red;
border-bottom: none;
border-radius: 4px 4px 0 0;
width: max-content;
}
.tabs2-item {
padding: 0 20px;
height: 40px;
line-height: 40px;
display: inline-block;
position: relative;
border-left: 1px solid red;
/* ** Hacky solution ** */
/* margin-left: -4px; */
}
.tabs2-item:first-child {
border-left: none;
}
.tabs2-isActive {
border-bottom: 1px solid #fff;
color: #409eff;
}
<div class="tabs2">
<div class="tabs2-wrap">
<div class="tablist">
<div class="tabs2-item tabs2-isActive">Algemeen</div>
<div class="tabs2-item">Vertrouwelijk</div>
<div class="tabs2-item">Historie</div>
<div class="tabs2-item">Kaasboer</div>
</div>
</div>
</div>
you try with display flex:
But why does this problem occur?
Because the display inline-block considers empty characters and spaces as part of block;
.tabs2 {
border-bottom: 1px solid red;
}
.tabs2-wrap {
margin-bottom: -1px;
position: relative;
}
.tablist {
transform: translateX(0px);
border: 1px solid red;
border-bottom: none;
border-radius: 4px 4px 0 0;
width: max-content;
display:flex;
}
.tabs2-item {
padding: 0 20px;
height: 40px;
line-height: 40px;
display: inline-block;
position: relative;
border-left: 1px solid red;
/* ** Hacky solution ** */
/* margin-left: -4px; */
}
.tabs2-item:first-child {
border-left: none;
}
.tabs2-isActive {
border-bottom: 1px solid #fff;
color: #409eff;
}
<div class="tabs2">
<div class="tabs2-wrap">
<div class="tablist">
<div class="tabs2-item tabs2-isActive">Algemeen</div>
<div class="tabs2-item">Vertrouwelijk</div>
<div class="tabs2-item">Historie</div>
<div class="tabs2-item">Kaasboer</div>
</div>
</div>
</div>
and other solution: remove white-space from html without flex:
.tabs2 {
border-bottom: 1px solid red;
}
.tabs2-wrap {
margin-bottom: -1px;
position: relative;
}
.tablist {
transform: translateX(0px);
border: 1px solid red;
border-bottom: none;
border-radius: 4px 4px 0 0;
width: max-content;
display:flex;
}
.tabs2-item {
padding: 0 20px;
height: 40px;
line-height: 40px;
display: inline-block;
position: relative;
border-left: 1px solid red;
/* ** Hacky solution ** */
/* margin-left: -4px; */
}
.tabs2-item:first-child {
border-left: none;
}
.tabs2-isActive {
border-bottom: 1px solid #fff;
color: #409eff;
}
<div class="tabs2">
<div class="tabs2-wrap">
<div class="tablist">
<div class="tabs2-item tabs2-isActive">Algemeen</div><div class="tabs2-item">Vertrouwelijk</div><div class="tabs2-item">Historie</div><div class="tabs2-item">Kaasboer</div>
</div>
</div>
</div>
Looking at your CSS, you have the left and right padding on all tabs2-item elements set to 20px. Then the CSS under the first-child selector turns off the padding to the left of the first tabs2-item element (leaving the padding on the right).
I have been trying hard without success to add a little triangle under my square to act as a pointer like this:
My code by itself works, but whenever I try to add css to make this triangle nothing will appear. I think it has to do with before-after functions, but I'm not really getting it. Anyone can help me with that?
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.com" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
edit: code of the triangle
<div class="triangle-down"></div>
<style>
.triangle-down {
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-top: 20px solid #555;
}
</style>
Generally in CSS triangles are made using borders, not before and after pseudo elements. To create a downward pointing triangle, you would create a top border of n number of pixels, and left and right borders of half that width and also transparent.
Example:
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.png" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"><div id='triangle-down'></div></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
#triangle-down {
position: absolute;
top: 40px;
right: 50%;
transform: translateX(50%);
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 20px solid blue;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
See my codepen here: https://codepen.io/anon/pen/bvXOab
You could add another div for the triangle like
<div id='triangle'></div>
Css For the triangle...
#triangle{
width: 0;
height: 0;
border-left: 40px solid transparent;
border-right: 40px solid transparent;
border-top: 80px solid blue;
}
However I feel that your problem is not that it just isnt appearing its that the positioning is messed up so its 'hidden' behind the sliders
I think I understand what you're trying to make. This should add a triangle above the marker. This solution should allow you to also remove anything related to triangle-down as it only requires the slider_marker1 div
#slider_marker1::before {
content: "";
width: 0;
height: 0;
position: absolute;
top: -6px;
left: 0;
right: 0;
margin: auto;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 4px solid green;
z-index: 100;
}
I'm trying to recreate this stylized line border behind my header (see: https://www.vox.com's yellow border behind 'Top Stories'). I understand that it's being created using :before but I can't seem to get my header span (projheader_name) to white out some of the border AND I'm getting two of the :before elements created for some reason. One gets inserted after div class="container" and the other after span="projheader_name".
#projheader {
margin-top: 40px;
padding-top: 20px;
}
#projheader .container {
background-color: white;
}
#projheader h3 {
margin-bottom: 10px;
}
.projheader_name {
background-color: white;
position: relative;
z-index: 3;
}
#projheader :before {
border-left: 4px solid #17A2B8;
border-right: 4px solid #17A2B8;
border-top: 4px solid #17A2B8;
content: " ";
height: 40px;
left: 6%;
position: absolute;
right: 6%;
top: 27%;
}
<section id="projheader">
<div class="container">
<span class="projheader_name">
<h3>Landing Page: Sense</h3>
</span>
</div>
</section>
h3 {
text-align: center;
border: 4px solid #17A2B8; border-bottom: 0;
}
h3 span {
position: relative;
top: -0.7em;
background: #fff;
display: inline-block;
padding: 0 0.7em;
}
<h3><span>LANDING PAGE</span></h3>
I was studying how to make static navigation bars and managed to get up to this
https://jsfiddle.net/dm310tau/
.bottom-bar
{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
position: fixed;
z-index: 100;
bottom: 10px;
left: 0;
width: 100%;
height: 35px;
color: #999999;
background-color: #101010;
}
.bottom-bar li
{
float: left;
}
.bottom-bar a
{
display: block;
color: #999999;
text-align: center;
font-size: medium;
padding: 6px 16px;
text-decoration: none;
border: 1px solid transparent;
}
.bottom-bar a:hover:not(.active)
{
color: #EFEFEF;
border: 1px solid #AAAAAA;
}
.bottom-bar .active
{
color: #FEFEFE;
background-color: #303030;
padding: 3px 16px 8px 16px;
border: 1px solid #EEEEEE;
}
.bottom-bar .active:after
{
}
<ul class = "bottom-bar">
<li class = "bottom-link">
<a class = "active"
href = "/one">
One
</a>
</li>
<li class = "bottom-link">
<a href = "/two">
Two
</a>
</li>
<li class = "bottom-link">
<a href = "/three">
Three
</a>
</li>
</ul>
As the next step I was trying to make it so that active bar ends up a little bit taller like so,
However, I am not sure where is the first place to look for something like this. I have explored option of using
.bottom-bar .active:after, but, unfortunately, because the bar is supposed to be static, I can not make the part pop up a little bit higher by using a border like I have seen it done on other websites.
I do understand that I can do a few of these using Bootstrap, but that is not my intention. I would like to learn CSS instead of just using what's there and not understanding what is going on behind the scenes.
This works in Chrome at least. The comments explain what is happening.
<!DOCTYPE HTML>
<html>
<head>
<style>
#footer {
width: 100%;
height: 35px;
background-color: black;
position: fixed;
left: 0;
bottom: 0;
padding: 5px 0 0 20px; //top right bottom left
}
.link {
color: gray;
margin-right: 10px;
padding: 5px;
float: left;
position: relative;
}
.active {
color: white;
height: 50px;
border-bottom: none;
border-radius: 5px 5px 0 0;
}
.active:after { /*or :before*/
content: ""; /*allows shape to display*/
display: block;
width: 100%; /*cover element*/
top: -20px; /*position as you would like, just to show the difference*/
left: 0;
position: absolute;
height: 60px;
border: 1px solid white;
border-radius: 5px;
background-color: black;
z-index: -1; /*place behind element*/
}
</style>
</head>
<body>
<div id="footer">
<div id="links">
<div class="link active">Contact</div>
<div class="link">About</div>
<div class="link">Support me!</div>
</div>
</div>
</body>
</html>
I have a vertical menu having an item "Click here to get the scientific name".
on hover it is showing like
I need to get the overflow part after the black background image to be in the next line(i cannot increase the image width at all.). How can I write the style for that.
css:
on hover
{
display: block;
background: url('/../.png') no-repeat 0px 2px #2F2F31;
text-decoration: none;
color:..;
}
This is coming under
<td>
<div id="first">
<ul id="second">
<li>Click here to get the scientific name
And css:
#first {
display: block;
width: 180px;
min-height: 50px;
float: left;
}
ul#second {
display: block;
clear: both;
margin: 50px 0px 12px 0px;
border-bottom: 1px solid
#C8C8C8;
}
ul#second li {
border-top: 1px solid
#C8C8C8;
padding: 0px;
display: block;
}
ul#second li a {
color:
#004C8E;
margin: 4px 0px 4px 0px;
padding: 4px 0px 4px 12px;
display: block;
text-decoration: none;
font-size: 12px;
background: url('/../.png') no-repeat 0px 2px;
}
td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background:
transparent;
}
On hover, you should explicitly set the width of the element to equal the width of the image.
FOr this you can use word-wrap:break-word;. Write like this:
p{
word-wrap:break-word;
}