I have a div that I am wanting to rotate -20deg. I have gotten it to do just that, the problem I am facing is that it is not displaying it across the whole screen.
It is obviously just displaying a div that is 100% width and 100% height. What I am wanting it to do is cover the whole screen at an angle, so you can not see the left/right corners. If I extend the width above 100% it works but that is only going to push the width of the entire browser out.
Is there any way to get it to display at an angle so that it doesn't show the corners and is across the whole screen?
Fiddle: https://jsfiddle.net/2dhkk03b/
.content {
width: 70%;
margin: 0 auto;
position: relative;
height: 700px;
}
.intro {
width: 60%;
text-align: left;
position: absolute;
top: 50px;
color: black;
font-weight: 300;
font-size: 2em;
}
.para_txt {
padding-top: 40px;
}
.intro p {
font-size: 24px;
}
.slide {
position: relative;
width: 100%;
background-color: red;
height: 400px;
transform: rotate(-20deg);
}
<div class="content">
<div class="intro">
<span>Hi there!</span>
<p class="para_txt">My name</p>
</div>
</div>
<div class="slide"></div>
You can use a pseudo element for the rotated rectangle and set overflow hidden on the parent div to hide the corners and prevent the bottom scrollbar :
.content {
width: 70%;
margin: 0 auto;
position: relative;
height: 700px;
}
.intro {
width: 60%;
text-align: left;
position: absolute;
top: 50px;
color: black;
font-weight: 300;
font-size: 2em;
}
.para_txt {
padding-top: 40px;
}
.intro p {
font-size: 24px;
}
.slide {
position: relative;
height: 1000px;
overflow: hidden;
}
.slide:after {
content: '';
position:absolute;
top:35%;
width:100%; height: 30%;
background: red;
transform: rotate(-20deg);
}
<div class="content">
<div class="intro">
<span>Hi there!</span>
<p class="para_txt">My name</p>
</div>
</div>
<div class="slide">
</div>
The problem is the corners of the div are square so if you rotate a rectangle x degrees you will lose some width.
The ideal solution would be to increase the size and minus the left margin for example.
width: 180%;
margin-left: -40%;
Thanks
Related
I'm trying to create a 90 deg rotated layout. But the problem is that none of the method I used to use works in this case. Since it is rotated, changing size, getting it responsive does not seem to work.
I'm trying to let the "My Project" title take half of the rotated screen and the other half will contain
images and containers.
Can anyone help me out with this? How do i make sure that it resizes and placement is always half:half layout without overflow during resize in different device size. Please provide me with a hint to complete my work. Thank you!
Link to the code in jsfiddle.
Here's a link to the think I'm doing:
https://jsfiddle.net/7tfy4gdh/1/
Here's what i want to build: https://prnt.sc/10wb1p7
One way to think of this is to design everything as though it was not rotated and with the container having width 100vh and height 100vw. Then when everything is in place, rotate container by 90 degrees and translate it so it exactly fits within the viewport.
To ensure it is all responsive, use relative units wherever possible. So have widths and heights as %s. Think about padding, possibly define it in terms of vmin and you may also want to define font size relatively so it grows on larger screens.
So, implement this first:
This snippet starts the process, defining a left side div and a right side div, centering the main component of each and rotating and translating the container. It isn't the full job, the logo side needs more work - and you may find defining everything in %s etc that it is better not to use flex but to control the use of the whole space yourself.
And remember that just because something is rotated it does not mean that its height becomes the vertical side...
Here's some code to start things off:
<head>
<style>
* {
box-sizing: border-box;
margin:0;
padding: 0;
overflow: visible;
}
body {
width: 100vw;
height: 100vh;
overflow: visible;
}
.container {
text-align: center;
width: 100vh;
height: 100vw;
transform: rotate(90deg) translateY(-100%);
transform-origin: 0% 0%;
overflow: hidden;
}
.container .left-side {
position: relative;
width: 50vh;
height: 100vw;
float: left;
}
.container .left-side .project-title {
position: relative;
top: 50%;
transform: translateY(-50%);
}
.container .project-title span {
text-align: center;
}
.container .right-side {
position: relative;
top: 0;
width: 50vh;
height: 100vw;
float: left;
padding: 1vmin;
}
.container .right-side .control {
position: relative;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
rmax-width: 450px;
rmin-width: 350px;
height: 80%;
width: 80%;
background-color: red;
padding: 5%;
}
.control .logo {
height: 25%;
}
.control .logo img {
width:100px;
height: 100%;
width: auto;
}
.logo-container {
flex:1;
display:flex;
margin-top: 5%;
height: 30%;
}
.logo-maker{
flex:1;
padding:25px 10px;
background-color: #ccc;
color:#ffffff;
border-radius: 8px;
padding-top: 15px;
}
.logo-maker .maker-contain {
width:50px;
background-color: #ccc;
border-radius: 8px;
padding:5px;
padding-bottom: 0;
margin:auto;
}
.logo-maker .maker-contain img{
width:100%;
}
.logo-maker h3 {
margin-top: 15px;
}
.earn-coin {
flex:1;
text-align: center;
padding:25px 0;
padding-top: 15px;
margin-left: 5px;
border-radius: 8px;
background-color: #ccc;
box-shadow: 5px 4px 5px -5px rgba(0,0,0,0.76);
-webkit-box-shadow: 5px 4px 5px -5px rgba(0,0,0,0.76);
-moz-box-shadow: 5px 4px 5px -5px rgba(0,0,0,0.76);
}
.earn-coin img {
width:40px;
margin:auto;
}
.earn-coin h3{
margin-top: 15px;
}
.footer {
padding:20px 30px;
padding-left: 55px;
background-color: #ccc;
background-color: purple;
height: 25%;
color:#ffffff;
border-radius: 5px;
margin-top: 5%;
text-align: left;
}
.footer i{
font-size:35px;
}
.footer h3 {
display: inline;
margin-left: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="left-side">
<div class="project-title">
<h2>
My Project
</h2>
</div>
</div>
<div class="right-side">
<div class="control">
<div class="logo">
<img src="https://d1csarkz8obe9u.cloudfront.net/posterpreviews/lion-fire-logo-design-template-free-89daa14626ac403bd3cf6282036663ff_screen.jpg?ts=1572094154">
</div>
<section class="logo-container">
<div class="logo-maker">
<div class="maker-contain">
<img src="https://www.logaster.com/blog/wp-content/uploads/2018/05/LogoMakr.png" alt="">
</div>
<h3>Build Logo</h3>
</div>
<div class="earn-coin">
<div class="coin-img">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSEWIhIZ48jnuWwHjIZ9I_EpQbRsHrFtomThQ&usqp=CAU">
</div>
<h3>Earn Coins</h3>
</div>
</section>
<div class="footer">
<i class="fa fa-bell"></i>
<h3>
Build by Dave ___
</h3>
</div>
</div>
</div>
</div>
</body>
I have the following HTML/CSS code:
<style>.dummy {
color: greenyellow;
}
.middle-container {
position: absolute;
top: 50%;
left: 50%;
}
.middle-container-box {
width: 50px;
height: 50px;
background-color: red;
}
.middle-container-text {
color: red;
font-weight: bold;
font-size: 15px;
}
</style>
<html>
<body>
<div class="dummy">
Lorem Ipsum is simply dummy text...
</div>
<div class="middle-container">
<div class="middle-container-box"></div>
<div class="middle-container-text">
this text needs to be in the center
</div>
</div>
</body>
</html>
In this sandbox: https://codesandbox.io/s/2py075pqnr
I need to have middle-container at the center of the screen and the div and the text elements (which are inside of this container) to be centralized inside of the container.
So it should be moved to the left, something as: https://prnt.sc/n349h1 (we need to move it only to the left). But moving it with fixes values (in pixels) is not an option, since I need this working on all screens resolutions.
You need to use translate to move to box back to the centre and flex to centre it's children:
.dummy {
color: greenyellow;
}
.middle-container {
position: absolute;
top: 50%;
left: 50%;
transform:translate(-50%, -50%); /* this moves this box back to the middle (back up and left 50% of itself) */
display:flex; /* the following four align it's children to the center horizontally and vertically */
flex-direction:column;
align-items:center;
justify-content:center;
}
.middle-container-box {
width: 50px;
height: 50px;
background-color: red;
}
.middle-container-text {
color: red;
font-weight: bold;
font-size: 15px;
}
<div class="dummy">
Lorem Ipsum is simply dummy text...
</div>
<div class="middle-container">
<div class="middle-container-box"></div>
<div class="middle-container-text">
this text needs to be in the center
</div>
</div>
You can do it with transfom
CSS
.dummy {
color: greenyellow;
}
.middle-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.middle-container-box {
width: 50px;
height: 50px;
background-color: red;
display: inline-block;
}
.middle-container-text {
color: red;
font-weight: bold;
font-size: 15px;
}
DEMO HERE
Change .middle-container, set top, left, right, bottom to 0 then set margin to auto. Your text is already in the center because it's giving the div it's width, what you need to do is put .middle-container-box in the middle setting display to block and margin to 0 auto. See below:
.middle-container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.middle-container-box {
width: 50px;
height: 50px;
background-color: red;
display: block;
margin: 0 auto;
}
.middle-container-text {
color: red;
font-weight: bold;
font-size: 15px;
text-align: center;
}
I have a webpage with responsive design, whose body I have set to max-width: 500px; and a div 'arrow' whose margin-left:45%. When screen size goes beyond 500px, the body stays fine and fixed, but since the div arrow's margin-left is 45% of screen size, it starts moving in the wrong direction.
Is there a way to set a max on margin-left so that arrow div doesn't move beyond a point even if screen-size keeps increasing?
CSS Code is below:
.arrow {
background-color:#ECEFF5;
width: 30px;
margin-top: -12px;
position: absolute;
margin-left: 45%;
}
html, body {
margin: 0 auto;
}
body {
background-color: #ECEFF5;
font-weight: lighter;
max-width: 500px;
}
And HTML is:
<body>
<div class="userdata">
<h2 style="font-weight:bold;"> First Name</h2>
<input class="input" type="text" name="firstname">
</div>
<div class="arrow">
<img src="arrow.png" style="position:absolute; width: 30px;">
</div>
<div class="instructions" id="test">
<h5>Step 1/7</h5>
<hr width="100%">
<h6 >Write your name here</h6>
<a href="xyz.html" class="button-nav" > Back </a>
</div>
Add position:relative; to the body. Then the margin will be 45% of the body rather than the window.
Eg:
.arrow {
background-color: red;
width: 30px;
margin-top: -12px;
position: absolute;
/* margin-left: 45%; */
left: 45%; /* <- why not just position left rather than using a margin? */
}
html, body {
margin: 0 auto;
height: 100%; /* <-just for demo */
}
body {
background-color: #ECEFF5;
font-weight: lighter;
max-width: 500px;
border: 1px solid red; /* <-just for demo */
position: relative; /* <- make relative */
}
<div class="arrow">arrow</div>
try with %50 margin-left and - width/2 left position to centre
.arrow {
background-color:#ECEFF5;
width: 30px;
margin-top: -12px;
position: absolute;
margin-left: 50%;
left:-15px;
}
Remove position: absolute and make margin-left:auto;
Such that:
.arrow {
background-color:#ECEFF5;
width: 30px;
margin-top: -12px;
margin-left: auto;
}
Right now, if you look at my page on my computer, it will look the way I want it to look. Now if you go on a pc with higher/lower resolution, the images will move, BUT the text will stay in place, why is that?
I have tried messing around with the position: and height/width percentages, but haven't managed to get it to work properly yet.
I'd like to get the images to stay in one place and resize depending on the resolution.
1st:
2nd:
The HTML:
<div id="content">
<div class="pricing">Pricing</div>
<div><img src="images/bracket.png" class="bracket"></div>
<div class="skills">Skills</div>
<div><img src="images/bracket.png" class="bracket_02"></div>
</div>
The CSS:
#content
{
margin: 0% 13% auto;
height: 100%;
width: 65%;
border-style: solid;
border-width: 1px;
color: white;
position: absolute;
}
.pricing
{
font-size: 40;
font-weight: bold;
margin-top: 6%;
margin-left: 20%;
color: #1eb1f5;
position: absolute;
}
.skills
{
font-size: 40;
font-weight: bold;
margin-top: 6%;
margin-left: 70%;
color: #1eb1f5;
position: absolute;
}
.bracket
{
margin-top: 11%;
margin-left: 8%;
position: absolute;
}
.bracket_02
{
margin-top: 11%;
margin-left: 57%;
position: absolute;
}
I usually use px for everything, but I wanted to try using %, as I have heard it can be better for mobile for example.
Is this what your looking for?
JSFIDDLE
I changed your css and html quite a lot.
I put the text and image in a container .head-elem
set text-align: center to center your text in its container
The width of the .head-elem to 50%. so that it takes up 50% of the width of #content.
Made the image take of full size of its container width: .bracket { width: 100%;}
#content {
width: 500px; //Change this to test out diffrent sizes
border-style: solid;
border-width: 1px;
color: white;
}
.head-elem {
width: 50%;
text-align: center;
display: inline-block;
font-size: 1em;
font-weight: bold;
color: #1eb1f5;
}
.bracket {
width: 100%;
}
<div id="content">
<div class="head-elem">
<span>Pricing</span>
<img src="http://www.i2symbol.com/images/symbols/brackets/presentation_form_for_vertical_left_curly_bracket_uFE37_icon_256x256.png" class="bracket" />
</div>
<div class="head-elem">
<span>Skills</span>
<img src="http://www.i2symbol.com/images/symbols/brackets/presentation_form_for_vertical_left_curly_bracket_uFE37_icon_256x256.png" class="bracket" />
</div>
</div>
Try adding the width in % for the class images:
.bracket
{
margin-top: 11%;
margin-left: 8%;
position: absolute;
width: 50%;
}
.bracket_02
{
margin-top: 11%;
margin-left: 57%;
position: absolute;
width: 50%;
}
Hello i have a problem with my images in divs.
jsFiddle
.navbar {
position: fixed;
z-index: 1000;
height: 100%;
width: 60px;
left: 0px;
top: 0px;
background-color: #2e2d2d;
border-right: 1px solid #c6c5c5;
}
#works {
position: relative;
margin-left: 60px;
height: 100%;
}
.left {
position: relative;
width: 50%;
float: left;
}
.right {
position: relative;
height: 100%;
width: 50%;
float: left;
}
#works .up {
width: 100%;
height: 50%;
}
.up h1 {
font-family: ralewayregular;
text-transform: uppercase;
text-decoration: none;
font-size: 10px;
padding: 10px 15px;
}
.up h2 {
font-family: ralewayregular;
font-size: 5pt;
padding: 1px 15px;
}
.down_1 {
float: left;
width: 50%;
height: 50%;
}
.down_2 {
float: left;
width: 50%;
}
<div class="navbar">
<a class="menu-trigger"></a>
</div>
<section id="works">
<div class="all">
<div class="left">
<img src="http://i.telegraph.co.uk/multimedia/archive/02194/Bank2_2194348b.jpg" width="100%">
</div>
<div class="right">
<div class="up">
<h1>bl bla</h1>
<h2>/asdasda <br /> as : VENEZIA
/ SELLEKTOR / SUGARPILLS / NIKKI LISSONI</h2>
<div class="arrow"></div>
</div>
<div class="down_1">
<img src="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg" width="100%" height="100%" />
</div>
<div class="down_2">
<img src="http://cutebabywallpapers.com/wp-content/uploads/2014/09/cute-a-little-baby-and-cat-pictures.jpg" width="100%" />
</div>
</div>
</div>
</section>
Div left must have the same hight like div right. Both should end in one line.
How to do this without giving them hight, to not strech my images? Div up and down should have 50% height but its not working.
Someone can help me solve it?
For them to to be the same height, there most be some measure, strict height or min-height.
For the height to measure, do something like:
.left, .right {
width: 100%; /* Adjust as needed */
min-height 50%; /* best to be the same as what you assume would
be the height of the taller both DIV's so that nothing will be cut off */
}
For your image not to be distorted, do something like:
.right img, .right img, {
width: 100%;
height: auto; /* Set the height to auto to give the
image a breathing space to reduce distortion */
}