I have 3 li's that I am trying to line up horizontally and then position a span inside each of the li's.
The spans get positioned correctly in Chrome but are well outside the boundary of the li's in Firefox.
http://jsfiddle.net/brendan_rice/mPnCh/1/
Can anyone help please?
<div id="blank-slate-steps">
<ul>
<li class="first">
<h3><em>Step 1</em>Create Something</h3>
<p>Once you have created Something Else you can Create Final Thing</p>
<span></span>
</li>
<li class="second">
<h3><em>Step 2</em>Create Something Else</h3>
<p>Once you have created Something Else you can Create Final Thing</p>
<span></span>
</li>
<li class="third">
<h3><em>Step 3</em>Create Final Thing</h3>
<p>Once you have created Something Else you can Create Final Thing</p>
<span></span>
</li>
</ul>
</div>
CSS
body{
padding-top: 300px;
}
#blank-slate-steps {
background-color: #E8E8E8;
bottom: 0;
font-family: OpenSansCondensedBold,sans-serif;
text-align: center;
width: 100%;
}
#blank-slate-steps li {
display: table-cell;
max-width: 300px;
padding: 40px;
position: relative;
width: 300px;
}
#blank-slate-steps h3 {
font-size: 1.6em;
margin-bottom: 0.6em;
}
#blank-slate-steps h3 em {
color: #878787;
float: left;
font-size: 0.8em;
font-style: normal;
margin-bottom: 4px;
text-transform: uppercase;
width: 100%;
}
#blank-slate-steps li.second span {
background: red url("../images/sprite/icons-grey-38.png") no-repeat scroll 0 -56px transparent;
height: 37px;
width: 36px;
}
#blank-slate-steps span {
background-color: red;
display: block;
height: 20px;
left: -10px;
position: absolute;
top: 50px;
width: 20px;
}
use position relative for blank-slate-steps div.
#blank-slate-steps {
background-color: #E8E8E8;
bottom: 0;
font-family: OpenSansCondensedBold,sans-serif;
text-align: center;
width: 100%;
position: relative;
}
Ok, I've made it work, you can do it like this : fiddle
Explanation: What I did was, I used position: relative; for #blank-slate-steps and than used position: relative; again for div and wrapped the <li> content inside it
HTML
<div id="blank-slate-steps">
<ul>
<li class="first">
<div style="position: relative;">
<h3><em>Step 1</em>Create Something</h3>
<p>Once you have created Something Else you can Create Final Thing</p>
<span></span>
</div>
</li>
<li class="second">
<div style="position: relative;">
<h3><em>Step 2</em>Create Something Else</h3>
<p>Once you have created Something Else you can Create Final Thing</p>
<span></span>
</div>
</li>
<li class="third">
<div style="position: relative;">
<h3><em>Step 3</em>Create Final Thing</h3>
<p>Once you have created Something Else you can Create Final Thing</p>
<span></span>
</div>
</li>
</ul>
</div>
CSS
body{
padding-top: 300px;
}
#blank-slate-steps {
background-color: #E8E8E8;
bottom: 0;
font-family: OpenSansCondensedBold,sans-serif;
text-align: center;
width: 100%;
position: relative;
}
#blank-slate-steps li {
display: table-cell;
max-width: 300px;
padding: 40px;
width: 300px;
}
#blank-slate-steps h3 {
font-size: 1.6em;
margin-bottom: 0.6em;
}
#blank-slate-steps h3 em {
color: #878787;
float: left;
font-size: 0.8em;
font-style: normal;
margin-bottom: 4px;
text-transform: uppercase;
width: 100%;
}
#blank-slate-steps li.second span {
background: red url("../images/sprite/icons-grey-38.png") no-repeat scroll 0 -56px transparent;
height: 37px;
width: 36px;
}
#blank-slate-steps span {
background-color: red;
display: block;
height: 20px;
left: -10px;
position: absolute;
top: 50px;
width: 20px;
}
Try to put your span in first like that:
<li class="second">
<span></span>
<h3><em>Step 2</em>Create Something Else</h3>
<p>Once you have created Something Else you can Create Final Thing</p>
</li>
and put the span in position:relative and float:left
Related
I expect these 3 colored rectangles under the "card" to line up with the whole "card". Right now they are positioned slightly to the right. I don't really know what did I mess up. I searched a lot of stuff but didn't find a fix, that's why I'm here. I hope that someone can help me because this thing is giving me a headache.
#import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght#0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap%27)');
* {
margin: 0;
}
li {
list-style: none;
}
#bCard {
width: 460px;
height: 350px;
left: 50%;
transform: translate(-50%);
position: absolute;
}
#bCardTop {
background: rgb(61, 61, 61);
width: 460px;
height: 75px;
display: flex;
justify-content: center;
align-items: center;
}
#tpdne1 {
width: 60px;
height: 60px;
border-radius: 50%;
}
#bCardTopProfession {
color: white;
margin-left: 6px;
font-family: poppins;
font-size: 24px;
font-weight: 500;
justify-content: center;
}
#bCardBottom {
background: rgb(43, 43, 43);
width: 460px;
height: 175px;
}
#socialLinks {
display: inline-flex;
}
#socialLinks li {
width: 153.33px;
height: 100px;
}
/* add before and after later */
#test1 {
background: tomato;
}
#test2 {
background: lime;
}
#test3 {
background: cyan;
}
<div id="bCard">
<div id="bCardTop">
<img id="tpdne1" src="https://i.ibb.co/cx9F4K1/tpdne-1.jpg" alt="thispersondoesnotexist">
<!-- change src back to ./img/tpdne_1.jpg later -->
<div id="bCardTopProfession">
Professional Idiot
</div>
</div>
<div id="bCardBottom">
</div>
<ul id="socialLinks">
<li id="test1">
<a href="#">
</a>
</li>
<li id="test2">
<a href="#">
</a>
</li>
<li id="test3">
<a href="#">
</a>
</li>
</ul>
</div>
I think you want this
#socialLinks {
padding: 0;
display: flex;
}
Just add a padding:0 to the socialLinks list
I have a class of divs that behave predicatively. The code is as follows:
.nav
{
background-color: none;
height: 50px;
width: 100px;
text-align: center;
color: white;
font-family: "comic sans", times, serif;
display: inline-block;
margin: auto;
margin-left: 2px;
padding-top: 15px;
}
This is inside a wrapper id navbar:
#navbar
{
width: 100%;
height: 50px;
background-color: #141414;
}
But whenever I try to add a picture or a large word to one of these divs, the rest of the divs, which contain text, are moved so that only the part containing the text is inside the wrapper and the rest hang down and outside of the wrapper.
For example:
<div id="navbar">
<div class="nav" style="background-image:url('xyz.jpg'); width:
100px; height: 50px;"></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Home</a></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Genres</a></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Favorites</a></div>
</div> <!-- End of navbar -->
I tried searching online but I have not been able to find a solution to this issue. Has anyone experienced this issue in the past?
Try to add: { display: flex;}
.nav
{
background-color: none;
height: 50px;
width: 100px;
text-align: center;
color: white;
font-family: "comic sans", times, serif;
margin: auto;
margin-left: 2px;
padding-top: 15px;
}
#navbar
{
display:flex;
width: 100%;
height: 50px;
background-color: #141414;
}
<div id="navbar">
<div class="nav" style="background-image:url('paper.gif'); width:
100px; height: 50px;"></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Home</a></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Genres</a></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Favorites</a></div>
</div>
You can read about flex here:https://www.w3schools.com/css/css3_flexbox.asp
add to .nav
.nav{
overflow:"hidden";
}
also i recommend to use:
<div class="nav">
<img src="logo.png" style="width: 100%; height: 100%">
</div>
insted
<div class="nav" style="background-image:url('logo.png'); width:
100px; height: 50px;"></div>
also if you want to div to be 50px and its have 15px padding so acctually you want to set the height for 35px (35px height + 15px padding = 50px) so:
.nav{
height:35px;
}
Declaring all child objects as inline-block and adjusting the line-height for the nav divs to the height of the nav divs themselves seems to have worked.
I managed to make it work with the following configuration:
body
{
margin: 0px;
}
#navbar
{
/*shape*/
width: 100%;
height: 50px;
/*decoration*/
background-color: #141414;
/*display: no configuration needed*/
/*Lesson learned - Only display methods applied to child objects count*/
}
.nav
{
/*decoration*/
background-color: none;
color: white;
font-family: "comic sans", times, serif;
overflow: hidden;
line-height: 50px;
text-align: center;
/*shape*/
height: 50px;
/*display*/
display: inline-block;
margin: auto;
margin-left: 2px;
}
#navbar
{
width: 100%;
height: 50px;
background-color: #141414;
}
#logo
{
/*decoration*/
background-image: url("https://ssl.gstatic.com/ui/v1/icons/mail/rfr/logo_gmail_lockup_dark_1x.png");
background-size: 100%;
/*shape*/
height: 50px;
width: 200px;
/*display*/
display:inline-block;
}
<div id="navbar">
<div id="logo"></div>
<div class="nav">Home</div>
<div class="nav">Genres</div>
<div class="nav">Favorites</div>
</div> <!-- End of navbar -->
So I'm using hero image for my website which is 100 vh high. Now the image is positioned absolutely, so I could position other elements like logo, nav and text on the image relatively to it. After this section, I want to start new section with new image and other text, but once I start new row, column and try to put new image with h1 text, it's hiding behind earlier image. What I mean is that I want a new section with new image and <h1> text appear under the hero image and not overlap it or hide under it as it is now hiding. It's not floated or anything, my floats are cleared, so I don't get it why is this hapenning.
Here is some codepen so you would understand what is hapenning.
<div class="container-fluid clearfix">
<div class="row">
<div class="col-lg-12">
<div class="hero_img">
<img class="logo" src="assets/logo.png"></img>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".collapse">
☰
</button>
<div class="collapse">
<div class="col-xs-12">
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="#">Lorem</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Lorem</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Lorem</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Lorem</a>
</li>
</ul>
</div>
</div>
<div class="black_box clearfix"><h1>Kolding Bike Marathon</h1></div>
<div class="black_box_sub clearfix"><p>Bring activity to your life again</p></div>
<button type="button" class="btn btn-outline-secondary">Register now</button>
<button type="button" class="btn btn-success">Learn more</button>
</div>
</div>
</div>
</div>
</div>
<div class="section_one">
<h1>heyyyyy</h1>
</div>
.hero_img {
background-image: url("assets/hero.jpg");
width: auto;
height: 100vh;
background-size: cover;
position: absolute;
top: 0;
left: 0;
z-index: 999;
overflow: hidden;
clear: both;
}
.hero_img {
width: 100%;
height: 100vh;
position: absolute;
top: 0;
}
.logo {
position: relative;
left: 20px;
top: 20px;
z-index: 1002;
width: 5%;
min-width: 50px;
}
.nav {
position: relative;
top: 0;
z-index: 1000;
margin-top: 20px;
/*margin-right: 15px;*/
padding: 20px;
/*float: right;*/
width: auto;
flex-direction: column;
background: #555;
/*width: 100%;*/
filter: opacity(0.93);
}
a {
text-decoration: none;
color: white;
display: block;
border-bottom: 1px solid #444;
}
a:hover {
color: #999;
}
.nav-item {
display: block;
}
.navbar-toggler {
/*float: right;*/
display: flex;
justify-content: right;
position: relative;
z-index: 1000;
margin-top: 15px;
margin-right: 15px;
color: white;
float: right;
}
.black_box {
position: relative;
width: 45%;
min-width: 400px;
text-align: center;
z-index: 1000;
background: black;
margin-top: 10%;
padding: 10px 30px;
clear: both;
}
.black_box h1 {
color: white;
/*font-family: 'PT Sans', sans-serif;*/
font-family: 'Montserrat', sans-serif;
font-weight: 600;
letter-spacing: 1.5px;
}
.black_box_sub {
position: relative;
width: 30%;
min-width: 310px;
text-align: center;
z-index: 1001;
background: black;
margin-top: 2%;
clear: both;
margin-left: 90px;
}
.black_box_sub p {
color: white;
padding: 5px 25px;
font-family: 'Montserrat', sans-serif;
text-transform: uppercase;
padding-top: 10px;
padding-bottom: 0px;
}
Codepen: http://codepen.io/Limpuls/pen/NpbwYp
There are multiple items to clean up in the code, but to keep the images from overlapping you can remove both entries of position: absolute; from the .hero_img class.
After that, remove the padding left and right from all of the media queries of container-fluid. This may affect and other padding that was needed in that container but would be a quick path to do what you are asking.
I can't get the background-image to display. I thought adding the min-width might make the image visible in case it was really small, but that didn't work. I've checked the url. It works as a normal image if put straight into the body.
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel = stylesheet href = Father.css>
<title> Very Important Company </title>
</head>
<body>
<div id = backs </div>
<div class = header>
<p>
<img src = http://www.unixstickers.com/image/data/stickers/opensuse/Opensuse-logo-wob.sh.png id = gecko>
</p>
<div class = navigation>
<ul>
<li> SHOP </li>
<li> ABOUT US </li>
<li> RENTALS </li>
<li> CONTACT </li>
<li> PARTIES </li>
</ul>
</div>
</div>
<p>
<div class = main>
<p1> Our Eggs
</p1>
</div>
</body>
</html>
CSS:
* {
margin: 0;
padding: 0;
}
#backs {
background: white;
}
#gecko {
content:url(http://www.unixstickers.com/image/data/stickers/opensuse/Opensuse-logo-wob.sh.png);
height: 128px;
width: 128px;
position: relative;
float: left;
margin-left: 10px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
display: inline;
}
li {
display: inline;
padding-left: 50px;
min-width: 100%
}
.navigation {
color: black;
letter-spacing: 2px;
float: right;
vertical-align: top;
width: 800px;
height: 70px;
margin-top: 47px;
min-width:800px;
padding-left: 150px;
position: absolute;
}
.main {
color: black;
font-size: 60px;
position: relative;
top: 150px;
background-image: url (http://files.vividscreen.info/soft/fc5e9b0dc8833c69951d28bb856b9ef4/Decorated-Easter-Eggs-2880x1920.jpg);
min-width: 100%;
height: 900px;
border: 2px solid red;
padding-top: 100px;
}
The format for the path to an image in background-image is url(...) not url (...)
So your line should be
background-image: url(http://files.vividscreen.info/soft/fc5e9b0dc8833c69951d28bb856b9ef4/Decorated-Easter-Eggs-2880x1920.jpg);
I think you should use bakground-image property rather than content
background-image:url(http://files.vividscreen.info/soft/fc5e9b0dc8833c69951d28bb856b9ef4/Decorated-Easter-Eggs-2880x1920.jpg);
this is your css
.main {
color: black;
font-size: 60px;
position: relative;
top: 150px;
background-image: url (http://files.vividscreen.info/soft/fc5e9b0dc8833c69951d28bb856b9ef4/Decorated-Easter-Eggs-2880x1920.jpg);
min-width: 100%;
height: 900px;
border: 2px solid red;
padding-top: 100px;
}
you have space between url and (http://files.vividscreen.info/soft/fc5e9b0dc8833c69951d28bb856b9ef4/Decorated-Easter-Eggs-2880x1920.jpg); in the background-image:. Remove the space and it should work.
Hi just remove the space before background-image:url and then check it (code as below) and close the div tag in <div id=backs> </div>
background-image: url(http://files.vividscreen.info/soft/fc5e9b0dc8833c69951d28bb856b9ef4/Decorated-Easter-Eggs-2880x1920.jpg);
demo
* {
margin: 0;
padding: 0;
}
#backs {
background: white;
}
#gecko {
content:url(http://www.unixstickers.com/image/data/stickers/opensuse/Opensuse-logo-wob.sh.png);
height: 128px;
width: 128px;
position: relative;
float: left;
margin-left: 10px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
display: inline;
}
li {
display: inline;
padding-left: 50px;
min-width: 100%
}
.navigation {
color: black;
letter-spacing: 2px;
float: right;
vertical-align: top;
width: 800px;
height: 70px;
margin-top: 47px;
min-width:800px;
padding-left: 150px;
position: absolute;
}
.main {
background: rgba(0, 0, 0, 0) url("http://files.vividscreen.info/soft/fc5e9b0dc8833c69951d28bb856b9ef4/Decorated-Easter-Eggs-2880x1920.jpg") repeat scroll 0 0;
border: 2px solid red;
color: black;
font-size: 60px;
height: 900px;
min-width: 100%;
padding-top: 100px;
position: relative;
top: 150px;
}
<div id ="backs"></div>
<div class ="header">
<p>
<img src = "http://www.unixstickers.com/image/data/stickers/opensuse/Opensuse-logo-wob.sh.png id = gecko" alt="">
</p>
<div class ="navigation">
<ul>
<li> SHOP </li>
<li> ABOUT US </li>
<li> RENTALS </li>
<li> CONTACT </li>
<li> PARTIES </li>
</ul>
</div>
</div>
<div class ="main">
<p1> Our Eggs
</p1>
</div>
It seems like no matter what I do I just can't get some text with a black background to centre vertically. The problem is that sometimes the text is on one line and sometimes it is on two or even three. I'm trying to get it to automatically adjust but I just can't.
I have tried numerous approaches such as those listed on here.
Here is my code I am trying to centre:
.infogrid {
display: inline-block;
position: relative;
bottom: 45px;
right: 0;
margin: 0px 1% -100% 1%;
width: 98%;
background-color: #F6F6F6;
}
.infogrid ul {
margin: 0;
padding: 0;
text-align: center;
}
.infogrid li {
display: inline-block;
position: relative;
background-color: white;
width: 320px;
margin: 1vw;
height: 320px;
transition: transform 0.4s;
box-shadow: 0.2vh 0vh 0.8vh #888888;
}
.infogrid li:hover {
transform: scale(1.05, 1.05);
}
.tilewrappertext {
display: inline-block;
color: white;
visibility: hidden;
z-index: 1;
width: 100%;
text-align: center;
font-family: "Century Gothic", "Arial", "Sans-Serif";
background-color: black;
opacity: 0.75;
font-size: 2.2em;
}
#tilewrapper:hover .tilewrappertext {
visibility: visible;
}
<div class="infogrid">
<ul>
<li>
<div id="tilewrapper">
<img id="automargins" src="content/tile1.png" width="96%">
<h3 class="tilewrappertext">Half price facials</h3>
</div>
</li>
<li>
<div id="tilewrapper">
<img id="automargins" src="content/tile2.png" width="96%">
<h3 class="tilewrappertext">1/4 off massages</h3>
</div>
</li>
<li>
<div id="tilewrapper">
<img id="automargins" src="content/tile3.png" width="96%">
<h3 class="tilewrappertext">20/3 off hot rocks</h3>
</div>
</li>
<li>
<div id="tilewrapper">
<img id="automargins" src="content/tile4.png" width="96%">
<h3 class="tilewrappertext">20/3 off nails</h3>
</div>
</li>
<li>
<div id="tilewrapper">
<img id="automargins" src="content/tile5.png" width="96%">
<h3 class="tilewrappertext">Free use of sauna with treatment</h3>
</div>
</li>
<li>
<div id="tilewrapper">
<img id="automargins" src="content/tile6.png" width="96%">
<h3 class="tilewrappertext">Free use of jacuzzi with treatment</h3>
</div>
</li>
<li>
<div id="tilewrapper">
<img id="automargins" src="content/tile7.png" width="96%">
<h3 class="tilewrappertext">1/20 off eyes</h3>
</div>
</li>
<li>
<div id="tilewrapper">
<img id="automargins" src="content/tile8.png" width="96%">
<h3 class="tilewrappertext">1/20 off hair</h3>
</div>
</li>
</ul>
</div>
The text appears when the image is hovered over.
Since your li is already position relative, you can add the following css rules to the h3 to center it vertically within the li.:
position: absolute;
top: 50%;
transform: translateY(-50%);
margin: 0;
Example here: http://codepen.io/nicerhugs/details/dMGMEv/
The top will move the top of the h3 halfway down the li, and the transform will correct for the height of the li itself. Getting rid of the margin will take away that weird mystery space that makes it appear to be lower than it really is.
Just go with the Jess's answer. Here is another method to do this using pseudo element aka ghost element in css.
You have to give absolute position to image. add a :after element to div#tilewrapper and make it display inline-block, also make the h3 tag inline-block and apply vertical-align: middle, it will position vertically middle. Little complicate to understand but anyway Here is the code . :)
.infogrid {
display: inline-block;
position: relative;
bottom: 45px;
right: 0;
margin: 0px 1% -100% 1%;
width: 98%;
background-color: #F6F6F6;
}
.infogrid ul {
margin: 0;
padding: 0;
text-align: center;
}
.infogrid li {
display: inline-block;
position: relative;
background-color: white;
width: 320px;
margin: 1vw;
height: 320px;
transition: transform 0.4s;
box-shadow: 0.2vh 0vh 0.8vh #888888;
}
.infogrid li:hover {
transform: scale(1.05, 1.05);
}
.tilewrappertext {
display: inline-block;
color: white;
visibility: hidden;
z-index: 1;
width: 100%;
text-align: center;
font-family: "Century Gothic", "Arial", "Sans-Serif";
background-color: black;
opacity: 0.75;
font-size: 2.2em;
}
#tilewrapper:hover .tilewrappertext {
visibility: visible;
}
.infogrid{
margin-top: 50px;
}
img {
max-height: 320px;
position: absolute;
}
div#tilewrapper{
height: 100%;
}
.tilewrappertext {
display: inline-block;
color: white;
visibility: hidden;
z-index: 1;
width: 100%;
text-align: center;
font-family: "Century Gothic", "Arial", "Sans-Serif";
background-color: black;
opacity: 0.75;
font-size: 2.2em;
vertical-align: middle;
display: inline-block;
vertical-align: middle;
width: calc(100% - 4px);
}
div#tilewrapper:after {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -5px;
}
<div class="infogrid">
<ul>
<li>
<div id="tilewrapper">
<img id="automargins" src="http://1.bp.blogspot.com/-fqGa-MyjVHY/UZPYekbmfHI/AAAAAAAABrg/CC4q0AQsY9o/s320/air-baloon.jpg" width="96%">
<h3 class="tilewrappertext">Half price facials</h3>
</div>
</li>
</ul>
</div>