Currently I am trying to center my arrows that are created using CSS when I hover over my nav menu. Even though I have set the margin left and right to auto. It still does not seem to want to center. It could be because of the format of my HTML. I have tried a number of options but none of them seem to have helped.
Please see my HTML and CSS below:
(Unfortunately I cannot seem to re-create my code but I will post it and continue to try and recreate it in the mean time)
#navbar {
overflow: hidden;
background-color: $base-white;
font-size: 11px;
z-index: 2;
border: 1px solid $base-grey;
height: 50px;
}
.navbar-links {
margin-left: 10em;
height: 100%;
padding: 0em 4em 0em 1em;
min-width: 348px;
margin-top: auto;
margin-bottom: auto;
}
#navbar .navbar-links a {
display: block;
float: left;
color: $base-grey;
padding: 14px 20px 14px 20px;
text-decoration: none;
font-size: 14px;
margin-top: auto;
margin-bottom: auto;
}
#navbar .navbar-links a:hover:after {
content: ' ';
position: absolute;
bottom: -10px;
width: 0;
height: 0;
text-align: center;
border-width: 10px 10px 0;
border-style: solid;
border-color: $base-grey transparent;
margin: 0 auto;
display: block;
}
<div class="navbar-links">
<div class="navbar-dropdown">
<button class="navbar-drop-btn">
<div class="navbar-arrow"></div>
</button>
<div class="navbar-dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<a [routerLinkActive]="['navbar-links-active']" [routerLink]="['insights']" (mouseover)="displayInsightDropDown();" (mouseleave)="hideInsightDropDown();">INSIGHTS</a>
<a [routerLinkActive]="['navbar-links-active']" [routerLink]="['explore']">EXPLORE</a>
<a [routerLinkActive]="['navbar-links-active']" [routerLink]="['aboutus']">ABOUT</a>
</div>
Here is a picture of the result:
As you can see the arrow is positioned to the left, but never the center.
Any suggestions would help, thank you in advance.
You need to set the context for the absolutely positioned ::after. To do so, add a non static position (position: relative in this case) to the <a> tags.
To center the ::after element, I've used left: calc(50% - 10px) because the width of the arrow is known (20px). If to arrow can have variable size, you can use:
left: 50%;
transform: translateX(-50%);
.navbar-links {
margin-left: 10em;
height: 100%;
padding: 0em 4em 0em 1em;
min-width: 348px;
margin-top: auto;
margin-bottom: auto;
}
.navbar-links a {
position: relative; /** the absolute context **/
display: block;
float: left;
color: grey;
padding: 14px 20px 14px 20px;
text-decoration: none;
font-size: 14px;
margin-top: auto;
margin-bottom: auto;
}
.navbar-links a:hover::after {
left: calc(50% - 10px);
position: absolute;
content: ' ';
bottom: -10px;
width: 0;
height: 0;
border-width: 10px 10px 0;
border-style: solid;
border-color: grey transparent;
display: block;
content: ' ';
}
body {
overflow: hidden;
}
<div class="navbar-links">
INSIGHTS
EXPLORE
ABOUT
</div>
Although answer is accepted but I've another solution using flex property of CSS, add two line inside .navbar-links a
display: flex;
justify-content: center;
no need for calculation
.navbar-links {
margin-left: 10em;
height: 100%;
padding: 0em 4em 0em 1em;
min-width: 348px;
margin-top: auto;
margin-bottom: auto;
}
.navbar-links a {
position: relative;
/** the absolute context **/
display: flex;
justify-content: center;
float: left;
color: grey;
padding: 14px 20px 14px 20px;
text-decoration: none;
font-size: 14px;
margin-top: auto;
margin-bottom: auto;
}
.navbar-links a:hover::after {
position: absolute;
bottom: -10px;
width: 0;
height: 0;
border-width: 10px 10px 0;
border-style: solid;
border-color: grey transparent;
content: ' ';
}
body {
overflow: hidden;
}
<div class="navbar-links">
INSIGHTS
EXPLORE
ABOUT
</div>
Related
Could you please advise how can I style my divs, so they are displayed next to each other in two rows? I have few items in html and three of them are .card1 and the other .card2, .service is for the whole container. I wish the divs are placed next to each other in two lines. Could you please help me in styling them? :)
.service {
background: #08122f;
width: 100%;
padding: 100px 0px;
}
.card1 {
height: 365px;
width: 335px;
padding: 20px 35px;
background: #251f4a;
border-radius: 15px;
margin: 15px;
position: relative;
overflow: hidden;
text-align: center;
}
.card2 {
height: 365px;
width: 335px;
padding: 20px 35px;
background: #251f4a;
display: flex-start;
border-radius: 15px;
margin: 15px;
position: relative;
overflow: hidden;
text-align: center;
}
You can use
display: inline flow-root list-item;
Example:
.service {
background: #08122f;
width: 100%;
padding: 100px 0px;
}
.card1 {
height: 365px;
width: 30%;
padding: 20px 35px;
background: #251f4a;
border-radius: 15px;
margin: 15px;
position: relative;
overflow: hidden;
text-align: center;
display: inline flow-root list-item;
}
.card2 {
height: 365px;
width: 30%;
padding: 20px 35px;
background: #251f4a;
display: flex-start;
border-radius: 15px;
margin: 15px;
position: relative;
overflow: hidden;
text-align: center;
display: inline flow-root list-item;
}
<div class="service">
<div class="card1"></div>
<div class="card1"></div>
<div class="card1"></div>
<div class="card2"></div>
</div>
I tried adding the Paypal smart button to my first project. When the Debit or Credit card button is pressed, the text above it goes through the navbar.
I tried adding additional blank space to the background image, but it did not work.
Is there a way to extend the blank space already made by the Paypal button script?
What can I do to fix it?
Navbar problem
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.header{
min-height: 100vh;
width: 100%;
background-image: linear-gradient(rgba(4,9,30,0.4),rgba(4,9,30,0.4)),url(slike/slika\ 2.JPG);
background-position: center;
background-size: 100%;
position: relative;
}
nav{
display: flex;
padding: 2% 6%;
justify-content: space-between;
align-items: center;
}
nav img{
width: 500px;
}
.nav-links{
flex: 1;
text-align: right;
}
.nav-links ul li{
list-style: none;
display: inline-block;
padding: 8px 20px;
position: sticky;
}
.nav-links ul li a{
color: #7814ac;
text-decoration: none;
font-size: 30px;
font-family: 'Lora', serif;
}
.nav-links ul li::after{
content: "";
width: 0%;
height: 2px;
background: white;
display: block;
margin: auto;
transition: 0.5s;
}
.nav-links ul li:hover::after{
width: 100%;
}
.text-box{
width: 90%;
color: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
text-align: center;
margin-top: 200px;
}
.text-box h1{
font-size: 62px;
}
.text-box p{
margin: 10px 0 40px;
font-size: 36px;
color: white;
}
.hero-btn{
display: inline-block;
text-decoration: none;
color: white;
border: 1px solid white;
padding: 12px 34px;
font-size: 24px;
background: transparent;
position: relative;
cursor: pointer;
margin-bottom: 5px;
}
.hero-btn:hover{
border: 1px solid #7814ac;
background: #7814ac;
transition: 1s;
}
The problem would appear to be the container in which all that text is located. Perhaps it has a fixed position or height. The black debit/credit card button needs to be rendered in a container that can expand normally. If for some reason you are not able to change the site's CSS to allow this, you can disable the black button with &disable-funding=card. Other buttons will open the PayPal window normally.
I have a strange problem.
Everything on my page went well, I had my navigation bar ready (also for my mobile phone).
Then I put a photo under the navigation bar and the bar was gone ..
I want the bar fixed so that it remains visible, but when I do it is gone.
The picture should remain relative otherwise this will not be correct anymore if you resize to mobile phone.
Someone a solution that keeps the bar back?
Image css
.header{
max-width: 100%;
margin-left: 0;
margin-top: 0;
position: relative;
letter-spacing: 4px;
margin-top: 70px;
box-sizing: inherit;
}
.header-image{
max-width: 100%;
height: auto;
border-style: none;
background-size: cover;
background-position: center center;
display: block;
position: relative;
box-sizing: inherit;
}
.header-image-tekst{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
box-sizing: inherit;
display: block;
text-align: center!important;
margin-top: 16px!important;
}
.header-image-tekst h1{
color: white;
font-size: 38px!important;
margin: 10% 0;
}
.header-image-tekst h1 .border{
padding: 8px 16px!important;
background-color: black;
opacity: 0.75;
}
Navigation bar css
.container{
margin: 0 auto;
width: 100%;
position: fixed;
}
.nav{
border-bottom: 1px solid #EAEAE8;
text-align: right;
height: 70px;
line-height: 70px;
position: fixed;
}
.menu{
margin: 0 30px 0 0;
}
.menu a{
clear: right;
text-decoration: none;
color: #000;
margin: 0 10px;
line-height: 70px;
padding: 20px;
border-radius: 40px;
}
.menu a:hover{
background-color: #03999e3b;
}
label{
margin: 0 40px 0 0;
float: right;
margin: 0 10px;
line-height: 70px;
font-size: 26px;
display: none;
width: 26px;
float: right;
}
#toggle{
display: none;
}
#media only screen and (max-width: 700px){
label{
display: block;
cursor: pointer;
position: fixed;
}
.menu{
text-align: center;
width: 100%;
display: none;
}
.menu a{
display: block;
border-bottom: 1px solid #03989E;
margin: 0;
}
#toggle:checked + .menu {
display: block;
position: fixed;
}
}
.active{
background-image: linear-gradient(315deg, #ffffff 0%, #03989E 74%);
}
From what I can tell, the image is likely over-lapping the navbar. Use z-index on the navigation bar to make it appear on top of the image. If you don't want them overlapping then you'll have to adjust some of your layout CSS but that should work. I'll usually put my z-index for my navigation at 10, that way it'll always be in front of other elements where I have a z-index set.
Here's a reference article: https://developer.mozilla.org/en-US/docs/Web/CSS/z-index
So, it's my first time getting into HTML/CSS and naturally, I'm having problems with certain parts.
I made a "Contine" button in my setup.html and gave it a class so I can style it in my styles.css, now the problem is that text-align center doesnt work on the button. I also have a "Start" button in my index.html, but strangely text-align center works there. I tried giving both buttons the same class and different classes. I'm not sure what to do at this point in time.\
My Button in HTML:
<div class="startcontainer">
<a href="./home.html">
<button id="continue"><span>Continue</span></button>
</a>
</div>
My CSS:
.startcontainer {
position: fixed;
border-radius: 5px;
width: calc(100% - 20px);
height: calc(100% - 120px);
left: 10px;
right: 10px;
bottom: 3%;
margin-bottom: 10px;
padding: 0px;
background-color: #1F1F1F;
float: middle;
text-align: center;
}
.startcontainer a {
position: relative;
display: block;
margin: 0 auto;
top: 40%;
text-decoration: none;
border: 0;
}
.startcontainer a #continue {
position: relative;
max-width: 280px;
max-height: 60px;
line-height: 60px;
padding: 10px 100px;
font-size: xx-large;
background-color: #1F1F1F;
color: #FFFFFF;
opacity: .87;
line-height: normal;
font-family: 'Open Sans', sans-serif;
border: 5px solid #8644A1;
border-radius: 45px;
display: block;
margin: 0 auto;
top: 40%;
transition: 0.4s;
outline: 0;
cursor: pointer
}
.startcontainer a #continue span {
display: block;
line-height: 30px;
}
.startcontainer a #continue:hover {
background-color: #8644A1;
}
Like I said the #contine part in my styles.css is the exact same for the "start" button, but it only works for the start button.
Problem is with max-width: 280px; and padding: 10px 100px; of button.
you are giving padding of 200px on the horizontal scale and then you are limiting button width to 280px. which leaves only 80px for text within. Remove button width for a better look of a button. Alternatively, you can trade off any of the CSS property over others.
.startcontainer {
position: fixed;
border-radius: 5px;
width: calc(100% - 20px);
height: calc(100% - 120px);
left: 10px;
right: 10px;
bottom: 3%;
margin-bottom: 10px;
padding: 0px;
background-color: #1F1F1F;
float: middle;
text-align: center;
}
.startcontainer a {
position: relative;
display: block;
margin: 0 auto;
top: 40%;
text-decoration: none;
border: 0;
}
.startcontainer a #continue {
position: relative;
/* max-width: 280px; */
max-height: 60px;
line-height: 60px;
padding: 10px 100px;
font-size: xx-large;
background-color: #1F1F1F;
color: #FFFFFF;
opacity: .87;
line-height: normal;
font-family: 'Open Sans', sans-serif;
border: 5px solid #8644A1;
border-radius: 45px;
display: block;
margin: 0 auto;
top: 40%;
transition: 0.4s;
outline: 0;
cursor: pointer
}
.startcontainer a #continue span {
display: block;
line-height: 30px;
}
.startcontainer a #continue:hover {
background-color: #8644A1;
}
<div class="startcontainer">
<a href="./home.html">
<button id="continue"><span>Continue</span></button>
</a>
</div>
I am building my first website and I am having some hidden speech bubbles appear when you hover over image like this demo
However I don't know how to affect the positioning measurements of the speech bubble, how could I make it so the speech bubble is aligned in the center of the box bellow it?
Any help would be much appreciated!
HTML:
<div id="container">Hover over me!<span>Hidden message here.</span></div>
CSS:
#container {
background-color: #FF0;
margin: 100px;
float: left;
height: 200px;
width: 200px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
a.hoverbubble {
position: relative;
text-decoration: none;
}
a.hoverbubble span {display: none;
}
a.hoverbubble:hover span {
display: block;
position: absolute;
padding: .5em;
content: attr(title);
min-width: px;
text-align: center;
width: auto;
height: auto;
white-space: nowrap;
top: -40px;
background: rgba(0,0,0,.8);
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
color: #fff;
font-size: 0.86em;
font-family: Arial, Helvetica, sans-serif;
}
a.hoverbubble:hover span:after {
position: absolute;
display: block;
content: "";
border-color: rgba(0,0,0,.8) transparent transparent transparent;
border-style: solid;
border-width: 10px;
height: 0;
width: 0;
position: absolute;
bottom: -20px;
left: 1em;
}
Set your container div to position:relative
remove position:relative from your a tag
Changing position:relative from your a tag to your div container will allow your absolutely positioned span to align relative to the container rather than the a tag.
set your span to position:absolute
align your span by editing the values top:40%; left: 11%;
you can now position your span element relative to your container.
http://jsfiddle.net/e4q7K/18/
On the assumption that the hidden message is to be centered on the link..
JSFiddle Demo
HTML
<div id="container">
<a href="#" class="hoverbubble">Hover over me!
<span>Hidden message here.</span>
</a>
</div>
CSS
#container {
background-color: #FF0;
margin: 100px;
float: left;
height: 200px;
width: 200px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
a.hoverbubble {
position: relative;
text-decoration: none;
background-color: lightblue;
}
a.hoverbubble span {display: none;}
a.hoverbubble:hover span {
display: block;
position: absolute;
padding: .5em;
text-align: center;
width: auto;
height: auto;
white-space: nowrap;
top: -40px;
left:50%; /* push the block halfway over to the right */
-webkit-transform:translate(-50%, 0); /* move it back left half it's own width */
background: rgba(0,0,0,.8);
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
color: #fff;
font-size: 0.86em;
font-family: Arial, Helvetica, sans-serif;
}
a.hoverbubble:hover span:after {
position: absolute;
display: block;
content: "";
border-color: rgba(0,0,0,.8) transparent transparent transparent;
border-style: solid;
border-width: 10px;
height: 0;
width: 0;
position: absolute;
bottom: -20px;
left: 1em;
}