How to float two divs above an image? - html

I have two divs and two images in one div. The images are stacked. The div they are inside is relative and the images and the two divs are absolute. Now I want to float one div on the right side but it didn't work .
Here is my fiddle : https://jsfiddle.net/2vrq243v/2/
#newsline {
position: relative;
padding-top: 60px;
transition: 0.5s;
width: 100%;
height: 400px;
overflow: hidden;
}
#newsline a img {
position: absolute;
transition: 1s;
height: 360px;
width: 90%;
margin: 20px 5% 20px 5%;
}
.move {
z-index: 1;
width: 100px;
height: 100px;
display: table;
position: absolute;
border-radius: 50px;
margin-top: 150px;
cursor: pointer;
background-color: rgb(255, 255, 255, 0.25);
}
.move:hover {
background-color: rgb(255, 255, 255, 0.6);
}
.move p {
height: 100%;
text-align: center;
vertical-align: middle;
display: table-cell;
color: rgb(250, 255, 255, 0.7);
font-size: 250%;
background-color: none;
}
.move p:hover {
color: darkslategrey;
}
.next {
float: right;
}
.previous {
margin-left: 6%;
}
<div id="newsline">
<div class="move next">
<p>⮚</p>
</div>
<div class="move previous">
<p>⮘</p>
</div>
<img src="https://www.planwallpaper.com/static/images/8ccb4ec4225b290726ae9be975220ff4.jpg" id="img1">
<img src="http://hdwpro.com/wp-content/uploads/2017/11/Awesome-Wallpaper.jpg" id="img2">
</div>

I think you want something like this? You can adjust the position of the two divs using the left and right property, this is possible because they have the position: absolute.
JSFiddle
.next {
right: 6%;
}
.previous {
left: 6%;
}

Hey whenever you are using a position in css use left, right instead of float left or right. Your Problem can be solved by following code:
.next {
right: 55px;
}
Remove float:right; use right and give the required value

For the proper positioning of controls use:
.next {
right: 0;
margin-right: 6%
};
.previous {
left: 0;
margin-left: 6%;
}

Related

Right Align Div CSS

I'm trying to right align a div on my navigation bar for my website. The goal is to align the div so it's always aligned in the same place towards the right of the webpage. I've tried margins, CSS positioning, and changing the div to display: inline-block;
body {
overflow-x: hidden;
font-size: large;
margin: 0;
}
h1,
h2,
h3,
h4 {
font-family: 'Montserrat', sans-serif;
}
.nav-bar {
z-index: 98;
background-color: rgba(204, 204, 204, 0.8);
padding: 15px;
}
.nav-img {
height: 100px;
}
.nav-options {
text-align: right;
}
.nav-option {
border: none;
background-color: rgba(204, 204, 204, 0.1);
height: 100px;
width: 150px;
font-size: large;
cursor: pointer;
transition: all 0.5s ease-out;
position: relative;
bottom: 15px;
}
.nav-option:hover {
background-color: rgba(204, 204, 204, 0.1);
color: white;
}
p,
ul,
ol,
li,
select {
font-family: 'Poppins', sans-serif;
}
.line {
width: 50px;
background-color: white;
z-index: 99;
height: 0.5px;
}
.hamburger-menu {
background-color: transparent;
border: none;
display: inline-block;
}
.mobile-nav {
display: none;
}
.mobile-menu {
margin: 50px;
padding: 0;
z-index: 98;
position: fixed;
right: 0%;
bottom: -6%;
background-color: rgba(204, 204, 204, 0.8);
width: 100%;
height: 110%;
margin-left: auto;
margin-right: auto;
padding: 50px;
}
.mobile-options {
position: absolute;
list-style: none;
top: 0;
width: 100%;
display: flex;
justify-content: center;
flex-direction: column;
height: 110%;
}
.mobile-option {
width: 100%;
height: 50px;
font-size: large;
letter-spacing: 2px;
line-height: 100%;
text-align: center;
background-color: rgba(204, 204, 204, 0.8);
border: none;
padding-right: 60px;
}
.exit-btn {
width: 50px;
background-color: transparent;
border: none;
font-size: 4rem;
color: white;
font-family: 'Montserrat', sans-serif;
font-weight: lighter;
float: right;
position: absolute;
bottom: 75%;
left: 75%;
}
#media screen and (max-width: 830px) {
.desktop-nav {
display: none;
}
.mobile-nav {
display: inline-block;
}
}
<div class="nav-bar">
<nav class="desktop-nav">
<img src="https://picsum.photos/100" class="nav-img">
<div class="nav-options">
<button class="nav-option">About Us</button>
<button class="nav-option">Classes</button>
<button class="nav-option">Contact Us</button>
</div>
</nav>
<nav class="mobile-nav">
<img src="https://picsum.photos/100" class="nav-img">
<div class="nav-options">
<button class="hamburger-menu" id="mobile-menu-enter">
<div class="line"></div><br>
<div class="line"></div><br>
<div class="line"></div>
</button>
</div>
</nav>
</div>
You can use float: right;.
You can also find other solutions here How do I right align div elements?
You could use position absolute to remove the element from the DOM and move your element anywhere relative to the first containing parent element up the DOM tree that has a position set. Then use positioning props like top, right, bottom and/or left to move the element on the page.
See MDN on position for more info
:root {
--padding: .5em;
}
/* This is the parent element, set its position to relative
so the right-div will be positioneed relative to it */
#parent {
background: red;
padding: .5em;
position: relative;
}
#first-div {
background: yellow;
padding: var(--padding);
}
p {
padding: var(--padding);
background: white;
}
/* set this divs position to absolute so its top, left, bottom, right
positioning props will be relative to its closest parent set to relative */
#right-div {
position: absolute;
right: calc(var(--padding) + 0px);
top: calc(var(--padding) + 0px);
background: green;
color: white;
padding: var(--padding);
<div id="parent">
<div id="first-div">This is the first div</div>
<p>This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a
paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph This is a paragraph</p>
<div id="right-div">This is the right div</div>
</div>
I ended up setting the position to absolute and using vw as the property for the left attribute.
.hamburger-menu {
background-color: transparent;
border: none;
position: absolute;
left: 80vw;
margin-right: 5vw;
}

