I am trying to make the text stay in the bottom right corner, but once I change the window height or width, it goes out of the curve (shown here)
I tried positioning it with percentages, vw, vh, em and it still goes out of the curve when the screen size is changed.
Any idea on how to position this so it always stays inside that curve no matter the size of the screen?
Here is the code:
.phone-number {
position: absolute;
bottom: 20vh;
right: 5vh;
color: #472d23;
font-weight: 600;
font-size: 3vh;
}
.landing-page {
background: url("../img/bg2.jpg");
background-size: cover;
background-repeat: no-repeat;
height: 100vh;
background-position: center;
position: relative;
overflow: hidden;
-webkit-transition: all 2s ease-in-out;
-moz-transition: all 2s ease-in-out;
transition: all 2s ease-in-out;
}
.curve {
background: url("../img/Curve.png");
background-position: bottom center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
height: 100vh;
}
<div class="row">
<div id="carasoul" class="landing-page">
<div class="curve">
<div class="container">
<h3 class="phone-number">+1 800-800-800</h3>
</div>
</div>
</div>
</div>
Try this. In HTML, add:
<div class="numBox">
<p class="num">Your number or your stuff</p>
</div>
In CSS, add:
.numBox
{position:relative;}
.num
{position:absolute; bottom:0; right:0;}
Try the following to set the text to fixed location relative to the bottom right corner:
.phone-number {
position: absolute;
bottom: 5px;
right: 5px;
color: #472d23;
font-weight: 600;
font-size: 3vh;
}
Wu. I think I my have a solution for you.
I think you will need a combination of things. Here goes...
First, I think you will need to set your position to relative.
Second, you will need to use a "transform: translate;" setting in your css, but use whatever percentages that you used before to keep the text where you wanted it. You would put those "y" and "x" percentages in the "translate" part of the css code.
Why do I think this would this work?
When you are creating a fullscreen video background for a webpage (or any kind of background for that matter), it is pretty common practice to use the "transform: translate" aspect of code to help insure that the background stays centered no matter what.
And if you think about it, what you're telling the CSS to do is to animate the item into the position you're telling it to be in, no matter the condition or size of the browser.
Using that concept, "transform: translate" should work no matter what position on the screen you want an item to have, whether it is to be centered or not. A really experienced engineer told me a few months ago that all engineering (coding included) is all about understanding CONCEPTS, because no two situations will call for the precise same answer. So the secret to learning is to learn how to adapt and apply concepts.
Sorry... tangent!
Anyway, I think that approach will work, even if I can't supply you exact code.
One more thing...
If "position: relative" doesn't work with what I told you, try "position: absolute".
I hope that helps!
Related
I know it might be a duplicated question, but I couldn't find the answer anywhere else in the internet.
Question is very simple: I want to know how should/could I add shapes/decoration to the page layout correctly so it will not look broken inside a responsive container.
Click here to see the picture!
Actually I don't know the way to add that much shapes without making some mess in the code or completely braking the responsiveness of the container itself. If anybody already have done this, please describe your solution/method of doing this correctly. Thank you in advance and hope this will be useful to somebody else.
You should probably set a position : relative in the parent element and then use position: absolut; with relative unites.
Also take care to have a lower z-index for the decorations:
section {
background-color: rgb(69, 83, 95);
display: inline-block;
position: relative;
width: 70vw;
height: 70vh;
}
.content {
z-index: 2;
}
.element {
position: absolute;
z-index: 1;
color: white;
}
.element1 {
top: 20%;
left: 20%;
}
.element2 {
top: 80%;
left: 30%;
}
.element3 {
top: 50%;
left: 70%;
}
<section>
<span class="element element1">+</span>
<span class="element element2">*</span>
<span class="element element3">*</span>
</section>
As the decorations are just that, with no particular meaning that for example would be read out by a screen reader, I would put them in as background images - either as SVGs or gradients (if suitable) and position and size each one in terms of %s relative to the dimensions of the main element.
That way you have a responsive page and you haven't cluttered up the HTML with elements.
Each of the decorations seems separate, but if they overlap then remember the one that comes first in the background-image list will be shown on top of one coming afterwards.
So you are going to end up with CSS looking something like this:
background-image: url(svg1), url(svg2), url(svg3)...;
background-position: x1% y1%, x2% y2%, x3% y3%,...;
background-repeat: no-repeat no-repeat;
background-size: w1% h1%, w2% h2%, w3% h3%,...;
It's easy to work out the percentages, just use a ruler on the image - any units will do, and divide by the width or height of the main element as appropriate * 100.
Moving from backend to the frontend, I was given a design and don’t know the best way to handle how to implement it. It’s gonna be about 6 or some images or layered. All Images are 1920px wide * X px high.
I did a little fiddle so you can see what I’m working with. A few images are in there too. https://www.bootply.com/EEjlR9IaFN#
So the problem is setting the width and height of the image/div causes it to extend outside of the bootstrap container and it’s not responsive. So that’s where I’m stuck, I can’t think of a way to make these images fit inside of this container and be responsive. I was gonna just use the img tag but would rather do it via css if I can
You can do a little trick that I learned to do the same thing, and it's putting an image behind for the responsive and the background for the front.
HTML:
<div class="element">
<div class="background-image"></div>
<img src="http://via.placeholder.com/1920x1080" class="image-responsive" alt="">
</div>
CSS:
.element{
position: relative;
display: inline-block;
}
.background-image{
background-image: url('http://sharksharkshark.net/snow.png');
background-size: cover;
background-position: center;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.image-responsive{
max-width: 100%;
}
NOTE: You can play and change the size of the back image for the responsive. In this way the div will not be empty but it will be responsive.
Example:
https://jsfiddle.net/grg9rc7z/1/
So i have this image right here
"http://i.imgur.com/eh71foN.png"
My problem is that whenever i resize the window the Mass Effect image doesnt resize with it.
It becomes like this
"http://i.imgur.com/jaDV7jG.png"
I've been trying to figure this out for a while. Can anyone point me in the right direction?
#MassEffectSign {
background: url(masseffect12.png) center top no-repeat;
top: 25px; left: 750px; z-index: 2;
padding: 250px;
position: absolute;
}
My blue background
#bodyBorder {
background: url(navyblue.jpg) center top repeat-y;
padding: 1000px;
opacity: 0.7;
background-attachment: fixed; }
Use img tag instead background image in CSS.
img {width: 100%}
Use percents for the relevent values.
top: 25px; left: 45%;
This makes the amount of space between the left edge and the image relative to the window size. Play around with the value a little to center it and you should be good.
Your positioning is absolute, so it will move independently of the scale. Put that inside a relatively positioned div and then it will work.
For instance,
<div style="position:relative;">
<div id="MassEffectSign"> </div>
</div>
Hope this helps.
I apologize if this has been answered time and time again. I remember searching thoroughly for an answer a couple years ago when I first wrote up my website script, but I couldn't ever find one. The same for now.
Recently I reworked my website's script so I can host it onto Weebly. Here is one of the four pages of my site that I need help with. As you can see, the images that pop up when the thumbnail is hovered over are absolutely positioned. For most computer resolutions and/or browsers, this will have the image appear out of the designated box.
How could I position them to the inner top left corner of the div? Or better yet, horizontally and vertically centered within it?
<section id="Sizes" style="float: left">
<a href="#Space">
<img class="Small" src="/files/theme/SampleD_Fun_Icon.png" width="150" height="150" alt="Sample 1: Day of Fun" />
<img class="Large" src="/files/theme/SampleD_Fun.png" width="150" height="150" alt="Sample 1: Day of Fun" />
</a>
...
</section>
<a id="Space"></a>
<span class="Popup">Hover over thumbnail to display sample artwork.</span>
<br style="clear: left" />
a:hover img.Small
{
border: 5px solid #21568b;
margin: 10px;
text-decoration: none;
}
section#Sizes a img.Large
{
border-width: 0;
height: 0;
left: 438px;
position: absolute;
top: 326px;
width: 0;
}
section#Sizes a:hover img.Large
{
height: 526px;
left: 438px;
position: absolute;
top: 326px;
width: 520px;
}
.Popup
{
border: 3px solid;
float: left;
height: 272px;
margin: 8px 20px 0px 0px;
padding-top: 254px;
text-align: center;
width: 520px;
}
Thank you for your time. :)
Your whole design is a bit fragile, and I wouldn't recommend building this this way in the first place, but you're looking for practical answers, so here's the smallest change I can think of that fixes your problem:
1) Add this to your style sheet:
body { position: relative; }
2) On line 40 from your main_style.css, change top: 326px to top: 316px and left: 438px to left: 428px, so that it becomes like this:
section#Sizes a:hover img.Large {position: absolute; top: 316px; left: 428px; width: 520px; height: 526px;}
How does that work?
Your images are place using absolute positioning. By default, that works relative to the viewport (the window). But by turning the body into position relative, it becomes a containing block, and position absolute is relative to the nearest containing block ancestor.
So now, your images are fixed within the body element, instead of being fixed relative to the window. Since the margins of the body element is what's changing size when you resize the window, that makes the various pieces of your content fixed relative to each other. You then just need to remove 10px from the top and left side, since that's the size of the border of your body element, and we're now measuring from inside the border.
TLDR: You can't do this in pure CSS.
You can easily position the image inside the container div if you place the image element inside the div element, and then use absolute positioning like top: 0; left: 0; (or with a number of other methods). But then you'd need JavaScript to correlate the hovered thumbnail with the popup full-size image.
Alternatively, you can have the full-size image be nested in the thumbnail element (like you currently have), but then you'd need JavaScript to position the full-size popup image inside the container div.
Of the two alternatives, I recommend the first: put all the popup images inside the target container, and use JavaScript to show or hide them when a thumbnail is hovered. Correlating the thumbnail and the full size image via JavaScript is going to be easier then writing positioning code.
I see you're using jQuery already so why not do something like this?
$('.Small').on('mouseover', function(){
$('.Popup').empty().html($(yourtarget).attr('img' , 'src'));
});
$('.Small').on('mouseout', function(){
$('.Popup').empty().html('Hover over thumbnail to display sample artwork.');
});
Just because everyone was saying it can't be done with pure css, I wanted to demonstrate that it can, and it is even quite easy. Have a look at the folowing example:
http://jsfiddle.net/aafa2zp5/
<div id='images-wrapper'>
<ul>
<li>
<img class='small' src='http://placehold.it/50/ff0000'/>
<img class='big' src='http://placehold.it/300/ff0000'/>
</li>
<!-- and some more similar thumb / image groups -->
</ul>
<div class='preview-area'></div>
</div>
CSS (or the relevant part at least)
#images-wrapper {
position: relative;
}
.big {
display: block;
position: absolute;
top: 54px;
right: 54px;
opacity: 0;
transition: opacity .5s;
}
.preview-area {
width: 350px;
height: 350px;
border: 4px solid blue;
position: absolute;
top: 21px;
right: 21px;
}
li:hover .big {
opacity: 1;
}
The key is to set a position relative to the wrapper (and keep all of the descendants as their default static). Then you can use this to position the preview area and the big images against by setting them to postion absolute and carefully calculating the correct postion. I even added a cross fade, just because it is so easy, but you could just as well work with display block / none if you prefer.
For smaller screens you may want to alter the dimensions and positioning inside a media query, but it still should be doable (though depending on the hover state is perhaps not the best idea on a touch device)
I hope you get the idea and you can figure out how to apply this technique to your own site. Feel free to ask if you want me to explain further or when you get stuck.
What I'm trying to achieve without using JS can be seen on jsfiddle.net/k2h5b/.
Basically I would like to display two images, both centered, one in background and one in foreground:
Background Image: Should cover the whole window without affecting the aspect ratio, which means that the image will always touch two opposite edges of the window, but the image will be cropped.
Forground Image: Should be inside the window without affecting the aspect ratio, which means the image will be always touch two opposite edges of the window, but the image will not be cropped.
It doesn't matter if it's a <div> or an <img> tag, as long as they are displaying the images.
Asume also that the image sizes are known upfront and can be used in CSS or HTML part.
So my question is: is it possible using only CSS or CSS3?
If it's not possible I will accept the answer that will be as close as possible to my goal.
Examples:
When the background image is cropped from the top and bottom:
When the background image when it's cropped from left and right:
After looking at #Kent Brewster's answer, I think I could achieve all the requirements of OP.
This doesn't have the problem of foreground image being cropped and you can also specify constant margin around the foreground image. Also div is being used instead of img tag, because we are using background images. Here is the link and here is the code:
<div id='bg'></div>
<div id='fg'></div>
#bg {
position: absolute;
height: 100%;
width: 100%;
background-image: url(http://i.imgur.com/iOvxJ.jpg);
background-repeat: no-repeat;
background-position: 50% 50%;
background-size: cover;
}
#fg {
position: absolute;
top: 10px;
left: 10px;
bottom: 10px;
right: 10px;
opacity: .7;
background-image: url(http://i.imgur.com/HP9tp.jpg);
background-repeat: no-repeat;
background-position: 50% 50%;
background-size: contain;
}
Try this:
<html>
<style>
body {
margin: 0;
}
#bg {
position: absolute;
height: 100%;
width: 100%;
background: transparent url(bg.jpg) 50% 50% no-repeat;
background-size: cover;
}
#fg {
position: absolute;
height: 90%;
width: 90%;
top: 5%;
left: 5%;
background: transparent url(fg.jpg) 50% 50% no-repeat;
background-size: cover;
opacity: .7;
}
</style>
<body>
<div id="bg"></div>
<div id="fg"></div>
</body>
</html>
If the scaling requirement is flexible, it might work. See http://jsfiddle.net/k2h5b/5/ to see it run.
Yes, it's possible.
Basically I just made the background image the background for the <body> (doesn't have to be the body of course), and then put the image inside that with a small margin.
<body>
<img id='fg' src='http://3.bp.blogspot.com/-OYlUbWqyqog/TeL-gXGx3MI/AAAAAAAAHRc/bdqvvvaeC7c/s1600/bald-eagle3.jpg'></img>
</body>
css:
body {
margin: 0; padding: 0;
overflow: hidden;
background: url('http://wallpaper.zoda.ru/bd/2006/07/21/2c7b4306fd22f049f331d43adb74a5f7.jpg') no-repeat left top;
}
#fg {
margin: 20px 20px;
opacity: 0.7;
}
obviously if the window is too big, there'd be issues. You could (I guess) use media queries to pull in different image sizes based on window size.
edit — OK, well for the image, if you do want it to crop and retain the right aspect ratio, then I think you'll have to know the image size ahead of time to do it so that it works out. Lacking that, here's another revision.
<body>
<div id='fg'> </div>
</body>
css:
body {
margin: 0; padding: 0;
overflow: hidden;
background: url('http://wallpaper.zoda.ru/bd/2006/07/21/2c7b4306fd22f049f331d43adb74a5f7.jpg') no-repeat left top;
}
body, html { width: 100%; height: 100%; }
#fg {
margin: 2%; width: 96%; height: 96%;
opacity: 0.7;
background: url('http://3.bp.blogspot.com/-OYlUbWqyqog/TeL-gXGx3MI/AAAAAAAAHRc/bdqvvvaeC7c/s1600/bald-eagle3.jpg') no-repeat center center;
}
If you know the image dimensions, you could then set max-height and max-width. (I'll try that too :-)
edit again To get the background to crop in a centered way, you'd need to set the position to "center center" instead of "left top". (Or "center top" if you just want it centered horizontally.)
Vertically centering elements with CSS without cutting-edge non-standard features (flexible box layout) is hard. That may be something to do with JavaScript. I'll say that one problem with any JavaScript solution like that is that it really slows the browser down. If you must do it, I would suggest introducing a little time lag so that you don't try to recompute the layout on every resize event. Instead, set a timer for like 200 milliseconds in the future where the work will get done, and each time you do so cancel the previous timer. That way, while a person is dragging the window corner it won't burn up their CPU.
edit even more ooh ooh yes #Kent Brewster's answer with the vertical centering is good - I always forget that trick :-)
There is no way to achieve this effect using only CSS, for two main reasons:
Because you are trying to resize your image, you cannot use the background property and must instead use an <img> tag. Your image will always try to take up as much room as it can if the width and height are not set. Thus, the aspect ratio will not be maintained, or your image will be cropped.
The other caveat of resizing the image is that you will not be able to vertically-align it to the center of your page without knowing its dimensions.