Centring svg in div [duplicate] - javascript

This question already has answers here:
How can I center an absolutely positioned element in a div?
(37 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 2 years ago.
im trying to centre the black svg logo in the middle of the pink div surrounded by the 4 coloured divs. Wondering why its not working with the exiting code right now? I tried adding a float on the svg to hopfully move it beside the right brown div but it didnt seem to work. Any ideas on how to center properly?
<style>
ul {
margin:0;
display: flex;
align-items: stretch;
justify-content: space-between;
width: 77%;
}
li {
display: block;
font-size:17px;
text-decoration:none;
}
.navtext{
background-color:orange;
width: 35%;
height:20%;
right:0px;
position:absolute;
display: flex;
align-items: center;
}
body {
margin: 0;
}
.header{
background-color:yellow;
width:100%;
height:20%;
}
.logo{
position:absolute;
left:5%;
background-color:lightblue;
height:20%;
display: flex;
align-items: center;
}
.logotext{
font-size:27px;
font-weight:bold;
}
.front {
background-color:blue;
height: 81vh;
position: relative;
z-index: 2;
width:100%;
}
.video {
background: url(https://picsum.photos/id/107/800/800) center/cover;
height: 100vh;
margin-top: -100vh;
position: sticky;
width:100%;
top: 0;
}
.container {
height:200vh;
}
.right{
right:0px;
width:50%;
Height:91%;
position:absolute;
background-color:pink;
/*display: flex;*/
justify-content: center;
align-items: center;
}
.logoanimecont{
text-align:center;
width:75%;
margin:auto;
}
.left{
width:50%;
Height:91%;
background-color:green;
display: flex;
justify-content: center;
align-items: center;
}
.titlebox {
text-align:center;
width:75%;
background-color:purple;
margin:auto;
}
.title {
font-size:30px;
text-align:center;
}
.hide{ display:none }
.rightbordertop{
width:100%;
height:25%;
background-color:red;
}
.rightborderbottom{
width:100%;
height:25%;
bottom:0px;
position:absolute;
background-color:darkgrey;
}
.rightborderleft{
width:25%;
height:75%;
background-color:brown;
}
.rightborderright{
right:0px;
height:75%;
width:25%;
background-color:blue;
position:absolute;
}
svg {position:absolute; width:50%; height:50%;}
</style>
<div class="container">
<div class="front">
<div class="header">
<div class="logo">
<span class="logotext">f-e</span>
</div>
<div class="nav">
<div class="navtext">
<ul>
<li>About</li>
<li>Services</li>
<li>Clients</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
<div class="left">
<div class="titlebox">
<span class="title">Random text, centered v and h.</span>
</div>
<div class="right">
<div class="rightbordertop"></div>
<div class="rightborderright"></div>
<div class="rightborderleft"></div>
<div class="rightborderbottom"></div>
<div class="logoanimacont">
<div class="logoanime">
<svg viewBox="0 0 70 70">
<path id="metabolism" d="M0,0v72h72V0H0z M45.38,12.19l-1.21,1.66c-0.16,0.23-0.35,0.26-0.57,0.09c-1.47-1-2.85-1.18-4.13-0.53
c-1.41,0.75-2.11,2.19-2.11,4.31v9.47h4.62c0.28,0,0.42,0.15,0.42,0.44v2.06c0,0.29-0.14,0.44-0.42,0.44h-4.62v23.85
c0,0.29-0.14,0.44-0.42,0.44h-2.02c-0.26,0-0.39-0.15-0.39-0.44V30.14H31.8c-0.28,0-0.42-0.15-0.42-0.44v-2.06
c0-0.29,0.14-0.44,0.42-0.44h2.72v-9.47c0-1.58,0.32-2.98,0.97-4.19c0.64-1.23,1.55-2.15,2.72-2.75c1.09-0.56,2.25-0.77,3.5-0.63
c1.25,0.12,2.44,0.59,3.59,1.41C45.53,11.73,45.56,11.94,45.38,12.19z"/>
<path id="technique" class="hide" d="M0,0v72h72V0H0z M40.05,36.57c0,0.22-0.11,0.33-0.33,0.33h-8.62c-0.22,0-0.33-0.11-0.33-0.33V35
c0-0.2,0.11-0.3,0.33-0.3h8.62c0.22,0,0.33,0.1,0.33,0.3V36.57z"/>
<path id="digital" class="hide" d="M0,0v72h72V0H0z M45.89,36.15c0,0.19-0.09,0.29-0.28,0.3l-16.83,1.48c0.47,1.7,1.41,3.1,2.81,4.2
c1.44,1.11,3.06,1.66,4.88,1.66c1.38,0,2.66-0.34,3.87-1.01c1.19-0.66,2.15-1.56,2.88-2.72c0.11-0.19,0.26-0.23,0.45-0.12
l1.36,0.77c0.19,0.12,0.23,0.28,0.12,0.47c-0.94,1.48-2.18,2.66-3.73,3.52c-1.53,0.86-3.18,1.29-4.95,1.29
c-2.81,0-5.21-0.99-7.2-2.98c-2-2-3-4.41-3-7.22c0-2.86,0.96-5.27,2.88-7.24c1.91-1.97,4.24-2.95,7.01-2.93
c2.69,0.02,4.98,1.01,6.89,2.98c1.89,1.95,2.84,4.3,2.84,7.03V36.15z"/>
</svg>
</div>
</div>
</div>
</div>
</div>
<div class="video"></div>
</div>
<div style="height:150vh"> more content later </div>

Does this give you what you're after?
svg {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
width: 50%;
height: 50%;
}

Related

Scrollable part of page

I want to have a similar effect like on this page: https://melaniedaveid.com/ (half of the page is scrollable).
I can make a sticky box, but there are certain things that I don't know how to make, such as the text. The text must be bigger than the box, but if overflow: hidden, then it is not scrollable. If it's overflow: scroll, it scrolls only if the mouse is hovering over the section, but I want the mouse to be able to scroll anywhere on the page.
body {
display: flex;
}
.example {
width: 50%;
}
.block {
background: #888888;
height: 300px;
/* margin: 1em; */
border: 1px solid black;
}
.block.one {
height: 100px;
}
.box {
width: 100%;
height: 100px;
background: orange;
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
}
.sticky {
position: sticky;
top: 10px;
}
.orange{
background: orange;
}
<div class="example">
<div class="block one"></div>
<div class="block">
<p class="box sticky"> </p>
</div>
<div class="block"></div>
</div>
<div class="example">
<div class="block one"></div>
<div class="block orange"></div>
<div class="block"></div>
</div>
Is this how you want it?
To create the sticky effect use position: sticky.
Code:
#wrapper {
display:flex;
flex-direction:row;
}
#sticky {
position: sticky;
position: -webkit-sticky;
background: #f83d23;
width: 50%;
height: 300px;
top: 0;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 0 6px #000;
color: #fff;
}
#para{
width:50%;
margin:10px;
}
<div id="wrapper">
<div id="sticky">
sticky
</div>
<div id="para">
This is a para
</div>
</div>

