I want to show a div named dot-menu when hover the after content of h1. I have tried the following code but did't work.
h1{
font-size: 20px;
font-weight: 400;
color: #3d3d3d;
margin-top:50px
}
h1:after{
content: "\22EE";
float: right;
font-size: 35px;
padding-right: 20px;
}
.dot-menu{
float: right;
background-color: #3d3d3d;
color: #FFFFFF;
font-size: 16px;
padding: 10px;
font-weight: 400;
font-family: "Montserrat Light", "Open Sans";
position: relative;
top:-10px;
opacity:0;
}
h1:after:hover .dot-menu{
opacity:1;
}
<h1>Henry Little</h1><h3 class="dot-menu">about</h3>
Your selector h1:after:hover .dot-menu is wrong.
This selector will look for .dot-menu element that is descendant of h1 but this is not the case. And 2nd you can't select another element on hover of a pseudo element.
You will need to change your code a bit. Consider the following HTML:
<h1>Henry Little
<span class="icon">⋮</span>
<span class="dot-menu">about</span>
</h1>
Make menu opener and menu both child elements of same parent. Then you can show menu on hover of icon with Sibling (+ ) selector.
h1 .icon:hover + .dot-menu{
opacity:1;
}
h1{
font-size: 20px;
font-weight: 400;
color: #3d3d3d;
margin-top:50px;
position: relative;
}
h1:after {
display: block;
clear: both;
content: '';
}
h1 .icon {
float: right;
font-size: 35px;
padding-right: 20px;
position: relative;
cursor: pointer;
}
.dot-menu {
float: right;
background-color: #3d3d3d;
color: #FFFFFF;
font-size: 16px;
padding: 10px;
font-weight: 400;
font-family: "Montserrat Light", "Open Sans";
position: relative;
top:30px;
opacity:0;
right: 0;
}
h1 .icon:hover + .dot-menu{
opacity:1;
}
<h1>Henry Little
<span class="icon">⋮</span>
<div class="dot-menu">about</div>
</h1>
See this just after making the .dot-menu a child of h1 it is working.
h1{
font-size: 20px;
font-weight: 400;
color: #3d3d3d;
margin-top:50px
}
h1:after{
content: "\22EE";
float: right;
font-size: 35px;
padding-right: 20px;
}
.dot-menu{
float: right;
background-color: #3d3d3d;
color: #FFFFFF;
font-size: 16px;
padding: 10px;
font-weight: 400;
font-family: "Montserrat Light", "Open Sans";
position: relative;
top:-10px;
opacity:0;
}
h1:hover .dot-menu{
opacity:1;
}
<h1>Henry Little<span class="dot-menu">about</span></h1>
Related
This is my HTML and CSS code. If you run this, there will be a image of a macbook and a 'buy' button. When the browser is minimised, the image is alittle off from the center. When it is in full screen, it causes the image to move up and the 'buy' button gets pushed to the bottom. I tried to use position: fixed but it didnt work. How do you make the picture have fixed position in the middle
.new {
font-family: Arial;
color: rgb(202, 137, 15);
font-size: 18px;
margin-bottom: 15px;
}
.macbook {
font-family: Arial;
font-weight: bold;
font-size: 44px;
margin-top: 0px;
margin-bottom: 10px;
}
.supercharged {
font-family: Arial;
font-weight: bold;
font-size: 60px;
margin-top: 0px;
margin-bottom: 25px;
}
.price {
font-family: Arial;
font-size: 18px;
margin-top: 0px;
}
.button {
background-color: #007aff;
color: white;
border-radius: 100px;
font-weight: bold;
border: none;
padding-left: 16px;
padding-right: 16px;
padding-bottom: 10px;
padding-top: 10px;
position: 50px;
}
.button:hover {
opacity: 0.8;
}
.button:active {
opacity: 0.5;
}
.charged {
color: plum;
text-decoration: underline;
}
.picture {
margin-top: 50px;
}
<!DOCTYPE html>
<html align='center'>
<body>
<p class='new'>New</p>
<h2 class='macbook'>MacBook Pro</h3>
<h1 class='supercharged'><span class='charged'>Supercharged</span> for pros.</h1>
<p class='price'>From $1999</p>
<button class='button'>Buy</button>
<img src="https://images.macrumors.com/t/PV_LL2AlRJvaRvbuXCTUOuDpwzU=/800x0/smart/article-new/2013/09/16-inch-macbook-pro.jpg?lossy" alt="Macbook" class='picture'>
</body>
</html>
Just apply display: block to the <a>-element. When you use display: block on an element, it will try to take up as much width as possible. Seeing as it is not inside a parent container, it will take up 100% width of the <body>-element, as that is the elements closest parent. This way, it won't wrap around the image. The link will however stretch and fill the entire parent container as well. To combat this, apply max-width: fit-content, so the link's width is only relative to its content. Then you can apply margin: auto to center the element again.
For a responsive image, apply max-width: 100% and height: auto. This way it will automatically scale down, as the max-width: 100% property won't let it overflow its parent container (the <body>-element)
body {
text-align: center;
}
.new {
font-family: Arial;
color: rgb(202, 137, 15);
font-size: 18px;
margin-bottom: 15px;
}
.macbook {
font-family: Arial;
font-weight: bold;
font-size: 44px;
margin-top: 0px;
margin-bottom: 10px;
}
.supercharged {
font-family: Arial;
font-weight: bold;
font-size: 60px;
margin-top: 0px;
margin-bottom: 25px;
}
.price {
font-family: Arial;
font-size: 18px;
margin-top: 0px;
}
.button {
background-color: #007aff;
color: white;
border-radius: 100px;
font-weight: bold;
border: none;
padding-left: 16px;
padding-right: 16px;
padding-bottom: 10px;
padding-top: 10px;
position: 50px;
}
.button:hover {
opacity: 0.8;
}
.button:active {
opacity: 0.5;
}
.charged {
color: plum;
text-decoration: underline;
}
.picture {
margin-top: 50px;
max-width: 100%;
height: auto;
}
a {
display: block;
max-width: fit-content;
margin: auto;
}
<p class='new'>New</p>
<h2 class='macbook'>MacBook Pro</h3>
<h1 class='supercharged'><span class='charged'>Supercharged</span> for pros.</h1>
<p class='price'>From $1999</p>
<button class='button'>Buy</button>
<img src="https://images.macrumors.com/t/PV_LL2AlRJvaRvbuXCTUOuDpwzU=/800x0/smart/article-new/2013/09/16-inch-macbook-pro.jpg?lossy" alt="Macbook" class='picture'>
By default an image is displayed inline, which is causing your issue. You're on the right track, but instead of position fixed, position: block; would be a better choice.
(You can also centre your image and avoid it overflowing using a max-width and some margin)
.new {
font-family: Arial;
color: rgb(202, 137, 15);
font-size: 18px;
margin-bottom: 15px;
}
.macbook {
font-family: Arial;
font-weight: bold;
font-size: 44px;
margin-top: 0px;
margin-bottom: 10px;
}
.supercharged {
font-family: Arial;
font-weight: bold;
font-size: 60px;
margin-top: 0px;
margin-bottom: 25px;
}
.price {
font-family: Arial;
font-size: 18px;
margin-top: 0px;
}
.button {
background-color: #007aff;
color: white;
border-radius: 100px;
font-weight: bold;
border: none;
padding-left: 16px;
padding-right: 16px;
padding-bottom: 10px;
padding-top: 10px;
position: 50px;
}
.button:hover {
opacity: 0.8;
}
.button:active {
opacity: 0.5;
}
.charged {
color: plum;
text-decoration: underline;
}
.picture {
margin: 50px auto 0 auto;
display: block;
max-width: 100%;
}
<!DOCTYPE html>
<html align='center'>
<body>
<p class='new'>New</p>
<h2 class='macbook'>MacBook Pro</h3>
<h1 class='supercharged'><span class='charged'>Supercharged</span> for pros.</h1>
<p class='price'>From $1999</p>
<button class='button'>Buy</button>
<img src="https://images.macrumors.com/t/PV_LL2AlRJvaRvbuXCTUOuDpwzU=/800x0/smart/article-new/2013/09/16-inch-macbook-pro.jpg?lossy" alt="Macbook" class='picture'>
</body>
</html>
I asked a question some days ago about resizing a div when resizing the browser so that it looks good on desktop and on mobile devices. But now I have an extended problem to the same. I have 2 divs one below the other and the bottom footer div resizes on resizing the browser. The working solution can be found here in my previous post: Resize div on resizing window
But in the problem here, I added another div on top of it. On resizing the browser window, the divs don't stack on top of one another. They work fine on a full window on a desktop. Would appreciate any suggestions that you may have or if you'd like to modify the sample code - that would be great!
.info-banner {
position: fixed;
width: 100%;
font-family: Arial, sans-serif;
font-size: 24px;
background: #000000;
color: #FFFFFF;
text-align: center;
bottom: 30px;
left: 0%;
opacity: 0.8;
}
.info-banner a {
color: #FFFFFF;
text-decoration: none;
}
.info-banner a:hover {
color: #aaa;
}
.footer-box {
position: fixed;
font-family: Arial, sans-serif;
color: #FFFFFF;
background-color: #000000;
font-size: 11px;
width: 100%;
opacity: 0.8;
z-index: 50;
bottom: 0px;
left: 0px;
}
.footer-box h2 {
margin-top: 0;
margin-bottom: 0;
font-size: 20px;
text-align: center;
line-height: 30px;
font-weight: normal;
font-family: Arial, sans-serif;
color: #A9A9A9;
}
.footer-box a {
text-decoration: none;
outline: none;
color: #A9A9A9;
}
.footer-box a:hover {
text-decoration: underline;
}
<div id="contact-footer-merged">
<div id="contact-banner" class="info-banner">
<div>HEADER</div>
<div>SUB-HEADER</div>
<div>SUB-SUB-HEADER</div>
</div>
<div class="footer-box">
<h2>
LINK |
LINK |
LINK |
LINK |
LINK |
LINK |
LINK
</h2>
</div>
</div>
</div>
You have 'posititon:static' assigned to both '.footer-box' and ''#contact-banner'' elements. The '#contact-banner' element has a bottom position of 30px, so when the '.footer-box' list elements stack it increases the height of that element. Once the height of the '.footer-box' element is greater than 30px, it will overlap the '#contact-banner' element.
To solve this issue I have just remove position:static from both of those elements and added it to the '#contact-footer-merged' wrapper.
#contact-footer-merged {
position:fixed;
bottom:0;
left:0;
right:0;
width:100%;
}
.info-banner {
font-family: Arial, sans-serif;
font-size: 24px;
background: #000000;
color: #FFFFFF;
text-align: center;
opacity: 0.8;
}
.info-banner a {
color: #FFFFFF;
text-decoration: none;
}
.info-banner a:hover {
color: #aaa;
}
.footer-box {
font-family: Arial, sans-serif;
color: #FFFFFF;
background-color: #000000;
font-size: 11px;
opacity: 0.8;
z-index: 50;
}
.footer-box h2 {
margin-top: 0;
margin-bottom: 0;
font-size: 20px;
text-align: center;
line-height: 30px;
font-weight: normal;
font-family: Arial, sans-serif;
color: #A9A9A9;
}
.footer-box a {
text-decoration: none;
outline: none;
color: #A9A9A9;
}
.footer-box a:hover {
text-decoration: underline;
}
<div id="contact-footer-merged">
<div id="contact-banner" class="info-banner">
<div>HEADER</div>
<div>SUB-HEADER</div>
<div>SUB-SUB-HEADER</div>
</div>
<div class="footer-box">
<h2>
LINK |
LINK |
LINK |
LINK |
LINK |
LINK |
LINK
</h2>
</div>
</div>
</div>
I'm trying to centre my banner img that is right underneath the nav bar. I want to put text on it aligned left.
I've been able to do that BUT the text on the image is not responsive at all. How do I make it so that the text changes size when browser changes size? Also, I think my CSS is all over the place so if you have any advice on that it would be much appreciated!
Here is the markup:
.topimage img {
position: relative;
width: 100%;
padding-top: 10px;
}
li {
list-style-type: none;
}
h1 {
z-index: 100;
position: absolute;
color: #272727;
font-size: 45px;
font-weight: normal;
left: 650px;
top: 250px;
font-family: Helvetica Neue, arial, serif;
}
.maintitle p {
z-index: 100;
position: absolute;
color: #272727;
font-size: 17px;
font-weight: normal;
left: 650px;
top: 390px;
font-family: Helvetica Neue, arial, serif;
}
.maintitle ul {
list-style-type: none;
}
a {
text-decoration: none;
}
.maintitle li {
z-index: 100;
position: absolute;
color: #272727;
font-size: 15px;
font-weight: bold;
left: 650px;
top: 470px;
font-family: Helvetica Neue, arial, serif;
border-style: solid;
border-width: medium;
border-color: #272727;
border-radius: 6px;
padding: 6px;
}
a:visited {
text-decoration: none;
color: #272727;
}
.maintitle a:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
.maintitle li:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
<div class="topimage">
<img alt="plant" src="images/main.png" />
</div>
<div class="maintitle">
<h1>Marketing Communications & <br> Digital Design</h1>
<p>Marketing enthusiast who has also ventured into the digital design world. Combining <br> strategy with creativity is essential in my books!</p>
<ul>
<li class="aboutme"><a id="aboutmelink" href="#about">My Story</a></li>
</ul>
</div>
This is what I'm trying to achieve:
enter image description here
There are several issues here. Yet, the most important is your use of absolute positioning. It's completely unnecessary. All you really need to do is use a margin of auto to center the elements.
In this case, instead of positioning h1, p and ul separately, we can move them into a wrapper element.
If you want to shrink the actual font size according to screen width, use something along the lines of font-size: 10vw;
.wrap{
margin: 200px auto 0;
min-width: 320px;
max-width: 500px;
}
.topimage img {
position: relative;
width: 100%;
padding-top: 10px;
}
li {
list-style-type: none;
}
h1 {
z-index: 100;
color: #272727;
font-size: 45px;
font-weight: normal;
top: 250px;
font-family: Helvetica Neue, arial, serif;
}
.maintitle p {
z-index: 100;
color: #272727;
font-size: 17px;
font-weight: normal;
top: 390px;
font-family: Helvetica Neue, arial, serif;
}
.maintitle ul {
list-style-type: none;
padding: 0;
}
a {
text-decoration: none;
}
.maintitle li {
z-index: 100;
color: #272727;
font-size: 15px;
font-weight: bold;
font-family: Helvetica Neue, arial, serif;
border-style: solid;
border-width: medium;
border-color: #272727;
border-radius: 6px;
padding: 6px;
}
a:visited {
text-decoration: none;
color: #272727;
}
.maintitle a:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
.maintitle li:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
<div class="topimage">
<img alt="plant" src="images/main.png" />
</div>
<div class="maintitle">
<div class="wrap">
<h1>Marketing Communications & <br> Digital Design</h1>
<p>Marketing enthusiast who has also ventured into the digital design world. Combining <br> strategy with creativity is essential in my books!</p>
<ul>
<li class="aboutme"><a id="aboutmelink" href="#about">My Story</a></li>
</ul>
</div>
</div>
* {
box-sizing: border-box;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
a {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #272727;
}
body {
font-family: Helvetica Neue, arial, serif;
}
.container {
max-width: 1024px;
width: 100%;
margin: 0 auto;
padding: 0 2%;
}
.topimage img {
position: relative;
width: 100%;
padding-top: 10px;
}
.maintitle h1 {
position: relative;
color: #272727;
font-size: 8vw;
}
.maintitle p {
z-index: 100;
position: relative;
color: #272727;
font-size: 4vw;
font-weight: normal;
}
.maintitle ul li {
z-index: 100;
position: relative;
color: #272727;
font-size: 15px;
font-weight: bold;
border-style: solid;
border-color: #272727;
border-radius: 6px;
padding: 6px;
}
.maintitle ul li:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
<div class="container">
<div class="topimage">
<img alt="plant" src="images/main.png" />
</div>
<div class="maintitle">
<h1>Marketing Communications &<br>Digital Design</h1>
<p>Marketing enthusiast who has also ventured into the digital design world. Combining <br> strategy with creativity is essential in my books!</p>
<ul>
<li class="aboutme"><a id="aboutmelink" href="#about">My Story</a></li>
</ul>
</div>
</div>
I might have understand it wrong, but if you want to have a background image with text over it, you can use a background-image in CSS.
<div class="banner">
<div class="maintitle">
<h1>Marketing Communications & <br> Digital Design</h1>
<p>Marketing enthusiast who has also ventured into the digital design
world. Combining <br> strategy with creativity is essential in my books!</p>
<ul>
<li class="aboutme"><a id="aboutmelink" href="#about">My Story</a></li>
</ul>
</div>
</div>
And then the CSS
.banner {
background-image:url('images/main.jpg');
background-position:center;
position: relative;
width: 100%;
padding-top: 10px;
}
.maintitle {
width:100%;
blahblahblah
... }
so I'm trying to get a handle on web designing and such (again). Haven't practiced in a long long time, I've been doing tutorials via codecademy.
Now I wanted to edit the code myself and change things as much as i could.
I can't seem to get the drop down menu to work. I got it to work using javascript toggle but I don't like that I have to reclick the menu to close it, and I'd much prefer the hover method via css as its also simpler (or so i thought lol).
now a lot of the examples I've seen use the pound sign " # ", I don't understand why, I've always known to use " .whatever " for my class selector.
my html code for the section i wanted the drop down menu for:
<ul class="menu">
<li class="dropdown">Join a Clan<b class="caret"></b>
<ul class="dropdown-menu">
<li>Warriors[WAR]
</li>
<li>Twizted[TWIZ]
</li>
</ul>
</li>
and entire CSS for it:
.container {
width: 960px;
}
/* Header */
.header {
background-color: rgba(255, 255, 255, 0.95);
border-bottom: 1px solid #ddd;
font-family:'Oswald', sans-serif;
font-weight: 300;
font-size: 17px;
padding: 15px;
}
/* Menu */
.header .menu {
float: right;
list-style: none;
margin-top: 5px;
}
.menu > li {
display: inline;
padding-left: 20px;
padding-right: 20px;
}
.menu a {
color: #898989;
}
/* Dropdown */
.dropdown-menu:hover {
font-size: 16px;
margin-top: 5px;
min-width: 105px;
}
.dropdown-menu:hover li a {
color: #898989;
padding: 6px 20px;
font-weight: 300;
}
/* Carousel */
.slider {
position: relative;
width: 100%;
height: 470px;
border-bottom: 1px solid #ddd;
}
.slide {
background-size: cover;
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.active-slide {
display: block;
}
.slide-copy h1 {
color: #363636;
font-family:'Oswald', sans-serif;
font-weight: 400;
font-size: 40px;
margin-top: 105px;
margin-bottom: 0px;
}
.slide-copy h2 {
color: #b7b7b7;
font-family:'Oswald', sans-serif;
font-weight: 400;
font-size: 40px;
margin: 5px;
}
.slide-copy p {
color: #959595;
font-family: Georgia, "Times New Roman", serif;
font-size: 1.15em;
line-height: 1.75em;
margin-bottom: 15px;
margin-top: 16px;
}
.slide-img {
text-align: right;
}
/* Slide feature */
.slide-feature {
text-align: center;
height: 470px;
}
.slide-feature img {
margin-top: 112px;
margin-bottom: 28px;
}
.slide-feature a {
display: block;
color: #6fc5e0;
font-family:"HelveticaNeueMdCn", Helvetica, sans-serif;
font-family:'Oswald', sans-serif;
font-weight: 400;
font-size: 20px;
}
.slider-nav {
text-align: center;
margin-top: 20px;
}
.arrow-prev {
margin-right: 45px;
display: inline-block;
vertical-align: top;
margin-top: 9px;
}
.arrow-next {
margin-left: 45px;
display: inline-block;
vertical-align: top;
margin-top: 9px;
}
.slider-dots {
list-style: none;
display: inline-block;
padding-left: 0;
margin-bottom: 0;
}
.slider-dots li {
color: #bbbcbc;
display: inline;
font-size: 30px;
margin-right: 5px;
}
.slider-dots li.active-dot {
color: #363636;
You are putting :hover on the wrong element. Try this:
.dropdown-menu {
font-size: 16px;
margin-top: 5px;
min-width: 105px;
display: none;
}
.dropdown:hover .dropdown-menu {
display: block;
}
.dropdown .dropdown-menu li a {
color: #898989;
padding: 6px 20px;
font-weight: 300;
}
I have a problem with the Height Tag in CSS. I want the page to be displayed without any scrollbars and just can't figure out why when i change "height" in the body tag from 99% to 100% suddenly scrollingbars appear and break the design.
I want to know why this happens and what's the reason for it.
thanks!
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html {
height:100%;
}
body {
height: 99%;
margin-left: 20px;
margin-top:0px;
}
.gallerytitle {
position: absolute;
top: 20px;
font-family: serif;
font-size: 20px;
text-align: left;
}
.fullgallerytitle {
text-align: left;
font-family: sans-serif;
font-size: 12px;}
.events{
position: absolute;
font-family: sans-serif;
font-size: 12px;
top: 20px;
right: 20px;}
/* Center Text Section */
.area {
width: 100%;
height: 100%;
position: relative;
}
.middlespace {
position: absolute;
left: 50%;
top: 50%;
display: table;
}
.middlespace p {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.bottom-left {
position: absolute;
font:sans-serif;
bottom: 15px;
left: 15px;
}
.contact {
font-size: 11px;
font-family: sans-serif;
border-bottom: 1px black dotted;
}
.exhibitiontitle {
color: #d4d4d4;
font-style: italic;
font-family: sans-serif;
font-size: 10px;
text-align: center;
}
.contact {
font-size: 11px;
font-family: sans-serif;
border-bottom: 1px black dotted;
}
.bold {
font-family: serif;
}
.about {
font-size: 11px;
font-family: sans-serif;
}
.address {
font-size: 11px;
border-bottom: 1px grey dotted;
}
.bottom-right {
position: absolute;
bottom: 15px;
right:15px;
font-style: italic;
color: #8e8e8e;
font-size: 11px;
}
.openinghours {
font-style: italic;
color: #8e8e8e;
font-size: 11px;
}
.subscribebutton
{
height:10px;
font-size: 9px;
}
.subscribebox
{
height:10px;
font-size: 9px;
}
</style>
<title>XYZ</title>
</head>
<body>
<div class="gallerytitle">XYZ<br /></div>
<div class="events">LOREM</div>
<div class="bottom-left">
<span class="about">
<span class="bold">XYZ</span> is a project by XZY. |
<span="address">Website Information</span> — info#info.com
</span>
</div>
<div class="bottom-right">
<span class="openinghours">Open by Appointment</span><span class=""> sponsored by XYZ</span>
</div>
</body>
</html>
There is also bottom margin on the body.
body {
height: 100%;
margin: 0 0 0 20px;
}
Though you should consider using a css reset such as eric meyers reset or normalize
Replacing your body style with this should solve the issue :
body {
height: 100%;
margin-left: 20px;
margin:0px;
}
It breaks the page because you use 99% of the page, then you move everything to the right of 20px. it moves the 99% outside and use more. here is the solution, i think both of them work :
body {
height: 100%;
margin-left: 20px;
margin-right: -20px;
margin-top:0px;
}
or
body {
height: 100%;
padding-left: 20px;
padding-right: -20px;
margin-top:0px;
}