How can a child override the opacity of the parent?

Currently I'm working on a website for a community and its getting a bit difficult, I have a nice pink>orange gradient with a image below it with a opacity of 0.2, to show both. That looks like this.
As you can see, the logo also has the opacity. I already found something about the rgba-color, but that did'nt work.
How can I solve this problem? I want the image with the border to have a full opacity.
body {
background-color: #f2f2f2;
color: #404040;
}
div.navbar {
height: 600px;
background: rgba(255, 255, 255, 0.7);
background-image: linear-gradient(25deg, #ec008c, #fc6767);
margin-top: -10px;
margin-left: -5px;
position: relative;
width: 105%;
}
img.logo {
position: absolute;
margin-top: 4%;
margin-left: 25%;
height: 40%;
padding: 25px;
border: 25px solid #f2f2f2;
border-radius: 50%;
}
div.image {
position: relative;
height: 100%;
opacity: 0.2;
background-image: url("img/slide1.jpg");
background-repeat: no-repeat;
background-size: cover;
}
div.nav {
position: absolute;
bottom: 0;
margin-left: 600px;
margin-bottom: 50px;
}
a.nav-item {
color: #f2f2f2;
font-weight: bold;
font-size: 25pt;
margin-right: 50px;
text-decoration: underline;
}
a.nav-item:hover,
a.nav-item .active {
text-decoration: overline underline;
}
<div class="navbar">
<img class="logo" src="img/logo.png">
<div class="image">
</div>
<div class="nav">
<a class="nav-item">Home</a>
<a class="nav-item">Twee</a>
</div>
</div>
Use the background property for both image and gradient. then take your gradient from the rgba equivalents of your hex values (Chrome dev tools color picker is good for this).
body {
margin: 0;
}
div.navbar {
height: 100vh;
/*
IMPORTANT BITS:
- ADDED image and gradient to navbar background and
- REMOVED opacity
THE REST:
The rest was just to make the demo look better/simpler
*/
background:
linear-gradient(25deg, rgba(236, 0, 140, 0.7), rgba(252, 103, 103, 0.7)),
url(http://placeimg.com/1000/600/arch) no-repeat center;
background-size: cover;
position: relative;
}
.logo-wrapper {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 25%;
height: 0;
padding-top: 25%;
border:25px solid #f2f2f2;
border-radius: 50%;
overflow: hidden;
}
.logo {
width: 90%;
border-radius: 50%;
position: absolute;
top: 5%;
left: 5%;
}
<html>
<head>
<link rel="stylesheet" href="css.css">
</head>
<body>
<div class="navbar">
<div class="logo-wrapper">
<img class="logo" src="http://placeimg.com/200/200/tech/grayscale">
</div>
</div>
</body>
</html>
Child can't override opacity of parent due to how opacity is managed by the browsers.
Simplest way to achieve this is to place the visual child after the parent and then use a negative margin-top to draw the child on top of the parent. You don't need absolute positioning.
.frame{
background-color: #AAAAAA;
opacity: 0.2;
border-radius: 13px;
padding: 21px;
color: #000000;
height: 73px;
}
.frametxt{
margin-top: -73px;
color: #000000 !important;
opacity: 1.0;
}

How can I make a div cover the entirety of a div behind it?

I am trying to have a square-shaped div (the red box) on the page by default. When the user hover the mouse over it, a second div should display with a semi-transparent black background and some text/content. I'm trying to imitate Devon Stank's project section on his website.
The code I have right now increases the height of the default square red box and the second div doesn't cover the whole of the red box. What's wrong with the code?
Fiddle
.project-box {
position: relative;
width: 30%;
padding-top: 30%;
overflow: hidden;
margin-right: 20px;
margin-bottom: 15px;
display: inline-block;
}
.default-box {
background-color: red;
}
.hover-content {
position: relative;
width: 100%;
height: 100%;
padding-top: 30%;
overflow: hidden;
display: inline-block;
}
.default-hover {
opacity: 0;
-webkit-transition: 0.5s;
-moz-transition: 0.5s;
-o-transition: 0.5s;
-ms-transition: 0.5s;
transition: 0.5s;
background-color: rgba(0, 0, 0, 0.5);
}
.default-box:hover .default-hover {
opacity: 1;
}
<div class="default-box project-box">
<div class="default-hover hover-content">hello</div>
</div>
height: 100%; won't work on the element if the parent's height isn't defined.
Also, if you stick with position: relative with a padding on the parent, you won't be able to cover it all.
If you want to cover all the .project-box (parent) no matter its padding values,
I suggest you to use an absolute positioning on its child:
(I've done it by adding the new class .veil, but it could be done within your existing class)
.project-box {
position: relative; /* ADDED so that the absolute positioning refers to this parent */
width: 30%;
padding-top: 30%;
overflow: hidden;
margin-right: 20px;
margin-bottom: 15px;
display: inline-block;
}
.default-box {
background-color: red;
}
.hover-content {
/* REMOVED position and sizes */
padding-top: 30%;
overflow: hidden;
display: inline-block;
}
.default-hover {
opacity: 0;
transition: 0.5s;
background-color: rgba(0, 0, 0, 0.5);
}
.default-box:hover .default-hover {
opacity: 1;
}
/* ADDED this class */
.veil {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
<div class="default-box project-box">
<!-- Added a class for the child here -->
<div class="default-hover hover-content veil">hello</div>
</div>
Hope it helps.
Here, it may help you, try it.
.project-box {
position: relative;
width: 30%;
height:100%
}
.default-box {
background-color: red;
}
.hover-content {
position: relative;
width: 100%;
height: 100%;
text-align:center;
padding-top: 30%;
}

Progress bar circle not center in bootstrap

Im try to center in webpage this Progress bar circle but i cant do it , how can i center , please help me to fix that issue , ,im try to put that text-center but not work for me, please look at this image you can understand that issue,
thanks
/jsfiddle
html
<div class="content-wrap">
<div>
<div class="progress-bar position text-center" data-percent="48" data-duration="1000" data-color="#6a6f77,#5fb756"><script>$(".progress-bar").loading()</script></div>
</div>
</div>
css
/* Progress Bar */
.progress-bar {
text-align: center;
height: 150px;
width: 150px;
margin-left: 55px;
margin-top: 65px;
}
.progress-bar {
float: left;
width: 0;
height: 100%;
font-size: 12px;
line-height: 20px;
color: #fff;
text-align: center;
-webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .15);
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .15);
-webkit-transition: width .6s ease;
-o-transition: width .6s ease;
transition: width .6s ease;
}
.progress-bar div {
position: absolute;
height: 200px;
width: 200px;
border-radius: 50%;
}
.progress-bar div span {
position: absolute;
font-family: sans-serif;
font-size: 60px;
line-height: 175px;
height: 175px;
width: 175px;
left: 12.5px;
top: 13.5px;
text-align: center;
border-radius: 50%;
background-color: #ffffff;
color: black;
}
.progress-bar .background {
background-color: #b3cef6;
}
.progress-bar .rotate {
clip: rect(0 100px 200px 0);
background-color: #4b86db;
}
.progress-bar .left {
clip: rect(0 100px 200px 0);
opacity: 1;
background-color: #b3cef6;
}
.progress-bar .right {
clip: rect(0 100px 200px 0);
transform: rotate(180deg);
opacity: 0;
background-color: #4b86db;
}
#keyframes toggle {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
/*End of Progress Bar*/
Try this: Just add style:"text-align:center" in div, below the content-wrap div
.progress-bar {
text-align: center;
height: 150px;
width: 150px;
/* margin-left: 55px;*/
margin-left: calc(100%/2 - 100px);
margin-top: 65px;
}
try this
.progress-bar{
float: none;
display: block;
margin: 0 auto;
}
If you are using multiple progress bar, then try this
.progress-bar{
float: none;
display: inline-block;
margin: 0 auto;
}
.on-parent-element{
text-align: center
}
UPDATE-
here is working fiddle - https://jsfiddle.net/thesumit67/6jz40dfa/6/
You should add proper width on progress bar element, and remove float use inline-block instead.
In your fiddle you made two mistakes.
add jQuery before progress bar plugin.
use HTTPS to load external resources. ( check in your console )

CSS hide top part of text

I prefer CSS only solution; I can change HTML structure; Always only single line of text
TL;DR;
How to hide top part of text instead of bottom:
div {
overflow: hidden;
height: 11px;
}
<div>HOME</div>
Full example
I want to hide top of the text line so I can simulate transition effect:
div {
height: 20px;
width: 100px;
text-align: center;
}
div span {
display: block;
overflow: hidden;
transition: all 500ms ease-in-out;
height: 20px;
}
div .default {
color: black;
background-color: #f0f0f0;
}
div .hover {
height: 0;
color: white;
background-color: black;
}
div:hover .hover {
height: 25px;
}
div:hover .default {
height: 0px;
}
<div>
<span class="default">HOME</span>
<span class="hover">HOME</span>
</div>
As you can see in example .hover is currently sliding from bottom because text is hidden from bottom to top when height is reduced.
I want to hide text from top to bottom, so that it will look like same text is inverting it's color.
Are you against if I use pseudo elements to do it ? I play with bottom height to make it appears from top to bottom with the text in content property.
div .default {
display: block;
overflow: hidden;
height: 20px;
position: relative;
color: black;
background-color: #f0f0f0;
}
div .default:after { content: "Home"; position: absolute; left: 0; bottom: 100%; right: 0; background: #000; color: #fff; text-transform: uppercase; transition: all 500ms ease-in-out;}
div .default:hover:after { bottom: 0; }
HTML
<div>
<span class="default">HOME</span>
</div>
Like this
Other solution keeping the structure and avoid text in content property
<div>
<span class="default">HOME</span>
<span class="black">HOME</span>
</div>
CSS
div .black { position: absolute; left: 0; bottom: 100%; right: 0; background: #000; color: #fff; text-transform: uppercase; transition: all 500ms ease-in-out;}
div .default:hover ~ .black { bottom: 0; }
Fiddle with 2nd solution
I have solved that by using absolute positioned element over origin item:
div {
height: 20px;
width: 100px;
text-align: center;
position: relative;
}
div span {
display: block;
overflow: hidden;
transition: all 500ms ease-in-out;
height: 20px;
}
div .default {
color: black;
background-color: #f0f0f0;
/* ADDED */
position: absolute;
left: 0;
z-index: 10;
top: 0;
width: 100%;
height: 100%;
}
div .hover {
height: 20px;
color: white;
background-color: black;
}
div:hover .default {
height: 0px;
}
<div>
<span class="default">HOME</span>
<span class="hover">HOME</span>
</div>
Given your first example, this one hides top part of the text. Just play around with the line-height on your animation
Just add on your div span style:
line-height: 5px; /* play with the value till desired look is reached*/
https://jsfiddle.net/w0ydLg9h/