HTML/CSS - Display the link while hovering over a photo

I want to have my link displayed when I hover over the image. The way I wrote the code displays the link only if I hover over the link itself(which is contained in the image div). Any ideas how I should go on?
.image-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100px;
padding-right: 100px;
font-size: 1.5em;
}
.image-text-wrapper .xx {
transition: 1s;
font-weight: 600;
margin: 20px;
}
.image-text-wrapper .xx a {
color: transparent !important;
}
.image-text-wrapper a:hover {
color: lightseagreen !important;
text-decoration: none;
}
<div class="portfolio-img-background" style="background-image:url()">
<div class="xx">
<a href="#">
Text
</a>
</div>
</div>
This is a solution using just CSS
#image{
width:200px;
height:200px;
background:black;
display:flex;
align-items:center;
justify-content: center;
}
#link{
display:none;
}
#image:hover > #link {
display:block;
}
<div id="image" class="portfolio-img-background" style="background-image:url()">
<div class="xx" id="link">
<a href="#">
Hi!, im a link
</a>
</div>
</div>
This CSS class at the bottom of your code can be slightly modified to make this work.
.image-text-wrapper:hover a {
color: lightseagreen !important;
text-decoration: none;
}

How to make 3 column two side by side one middle my divs takes everything to left

I am trying to make simple css layout. I want 3 box
{Left} {center} {right}
So I write this code
#myleft {
position: relative;
float: left;
width: 20%;
background-color: #CC6600;
}
#mycenter {
width: 60%;
background-color: #f2f4f4;
}
* html #mycenter {
height: 1%
}
#myright {
position: relative;
float: right;
width: 20%;
background-color: #FF6633;
}
<div id='left'> Left </div>
<div id='mycenter'> Center </div>
<div id='right'> right </div>
but instead of
{left} {center} {right}
{left}
{center}
{right}
I don't know why but it goes like this even the float is left and right
You didn't name your div id's correctly. they should be myleft and myright
body {
width: 100%;
}
#myleft {
position:relative;
float:left;
width:20%;
background-color:#CC6600;
}
#mycenter {
width:60%;
float: left;
background-color:#f2f4f4;
}
#mycenter {
height:1%
}
#myright {
float:left;
width:20%;
background-color:#FF6633;
}
<div id='myleft'> Left </div>
<div id='mycenter'> Center </div>
<div id='myright'> right </div>
Wrap your divs into a main div and try to use Flexbox
Stack Snippet
.d-flex {
display: flex;
flex-wrap: wrap;
}
#myleft {
position: relative;
width: 20%;
background-color: cyan;
}
#mycenter {
width: 60%;
background-color: #f2f4f4;
}
#myright {
position: relative;
width: 20%;
background-color: cyan;
}
<div class="d-flex">
<div id='myleft'> Left </div>
<div id='mycenter'> Center </div>
<div id='myright'> right </div>
</div>
And, of course, there is grid. First wrap the "gridded" elements
<div id='wrapper'>
<div id='left'> Left </div>
<div id='center'> Center </div>
<div id='right'> right </div>
</div>
#wrapper {
display: grid;
grid-template-columns: 2fr 6fr 2fr;
}
Then, optionally, if you want the content of each sub-div to be centered:
#left, #right, #center {
margin-left:auto;
margin-right:auto;
}
.container {
display: flex;
}
.box1 {
flex: 1 ;
text-align: center;
background-color: gray;
}
.box2 {
flex: 2;
text-align: center
}
.box3 {
flex: 1;
text-align: center;
background-color: gray;
}
<div class="container">
<div class="box1">
<p> text</p>
</div>
<div class="box2">
<p> text</p>
</div>
<div class="box3">
<p> text</p>
</div>
</div>

