I have some text inside a parallelogram, the problem is that when I resize the window the text loses all its properties, I have tried vw, vh, em, pt, rem and px
Also I have tried with #media screen and (min-width: 320px;)
But nothings seems to work, currently this is what I have so far, I hope you could help me.
.paralelo {
margin-top: 8%;
margin-left: 0%;
padding-left: 0;
text-align: right;
width: 48%;
height: 50%;
max-height: 10px;
border-top: 50px solid #c5027f;
border-right: 30px solid #FFf;
}
.who {
font-family: "Montserrat","Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 3em;
font-weight: 400;
color: white;
margin-top: -21.5%;
margin-right: 12px;
}
<div class="paralelo">
<p class="who">Servicios</p>
</div>
Try with using position like:
.paralelo {
position: relative; /* -- add this line */
margin-top: 8%;
margin-left: 0%;
padding-left: 0;
text-align: right;
width: 48%;
height: 50%;
max-height: 10px;
border-top: 50px solid #c5027f;
border-right: 30px solid #FFf;
}
.who {
position: absolute; /* -- add this line */
top: -100px; /* -- add this line */
right: 12px; /* -- add this line */
font-family: "Montserrat","Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 3em;
font-weight: 400;
color: white;
/* margin-top: -21.5%; -- remove this line */
/* margin-right: 12px; -- remove this line */
}
<div class="paralelo">
<p class="who">Servicios</p>
</div>
here is jsfiddle so you can resize screen
read more about how to use position here
Update after comment
Here is the example with vw so if you resize the screen it will change all sizes accordingly https://jsfiddle.net/5x7p6fsr/1/
Related
I want the text to shrink as the image shrinks. e.g. maintain the same ratio in size relative to the image. I've tried making the text disappear but it simply isn't what I want.
The CSS:
.header{
padding: 0.16px 16px;
position: relative;
box-sizing: inherit;
display: block;
font-size: 15px;
line-height: 1.5;
text-size-adjust: 100%;
content: "";
display: table;
clear: both;
font-family: "Montserrat", sans-serif;
}
.top-left{
padding: 24px 48px;
margin-left: 16%;
position: absolute;
left: 0px;
top: 0px;
box-sizing: inherit;
display:block;
font-size: 15px;
line-height: 22.5px;
text-size-adjust:100%;
}
.header-image{
vertical-align:middle;
border-style: none;
box-sizing: border-box;
width:65%;
height:auto;
margin:30px 250px;
}
#media screen and (max-width: 600px) {
.header-image {
margin-left: auto;
margin-right: auto;
display: block;
width:65%;
}
}
.new-arrivals{
position: absolute;
display:block;
left: 0;
top: 0;
margin:10px 5px 10px 0;
font-size: 4vw !important;
color:black;
padding: 50px 100px;
font-weight: 400;
line-height: 60px;
}
.shop-now{
border:none;
display:inline-block;
padding:12px 24px;
margin: 260px 50px;
vertical-align:middle;
overflow:hidden;
text-decoration:none;
color:white;
background-color:black;
text-align:center;
white-space: nowrap;
font-size: 18px
}
.shop-now:hover{
background-color: #ccc;
color: black;
border-style: ridge;
border-color: black;
border-width: 1px;
}
.designs{
position: absolute;
left: 0;
top: 0;
font-size: 20px !important;
font-family: "Montserrat", sans-serif;
margin: 150px 0;
color:black;
padding: 24px 100px;
font-weight: 400;
}
The HTML:
<div class="header">
<img class="header-image" src="img/jeans.jpg" alt="Jeans">
<div class="top-left">
<h1 class="new-arrivals">New arrivals</h1>
<p><h3 class="designs">Our new season collection is here</h3> </p>
<p>SHOP NOW</p>
</div>
</div>
If you want the text to be responsive as the image, you need to set h1 element style in your CSS file. For example:
.new-arrivals {
font-size:clamp(2em, 4vw, 4em); /* set min, ideal value, max */
}
I was trying to do the same thing for my portfolio. And I end up putting my text imbedded inside the image by using the ms paints. The text inside image can't be responsive if it's not of part of image. I hope that help.
You can accomplish this by setting both the width of the image and the font-size based on the width of the screen. Below is an example of that.
This question is similar, and the answers there may be helpful to you as well.
body {
margin: 0;
}
.container {
position: relative;
color: white;
width: fit-content;
}
.top-left {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 3vw;
}
img {
width: 100vw;
}
<div class="container">
<img src="https://html.com/wp-content/uploads/flamingo.jpg">
<div class="top-left">
<h1 class="new-arrivals">New arrivals</h1>
<h3 class="designs">Our new season collection is here</h3>
<p>SHOP NOW</p>
</div>
</div>
If you don't need the image to scale with the screen width, you can simply set a fixed pixel size for both the image and the text.
CSS for the Text:
.text {
font-size: 15vw;
}
CSS for the Image
img {
width: 10vw;
max-width: /* Set this to 10-15cm if you want to show you page on
mobiles too */
min-width: /* Set this to 8-10cm if you want to show you page on
mobiles too */
}
try these and adjust
font-size: clamp(1rem, 3vw, 2rem)
font-size: max(1rem, 3vw)
font-size: calc(200% + 2vw)
I am making a website and I need a CTA image.
I am using Bootstrap 4 and I have made a custom CSS to adjust how the image will look. I've put it so that it takes up the whole width of the screen, so width: 100%;
When I adjust the size of the screen, the image is responsive and also adjusts itself so that it will turn smaller and fit the whole screen. But when is on a regular big sized screen the image takes up the whole website so I want to be able to leave it as 100% width but with a smaller height. When I try adjusting the max-height it just ends up stretching the image and it is not appealing to look at. What should I do?
This is the HTML Section:
<!-- CTA Section -->
<div class="img-wrapper">
<img class="img-responsive" src="I/CTA.png">
<div class="img-overlay">
Want to see what more we have to offer?
<br><br>
<a href="coffee.html"><button class="btn btn-md btn-primary">
Click here</button></a>
</div>
</div>
<!-- /.img-wrapper -->
This is the CSS section of the code:
.img-wrapper {
position: relative;
}
.img-wrapper img {
width: 100%;
max-height: 650px;
}
.img-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align: center;
font-family: 'Raleway', sans-serif;
letter-spacing: 2px;
color: white;
font-size: 14px;
}
.img-overlay:before {
content: ' ';
display: block;
height: 60%;
}
button {
font-family: 'Raleway', sans-serif;
letter-spacing: 2px;
}
.btn-responsive {
/* matches 'btn-md' */
padding: 10px 16px;
font-size: 18px;
line-height: 1.3333333;
border-radius: 6px;
}
#media (max-width:760px) {
/* matches 'btn-xs' */
.btn-responsive {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
}
You can use object-fit, though it hasn't so good browser support yet, so a solution making use of background-image might be needed (based on the browser support you require)
Here is a solution using object-fit
.img-wrapper img {
width: 100%;
max-height: 350px;
object-fit: cover;
}
Fiddle demo
Stack snippet
.img-wrapper {
position: relative;
}
.img-wrapper img {
width: 100%;
max-height: 350px;
object-fit: cover;
}
.img-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align: center;
font-family: 'Raleway', sans-serif;
letter-spacing: 2px;
color: white;
font-size: 14px;
}
.img-overlay:before {
content: ' ';
display: block;
height: 60%;
}
button {
font-family: 'Raleway', sans-serif;
letter-spacing: 2px;
}
.btn-responsive {
/* matches 'btn-md' */
padding: 10px 16px;
font-size: 18px;
line-height: 1.3333333;
border-radius: 6px;
}
#media (max-width:760px) {
/* matches 'btn-xs' */
.btn-responsive {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
}
<!-- CTA Section -->
<div class="img-wrapper">
<img class="img-responsive" src="http://lorempixel.com/500/350/nature/1/">
<div class="img-overlay">
Want to see what more we have to offer?
<br><br>
<a href="coffee.html"><button class="btn btn-md btn-primary">
Click here</button></a>
</div>
</div>
Here is another using background-image.
The trick for making this work, is to keep the image in place, but with visiblity: hidden set. This will make the image wrapper size proper, and then the background image adjust without stretching.
Fiddle demo
Stack snippet
.img-wrapper {
position: relative;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.img-wrapper img {
width: 100%;
max-height: 350px;
visibility: hidden;
}
.img-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align: center;
font-family: 'Raleway', sans-serif;
letter-spacing: 2px;
color: white;
font-size: 14px;
}
.img-overlay:before {
content: ' ';
display: block;
height: 60%;
}
button {
font-family: 'Raleway', sans-serif;
letter-spacing: 2px;
}
.btn-responsive {
/* matches 'btn-md' */
padding: 10px 16px;
font-size: 18px;
line-height: 1.3333333;
border-radius: 6px;
}
#media (max-width:760px) {
/* matches 'btn-xs' */
.btn-responsive {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
}
<!-- CTA Section -->
<div class="img-wrapper" style="background-image: url(http://lorempixel.com/500/350/nature/1/)">
<img class="img-responsive" src="http://lorempixel.com/500/350/nature/1/">
<div class="img-overlay">
Want to see what more we have to offer?
<br>
<br>
<a href="coffee.html">
<button class="btn btn-md btn-primary">
Click here</button>
</a>
</div>
</div>
I want to place some text over a banner on my homepage. The banner changes it's size dynamically, when I scale it in Developer-Mode. Hower I can't mange to kepp the position of the text relative to the banner and change the font-size according to the scaling factor. I tried with font-size vh, vw, % etc.
Here is the sample on jsfiddle:
https://jsfiddle.net/malptek/2o3a81vp/2/
My html-code:
<div class="header-container clearfix">
<!-- <div class="helper-box"></div> -->
<h1 class="header-post-title-banner header-subimage">This is a title</h1>
<img src="http://mesut.alptekin.de/wp-content/uploads/tmpbanner.jpg" class="header-image">
</div>
And css:
.header-container {
margin-bottom: 0;
font-size: 16px;
z-index: 1;
/* border-bottom: 1px solid #EAEAEA; */
position: relative;
width: 100%;
}
.helper-box {
z-index: 2;
position: absolute;
margin-left: 8%;
background-color: #ababab;
margin-bottom: 0;
width: 260px;
height: 20%;
}
.header-subimage {
z-index: 2;
font-size: 16px;
position: absolute;
margin-left: 8%;
margin-bottom: 0;
/* background-color: #fff;
opacity: .5; */
width: 20%;
height: 20%;
/* width: 8em;
height: 1.67em; */
}
.header-image {
z-index: 1;
margin-bottom: 0;
/* border-bottom: 1px solid #EAEAEA; */
width: 100%;
position: relative;
}
.header-post-title-banner {
/* font-size: 3vh;
font-size: 2vw; */
font-size: 150%;
text-align: center;
color: #1b6dba;
font-weight: bold;
padding-bottom: 0;
}
#media screen and (min-width: 1285px) {
.header-post-title-banner {
font-size: 1.8em;
text-align: center;
color: #1b6dba;
font-weight: bold;
padding-bottom: 0;
}
}
==================================
UPDATE:
well, this example is working because viewport is the same size as the banner. but you can imagine the banner being inside another big with 1400px wide (see new example: jsfiddle.net/malptek/2o3a81vp/7). However, in this example the image is somehow not scaling according to the new (don't know why).
Works for me with vw.
https://jsfiddle.net/abalter/2o3a81vp/3/
CSS length measurements vw, vh, and vmin are starting to be widely supported.
http://caniuse.com/#feat=viewport-units
I'm kind of confused by how to interpret the global browser use percentages, but, unless you are concerned about compatibility with older browsers, you can use them pretty freely.
CSS: Are view height (vh) and view width (vw) units widely supported?
I'm trying to put the blue div at the bottom of this picture, and I'm stuck for some reason.
My CSS:
.boxes {
margin-left: 4%;
margin-right: -4px;
height: 345px;
padding: 5px;
font-size: 12px;
}
.box-one{
background-image: url("uploadir.com/u/nxa8310f");
background-repeat: no-repeat;
background-size: cover;
}
.index-image-text {
padding-bottom: 0;
margin-bottom: 0;
font-weight: bold;
color: white;
background-color: #2E3192;
}
HTML:
<div class="boxes img-rounded box-one grid-20">
<h1>Pottery Painting</h1>
<p class="index-image-text">
Testing<br>
</p>
</div>
It shows the little gap on both sides, but i want it all the way at the bottom of the div, and without the gap.
This is what it's showing:
https://sc-cdn.scaleengine.net/i/b4a1b72231a52f3a4977f68b76c0a7ad.png
this is what I want it to show:
https://sc-cdn.scaleengine.net/i/c66fe095c68250837b4b320c87bf72f0.png
any ideas? here's a fiddle: jsfiddle.net/kzaLx2vb/
May be this help.
HTML:
<div class="boxes img-rounded box-one grid-20">
<h1>Pottery Painting</h1>
<p class="index-image-text">Testing</p>
</div>
CSS:
body {
width: 300px;
}
.boxes {
margin-left: 4%;
margin-right: -4px;
height: 345px;
font-size: 12px;
}
.box-one{
background-image: url("http://uploadir.com/u/nxa8310f");
background-repeat: no-repeat;
background-size: cover;
}
.index-image-text {
padding-bottom: 0;
margin-bottom: 0;
position:relative;
top:75%;
font-weight: bold;
border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px;
color: white;
background-color: #2E3192;
text-align: center;
padding-top: 10px;
}
h1 {
padding-top: 30px;
text-align: center;
color:#FFF;
}
JSFiddle: http://jsfiddle.net/5q354m3h/
A good way to achieve what you want is to give the box a relative style:
.box-one{
position:relative;
}
and then absolutely position your index-image-text
.index-image-text {
position:absolute;
bottom: 0;
left:0;
right:0;
}
http://jsfiddle.net/kzaLx2vb/11/
CSS:
.boxes {
margin-left: 4%;
margin-right: -4px;
height: 345px;
font-size: 12px;
/* addition code */
padding: 0; /*change your padding from 5px to 0*/
position: relative; /* set to relative to be the reference outter box */
border-radius: 10px; /* rounded corner based on the reference image */
overflow: hidden; /* to cut out for the bottom rounded corner */
max-width: 320px; /* this line not required*/
}
.box-one{
background-image: url("http://uploadir.com/u/nxa8310f");
background-repeat: no-repeat;
background-size: cover;
}
h1 {
color: #fff;
text-align: center;
}
.index-image-text {
padding-bottom: 0;
margin-bottom: 0;
font-weight: bold;
color: white;
background-color: #2E3192;
/* addition code */
margin: 0; /* override default padding value on "p" tag */
padding-top: 10px; /* spacing based on the reference image */
position: absolute; /* set to absolute to position within relative outter box */
bottom: 0; /* make the inner box stick to the bottom of outter box */
width: 100%; /* stretch the inner box to fill up outter box */
text-align: center; /* position based on the reference image */
font-family: verdana; /* font fammily based on the image */
}
I am designing a responsive website for a client where the image needs to be resized according to the width of screen.
I set the image to max-width:100% and height:auto and it's working perfectly in chrome but not in mozilla.
Here is the link http://touchtalent.cloudvent.net/
Also, there is a similar question at
Image mysteriously ignoring max-width in Firefox & IE
And, according to it's answer, I tried to give it's parent a width of 100%, but that doesn't help.
Here is my HTML code
<div id="wrapper">
<header>
<section class="banner1">
<img class="banner" src="img/banner1.jpg" alt="banner1"/>
<div class="tag1">
BECAUSE YOU HAVE
</div>
</section>
<section class="banner2">
<img class="banner" src="img/banner2.jpg" alt="banner2"/>
</section>
<section class="banner3">
<img class="banner" src="img/banner3.jpg" alt="banner3"/>
<div class="tag2">
A
</div>
<div class="tag3">
CREATIVE GENIUS
</div>
<div class="tag4">
INSIDE YOU
</div>
<div class="tag5">
<div class="btn_join">
JOIN US
</div>
</div>
</section>
</header>
</div><!--wrapper-->
Here is its CSS
* {
float: left;
}
header {
max-width: 100%;
}
img.banner {
max-width: 100%;
height: auto;
display: block;
}
.banner1, .banner2, .banner3 {
max-width: 100%;
position: relative;
}
.tag1, .tag2, .tag4, .tag3, .tag5 {
width: 100%;
font-family: "HeroLight", sans-serif;
font-size: 40px;
color: #FFF;
position: absolute;
text-align: center;
left: 0px;
bottom: 20px;
height: 40px;
}
.tag2 {
top: 20px;
}
.tag4 {
top: 160px;
}
.tag3 {
top: 70px;
font-family: "sixties", sans-serif;
font-size: 80px;
}
.tag5 {
bottom: 60px;
}
.tag5 .btn_join {
background: #FFF;
-webkit-border-radius: 40px;
-moz-border-radius: 40px;
-ms-border-radius: 40px;
-o-border-radius: 40px;
border-radius: 40px;
color: #000;
font-size: 23px;
font-family: "HeroLight", sans-serif;
width: 198px;
height: 53px;
line-height: 60px;
position: relative;
left: 50%;
margin-left: -99px;
cursor: pointer;
}
#media screen and (min-width: 500px) and (max-width: 1200px) {
.tag1, .tag2, .tag4, .tag3, .tag5 {
width: 100%;
font-family: "HeroLight", sans-serif;
font-size: 25px;
color: #FFF;
position: absolute;
text-align: center;
left: 0px;
bottom: 0px;
height: 40px;
}
.tag2 {
top: 15px;
}
.tag4 {
top: 100px;
}
.tag3 {
top: 45px;
font-family: "sixties", sans-serif;
font-size: 50px;
}
.tag5 {
bottom: 25px;
}
.tag5 .btn_join {
background: #FFF;
-webkit-border-radius: 40px;
-moz-border-radius: 40px;
-ms-border-radius: 40px;
-o-border-radius: 40px;
border-radius: 40px;
color: #000;
font-size: 23px;
font-family: "HeroLight", sans-serif;
width: 198px;
height: 53px;
line-height: 60px;
position: relative;
left: 50%;
margin-left: -99px;
cursor: pointer;
}
}
#media screen and (min-width: 1201px) and (max-width: 1400px) {
.tag1, .tag2, .tag4, .tag3, .tag5 {
width: 100%;
font-family: "HeroLight", sans-serif;
font-size: 35px;
color: #FFF;
position: absolute;
text-align: center;
left: 0px;
bottom: 15px;
height: 40px;
}
.tag2 {
top: 15px;
}
.tag4 {
top: 125px;
}
.tag3 {
top: 55px;
font-family: "sixties", sans-serif;
font-size: 60px;
}
.tag5 {
bottom: 25px;
}
.tag5 .btn_join {
background: #FFF;
-webkit-border-radius: 40px;
-moz-border-radius: 40px;
-ms-border-radius: 40px;
-o-border-radius: 40px;
border-radius: 40px;
color: #000;
font-size: 23px;
font-family: "HeroLight", sans-serif;
width: 198px;
height: 53px;
line-height: 60px;
position: relative;
left: 50%;
margin-left: -99px;
cursor: pointer;
}
}
#wrapper {
width: 100%;
min-width: 1000px;
overflow: hidden;
}
Please help!
You have float:left applied to all elements. Floated blocks occupy as much width, as needed by their content. In this case, image initial width "spreads" on the parent section.
And max-width on replaced block elements (such as images) doesn't make them occupy all the space - it just makes them not to widen more, than soe value. width:100% does
Try removing the float rule and give images width:100%
I had the same problem and after reading this bugzilla report https://bugzilla.mozilla.org/show_bug.cgi?id=975632 I found out that if the image is nested in a table or a {display: table;} property is applied, then the max-width trick doesn't work because the table adapts to its content size.
So I hunted down this property in my DOM via dev tools in Firefox and I found a {display: table;} on one of the very first divs. Some attempt to scale the website ? I'm using currently TikiWiki CMS, an old version (12).
Anyway, correcting the CSS to {display: block;} made the {max-width: 100%} rule now work, and so finally I get the small images keeping their sizes and the big ones resizing to the container width.
As it took me some time to find out, I just thought let's share this if it can avoid others to loose time on this !!!
add this to your css
body, html {margin: 0; padding:0; width: 100%;min-width: 100%;max-width: 100%;}
img.banner {
width: 100%;
min-width: 100%;
max-width: 100%;
height: auto;
display: block;
}
.banner1, .banner2, .banner3 {
width: 100%;
min-width: 100%;
max-width: 100%;
position: relative;
}
also as also mentioned remove the float?
* {float: left;}
This is completly working, however, you set a minimum width on your #wrapper div content.
Remove it from the main.css line 550 and it will work
CSS
#wrapper {
width: 100%;
/* min-width: 1000px; to remove */
overflow: hidden;
}
You must use image width="100%" like ().
It must work for you. Gud Luck
For my issue (and using a bootstrap derivative), I didn't want my images scaled to 100% when they weren't intended to be as large as the container.
For my xs container (<768px as .container), not having a fixed width drove the issue, so I put one back on to it with javascript & jQuery (less the 15px col padding).
// Helps bootstrap 3.0 keep images constrained to container width when width isn't set a fixed value (below 768px), while avoiding all images at 100% width.
// NOTE: proper function relies on there being no inline styling on the element being given a defined width ( '.container' )
function setWidth() {
width_val = $( window ).width();
if( width_val < 768 ) {
$( '.container' ).width( width_val - 30 );
} else {
$( '.container' ).removeAttr( 'style' );
}
}
setWidth();
$( window ).resize( setWidth );
Add this to your css.
body {width: 100%;)
Your elements are displaying as 100% of your parent element. Webkit renders this properly, but Chrome requires you to explicitly state the width of your body to achieve the proper result.