I have my code here in css for the a inside the header:
header {
display: block;
background-color: black;
color: white;
width: 100%;
height: 150px;
position: relative;
min-width:200px;
}
header img {
float: left;
}
header a {
color: white;
font-family: 'Roboto Slab', sans-serif;
font-weight: 100;
font-size: 200%;
text-decoration: none;
float: left;
}
<header>
<div class="header-image-container">
<img src="benny.jpg" alt="Benny logo">
</div>
<h1 class="site-title">Benny's List</h1>
</header>
I just want the a that is inside the header to be down towards the bottom of the header but no matter if I put margin or padding, it won't move at all. Thank you guys for any help!
Screenshot: https://imgur.com/a/YbwDAML
You probably just need to add clear for your hyperlink
header {
display: block;
background-color: black;
color: white;
width: 100%;
height: 150px;
position: relative;
min-width: 200px;
}
header img {
float: left;
}
header a {
color: white;
font-family: 'Roboto Slab', sans-serif;
font-weight: 100;
font-size: 200%;
text-decoration: none;
float: left;
clear: both; /* Added */
}
<header>
<img src="https://via.placeholder.com/100x100">
Link
</header>
There is no need of using floats when u don't need them next to each other, have a look at the below working snippet without using float: left, hope it helps :)
header {
display: block;
background-color: black;
color: white;
width: 100%;
height: 150px;
position: relative;
min-width: 200px;
}
header img {
/* float: left; */ /* removed */
display: block; /* Added */
}
header a {
color: white;
font-family: 'Roboto Slab', sans-serif;
font-weight: 100;
font-size: 200%;
text-decoration: none;
/* float: left; */ /* removed */
}
<header>
<img src="http://placekitten.com/g/80/80">
Link
</header>
header {
background-color: #000000;
color: #ffffff;
width: 100%;
height: 150px;
position: relative;
min-width: 200px;
}
header img {
width: 100px;
height: 100px;
display: block;
}
header a {
color: #ffffff;
font-family: 'Roboto Slab', sans-serif;
font-weight: 100;
font-size: 200%;
text-decoration: none;
}
<header>
<img src="https://image.ibb.co/nsrpRz/111.jpg">
Link
</header>
Just play with negative value of margin-top of img according to your requirement.
It will work. Below is the css code:
header img {
float: left;
margin-top: -10px;
}
Just tweak the value of margin-top according to your requirement.
Related
I am currently trying to center favicons in this circular background so it can change color on hover. I am struggling a little bit to center it, though. I tried text-align: center but that was no use. Not very up to speed with CSS. What should I be doing instead?
https://codepen.io/teecp/pen/gOYRwbO
One way to solve this problem is to set fixed height and width on the parent element. Then set the icon's dimensions the same with a line height that measures its height.
body {
font-family: "Lato", sans-serif;
}
.sidebar {
height: 100%;
width: 75px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #7b68ee;
transition: 0.5s;
overflow-x: hidden;
padding-top: 60px;
white-space: nowrap;
}
.sidebar a {
position: relative;
left: 20%;
text-decoration: none;
text-align: center;
font-size: 25px;
background: red;
border-radius: 90px;
width: 20%;
color: #ffffff;
display: block;
margin-bottom: 10px;
/* Added the properties below */
height: 50px;
width: 50px;
}
main .sidebar {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
#main {
padding: 16px;
margin-left: 85px;
transition: margin-left 0.5s;
}
.sidebar .fas:hover {
background: #ffffff1a;
border-radius: 90px;
}
.sidebar-bottom {
position: absolute;
bottom: 0;
width: 100%;
margin-bottom: 4rem;
}
/* Added the block below */
.fa, .far, .fas {
font-family: "Font Awesome 5 Pro";
line-height: 50px!important;
}
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script src="https://kit.fontawesome.com/b61e574d7a.js"></script>
<div class="sidebar">
<i class="fas fa-home"></i>
<i class="fas fa-chess-queen"></i>
<div id="main">
hello
</div>
Remove padding, add width, height and line-height.
.sidebar a {
position: relative;
left: 20%;
height: 50px;
width: 50px;
line-height: 55px;
text-decoration: none;
text-align: center;
font-size: 25px;
background: red;
border-radius: 90px;
color: #ffffff;
display: block;
margin-bottom: 10px;
}
When I hover my link normally it turns to green. However there is also red showing up around the link. I don't understand.
.myButtonRegister{
float: left;
background-color: #C22312;
height: 48px;
width: 168px;
text-align: center;
font-family: 'Pridi', serif;
font-size: 26px;
padding-top: 10px;
word-spacing: 0px;
}
.myButtonRegister a {
color: #f2f2f2;
text-decoration: none;
}
.myButtonRegister a:hover {
background-color: green;
color: black;
}
Thanks
As the size of <a> link tag is size of the content it contains, so the background doesn't cover the entire parent element which it has a larger size.
You can force the link to have the same size as the container by adding:
.myButtonRegister a {
display: block;
width: 100%;
height: 100%;
...
}
.myButtonRegister {
float: left;
background-color: #C22312;
height: 48px;
width: 168px;
text-align: center;
font-family: 'Pridi', serif;
font-size: 26px;
line-height: 48px; /* added */
/* padding-top: 10px; */
word-spacing: 0px;
}
.myButtonRegister a {
color: #f2f2f2;
text-decoration: none;
display: block;
width: 100%;
height: 100%;
}
.myButtonRegister a:hover {
background-color: green;
color: black;
}
<div class="myButtonRegister">Sample text</div>
I would suggest to get rid of the div container but only use the link tag.
.myButtonRegister {
display: inline-block;
height: 48px;
width: 168px;
font-family: 'Pridi', serif;
font-size: 26px;
line-height: 48px;
text-decoration: none;
text-align: center;
background-color: #C22312;
color: #f2f2f2;
}
.myButtonRegister:hover {
background-color: green;
color: black;
}
<a class="myButtonRegister" href="#">Sample text</a>
When hovering the <a> tag you are also triggering the hover on its parent element .myButtonRegister. Your html can be simplified from this:
<button class="myButtonRegister">
REGISTER
</button>
to this:
<a class="myButtonRegister">REGISTER</a>
Then trigger a hover animation on class myButtonRegister. Because both button tag and a tag can be used to render a button.
https://www.cp24.com/polopoly_fs/7.687199!/httpImage/image.jpg_gen/derivatives/default/image.jpg
I want to accomplish something similar to the image attached, I tried several post but didn't get it done, please help me.
Thanks
You can utilise the CSS :after pseudo-element to achieve a similar item, for example:
#banner {
font-family: sans-serif;
text-transform: uppercase;
}
#banner > div {
display: inline-block;
height: 40px;
line-height: 40px;
padding: 0 20px;
}
#banner .banner-grey {
background: #aaa;
position: relative;
}
#banner .banner-grey:after {
border: 20px solid transparent;
border-left-color: #aaa;
content: '';
display: block;
position: absolute;
right: -40px;
top: 0;
}
#banner .banner-red {
background: red;
font-weight: bold;
margin-left: -4px;
padding-left: 60px;
}
#banner .banner-red span {
color: #fff;
font-style: italic;
}
<div id="banner">
<div class="banner-grey">Check out our <b>live and interactive screen</b></div>
<div class="banner-red"><span>CP24</span>now</div>
</div>
My goal is to hover on next_wrapper and nav_text_title_next appears.
Now both the image and the p tag nav_text_title_next appears, but unfortunately I can't see any of the text in p tag nav_text_title_next. I use the same code for other sections, and it works well but it's not working in this part. Can you help me figure out what goes wrong?
HTML:
<div class="next_wrapper" id="next_wrapper_title" style="position:absolute; left:1050px; top:300px; z-index:5;">
<a class="next_button" href="#blah" style="background:none;">
<p class="navigation_text_next" id="nav_text_title_next">
HI!
</p>
<img class="next_button" src="img/next-icon.gif" onmouseover="this.src='img/next-icon-stop2.gif'" onmouseout="this.src='img/next-icon.gif'">
</a>
</div>
Here is the CSS:
.next_wrapper {
position: absolute;
top: 0px;
left: 95px;
}
#nav_text_title_next {
display: none;
}
#next_wrapper_title:hover #nav_text_title_next {
display: block;
}
.next_button {
width:75px;
background: none;
position: absolute;
}
.navigation_text_next {
background: #000;
color: #FFF;
font-family: AvenirLTStd-Medium;
font-weight: normal;
font-style: normal;
font-size: 11px;
position: absolute;
width: 100px;
height: 55px;
top: 30px;
left: 67px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 45px;
padding-right: 5px;
text-align: left;
display: none;
}
.next_button {
width:75px;
background: none;
position: absolute;
}
your display is none delete that and you will see your text
also delete it on your image
then do something similar to this
in html
<p>bla</p>
in css
p {
opacity:0;
}
p:hover {
opacity:1;
}
You have hidden it from view that is why.
.navigation_text_next {
background: #000;
color: #FFF;
font-family: AvenirLTStd-Medium;
font-weight: normal;
font-style: normal;
font-size: 11px;
position: absolute;
width: 100px;
height: 55px;
top: 30px;
left: 67px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 45px;
padding-right: 5px;
text-align: left;
display: none; <-- remove this
}
You can remove display: none; as it parents is hiiden and not required.
This is my HTML structure:
<div class="pageSlider">
Visitor's Lounge
News Stream
<a class="slide-button"></a>
</div>
And here are my CSS rules:
.pageSlider {
margin: 15px auto !important;
font-size: 1.2em;
white-space: nowrap;
height: 35px;
}
.pageSlider a[href] {
display: inline-block;
text-align: center;
text-decoration: none;
z-index: 2;
}
.pageSlider a[href].active {
color: #000;
}
.pageSlider .slide-button {
background-color: #cccc00;
position: relative;
top: -35px;
display: inline-block;
height: 35px;
padding: 0;
float: left;
height: inherit;
z-index: 1;
}
The .pageSlider .slide-button is set to z-index: 1 and .pageSlider a[href] is set to z-index: 2, but the lower z-index actually overlaps the higher.
I somehow need toget the .slide-button under the links, but I can't seem to figure out a better way.
Live demo:
(function(e){e.parseURL=function(e){if(typeof e==="undefined"&&typeof window.location.href!=="undefined")e=window.location.href;var t={whole:/^((http|https):\/\/)?((.*\.)?.*\..*|localhost|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/.*/,protocol:/^(http|https):\/\//,absolute:/^\/\/((.*\.)?.*\..*|localhost|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\//,relative:/^[\/](?!\/).*(\..*|\/)?.*$/,params:/\?.*=.*(\&.*\=.*)+[^#.*]/},n={protocol:undefined,hostname:undefined,hash:undefined,href:{original:undefined,noparams:undefined},parentDomain:undefined,parameters:undefined,pathname:{nohash:undefined,withhash:undefined},type:undefined};if(typeof e!=="string")throw new TypeError("Argument must be a string!");else if(!t.whole.test(e)&&!t.absolute.test(e)&&!t.relative.test(e))throw new Error("Invalid string");n.href.original=e;if(e.indexOf("#")!==-1){n.hash=e.substring(e.indexOf("#"));e=e.substring(0,e.indexOf("#"))}if(t.params.test(e)){n.parameters={};var r=e.match(t.params)[0].substring(1).split("&");for(var i=0,s=r.length;i<s;i++){var o=r[i].split("=");n.parameters[o[0]]=o[1]}e=e.replace(t.params,"");n.href.noparams=e+(typeof n.hash!=="undefined"?n.hash:"")}if(t.protocol.test(e)){n.protocol=e.match(t.protocol)[0];n.hostname=e.replace(t.protocol,"");n.hostname=n.hostname.substring(0,n.hostname.indexOf("/"));n.parentDomain=n.hostname.split(".");n.parentDomain.splice(0,1);n.parentDomain=n.parentDomain.join(".");if(n.parentDomain=="")n.parentDomain=n.hostname;var u=e.replace(t.protocol,"");n.pathname.nohash=u.substring(u.indexOf("/"));u=undefined;n.type="normal"}else{n.protocol=window.location.href.match(t.protocol)[0];if(t.absolute.test(e)){var u=e.replace(/^\/\//,"");n.hostname=u.substring(0,u.indexOf("/"));n.pathnam.nohashe=u.substring(u.indexOf("/"));n.type="absolute";n.href.original=n.href.original.replace(/^\/\//g,n.protocol)}else if(t.relative.test(e)){n.hostname=window.location.href.replace(t.protocol,"");n.hostname=n.hostname.substring(0,n.hostname.indexOf("/"));n.pathname.nohash=n.href.original;n.type="relative"}else{throw new Error("Invalid string")}}n.pathname.withhash=n.pathname.nohash+n.hash;return n};if(typeof e(".pageSlider")[0]!=="undefined"){e.pageSlider=function(t){if(t==="update"){e('.pageSlider a.active:not([href="'+e.parseURL().hash+'"])').removeClass("active");e('.pageSlider a[href="'+e.parseURL().hash+'"]').addClass("active");e(".pageSlider").each(function(){var t=e(this);var n=t.find("a.slide-button");var r=t.find("a[href]");var i=r.size();var s=100/i;var o=r.index("a.active");r.css("width",s+"%");console.log(o);n.css("width",s+"%").animate({left:o*-1*s+"%"})});return e('.pageSlider a.active[href="'+e.parseURL("/index.php").hash+'"]')}};window.location.hash="lounge";e.pageSlider("update");e(window).on("hashchange",function(){e.pageSlider("update")})}})(jQuery)
.pageSlider {
margin: 15px auto !important;
font-size: 1.2em;
white-space: nowrap;
height: 35px;
}
.pageSlider a[href] {
display: inline-block;
text-align: center;
text-decoration: none;
color: #fff;
z-index: 2;
}
.pageSlider a[href].active {
color: #000;
}
.pageSlider .slide-button {
background-color: #cccc00;
position: relative;
top: -35px;
display: inline-block;
padding: 0;
float: left;
height: inherit;
z-index: 1;
}
body{background-color:#777}#media all and (max-width: 500px){.pageSlider{white-space: normal}.pageSlider a[href]{display: block !important;width: 100% !important}.pageSlider [href].active {background-color: #cccc00}.pageSlider .slide-button{display: none}}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pageSlider">
Visitor's Lounge
News Stream
<a class="slide-button"></a>
</div>
You forgot to add:
position:relative;
on your link (.pageSlider a[href]). z-index only applies to positioned elements.