How do I slide a Div in <li> using javascript or Jquery?

I am required to me make a Textual slider which is going to slide after every 3 seconds but I am not able to find out how to to do this.
the slider must slide the div inside it from right to left. It is not just like any image slider.
Kindly help me out how to achieve this, i have tried all the help from stackoverflow and jsFiddle but i am not getting anything thats why I have left my Script blank so that you can tell me how to do step by step.
here is my code:
<div class="dslider">
<div class="d30">
<div class="bottom_mini_slide_container">
<ul class="bottom_ul">
<li>
<div class="bottom_single_div">
<div class="bottom_single_div_padded">
<span class="make_big"><img src="images/background/client says.png" /></span>
<p>
Make1 an outline by
assembling scattered
elements together...”
</p>
</div>
</div>
</li>
<li>
<div class="bottom_single_div">
<div class="bottom_single_div_padded">
<span class="make_big"><img src="images/background/client says.png" /></span>
<p>
Make2 an outline by
assembling scattered
elements together...”
</p>
</div>
</div>
</li>
<li>
<div class="bottom_single_div">
<div class="bottom_single_div_padded">
<span class="make_big"><img src="images/background/client says.png" /></span>
<p>
Make3 an outline by
assembling scattered
elements together...”
</p>
</div>
</div>
</li>
</ul>
</div>
</div>
<div class="d70">
<div class="top_mini_slide_container">
</div>
</div>
</div>
CSS:
.dslider{
height: 696px;
width: 100%;
background-color: rgb(255,255,255);
float: left;
background:url(../images/background/Slider%20Background.png) no-repeat;
background-size:100% 100%;
}
.d30{
width:37.5%;
float:left;
height:100%;
}
.d70{
width:62.5%;
float:left;
height:100%;
}
.bottom_mini_slide_container{
width:100%;
height:471px;
position:relative;
top:224px;
border-top:1px solid #000;
border-right:1px solid #000;
}
.top_mini_slide_container{
width:100%;
height:570px;
position:relative;
top:0;
border-bottom:1px solid #000;
border-left:1px solid #000;
}
.bottom_ul{
display:block;
width:100%;
height:100%;
padding:0;
margin:0;
overflow:hidden;
}
.bottom_ul li{
display:block;
width:100%;
height:100%;
overflow:hidden;
float:left;
}
.bottom_single_div{
width:100%;
height:100%;
float:left;
}
.bottom_single_div_padded{
padding-top: 150px;
width: 81%;
height: 289px;
float: left;
padding-right: 19%;
}
.bottom_single_div_padded p{
font-size: 28px;
text-align: left;
padding-left: 65px;
padding-right: 65px;
margin: 0;
margin-top: -39px;
color:#1294de;
padding-top: 83px;
}
.make_big{
font-size: 64px;
position: relative;
left: 39px;
top: 64px;
font-family:mifont;
}
and here is the blank script:
<script>
$('document').ready(function(e) {
setInterval(function(){
}, 3000);
});
</script>

Make a div to fill the rest of the available screen height

I have this structure:
I would like to make content2's min-height = height of screen - height of other divs.
With the HTML/CSS below, the outcome is greater than the screen height. So How can I do what I wanted? The copyright part (footer) is inside the content2, so I want to make the content2's height to be exact in the screen.
body {
margin:0;
border:0;
background-color:#24373B;
color: #fff;
}
#headerBG {
min-width:980px;
background-color:#000;
}
#header {
width:980px;
}
#content1 {
width:980px;
}
#content2 {
width:960px;
padding:10px;
margin-top:30px;
background-color:#355258;
min-height:100hv;
}
<body>
<div id="headerBG">
<div id="header">header</div>
</div>
<div id="content1">content1</div>
<div id="content2">content2</div>
</body>
You are using 100hv instead of 100vh as min height. Fixed:
#content2{
width:960px;
padding:10px;
margin-top:30px;
background-color:#355258;
min-height: calc(100vh - 50px);
}
But before you use vw or vh, you should define:
html {
width: 100%;
height: 100%;
}
body {
width: 100%;
height: 100%;
}
You don't have to use viewport units (vw, vh). You could simply do it with CSS table layout as follows. The height of the pink area will expand and fill out all the free space automatically.
http://jsfiddle.net/qtu89zhm/
html, body {
height: 100%;
margin: 0;
}
.table {
display: table;
width: 100%;
height: 100%;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
}
.box {
width: 500px;
margin: 0 auto;
}
.content-2 .cell, .content-2 .box {
height: 100%;
}
.header .cell {
background: gray;
}
.header .box {
background: teal;
}
.content-1 .box {
background: gold;
}
.content-2 .box {
background: pink;
}
<div class="table">
<div class="row header">
<div class="cell">
<div class="box">header</div>
</div>
</div>
<div class="row content-1">
<div class="cell">
<div class="box">content1</div>
</div>
</div>
<div class="row content-2">
<div class="cell">
<div class="box">content2</div>
</div>
</div>
</div>
If I understand your question correctly...
body{
margin:0;
border:0;
background-color:#555555;
height:100vh;
width:100vw;
}
#headerBG{
min-width:980px;
background-color:#AAAAAA;
height:10%;
}
#header{
width:980px;
height:100%;
width:10%;
background-color:#FFF;
}
#content1{
width:980px;
height:40%;
background-color:#000000;
margin-left:5%;
width:90%;
}
#content2{
margin-top:30px;
background-color:#FFFFFF;
margin-left:5%;
width:90%;
height:50%;
}
<body>
<div id="headerBG">
<div id="header">
</div>
</div>
<div id="content1">
</div>
<div id="content2">
</div>
</body>

Categories

Resources