so I am basically coding my website.
I made a container, where a text floats to the left and the img to the right. I set a min-width for the text so it gets responsive. The image size is also responsive. Once the screen width gets lower, the image does get under the text but not in the center. I tried using margin: 0 auto; but that didn't help either.
.container {
width: 88%;
margin: auto;
overflow: hidden;
}
/* showcase */
#showcase h1 {
margin: 0;
}
#text {
width: 60%;
float: left;
min-width: 300px;
}
#pic {
width: 40%;
float: right;
}
#pic img {
width: 100%;
}
<section id="showcase">
<div class="container">
<div id="text">
<h1> dummy text </h1> <button class="button_1">Kontakt</button> </div>
<div id="pic"> <img class="mypic" src="./img/menew.png"> </div>
</div>
</section>
Use flex rather than a float on your container, you will get a better response from it
.container {
width: 88%;
overflow: hidden;
display: flex;
}
/* showcase */
#showcase h1 {
margin: 0;
}
#text {
min-width: 300px;
}
#pic {
width: 40%;
}
#pic img {
width: 100%;
}
You can now change the width of your #text div to place where you want the elements
Media query as asked for responsive
#media (max-width: 750px) {
.container {
display: block;
}
}
I deleted #pic float and added auto margin + a min width
#pic{
width: 40%;
min-width: 300px;
margin: 0 auto;
}
and made a media query:
#media (min-width: 600px) {
#pic {
float: right;
}
}
Related
I'm trying to make it so that the height is restricted to the height of the device the image is viewed on so that you can view the entire image without having to scroll down.
To accomplish this I've used:
.specific-image {
display: block;
max-height: 92vh;
max-width: 1240px;
}
So if the image is 500x1000 px, it'll take 92vh height and if it's 1000x500, it'll have width of 1240px and height (most probably) less than 92vh.
The problem with that is that if I resize the height of the browser the image scales down, however, if I scale the width, my browser will cut part of the image and I'll have to scroll horizontally to see the full image.
Not sure how to get the best of both worlds.
https://codepen.io/BozhidarSK/pen/NBKyyW
.specific-image-flex-container {
display: flex;
}
.specific-image-column {
flex: 4;
}
.specific-image-container-element {
text-align: center;
position: relative;
display: inline-block;
width: 100%;
}
.specific-image {
display: block;
max-height: 92vh;
max-width: 1240px;
}
.stickySpecificContainer {
position: relative;
z-index: 2;
display: inline-block;
}
<div class="specific-image-flex-container">
<div class="specific-image-column">
<div class='specific-image-container-element'>
<div class="stickySpecificContainer">
<img class='specific-image' src='https://i.redd.it/1v3x2pxkjy611.png' alt='Random image' />
</div>
</div>
</div>
</div>
You want the image to be maximum 100% wide by default and 1240px if the screen is wider than 1240px. You can achieve the desired result using media queries:
body {
margin: 0;
}
.specific-image {
display: block;
max-height: 92vh;
max-width: 100%;
}
#media screen and (min-width: 1240px) {
.specific-image {
max-width: 1240px;
}
}
<img class="specific-image" src="https://dummyimage.com/1600x600/000/fff">
Same demo with square image:
body {
margin: 0;
}
.specific-image {
display: block;
max-height: 92vh;
max-width: 100%;
}
#media screen and (min-width: 1240px) {
.specific-image {
max-width: 1240px;
}
}
<img class="specific-image" src="https://dummyimage.com/600x600/000/fff">
give max-width:100% to the image instead of the pixel value, the percentage value will make sure that max width of the image 100% of the document.
.specific-image {
display: block;
max-height: 92vh;
max-width: 100%
}
.specific-image-flex-container {
display: flex;
}
.specific-image-column {
flex: 4;
}
.specific-image-container-element {
text-align: center;
position: relative;
display: inline-block;
width: 100%;
}
.specific-image {
display: block;
max-height: 92vh;
max-width: 100%;
}
.stickySpecificContainer {
position: relative;
z-index: 2;
display: inline-block;
}
<div class="specific-image-flex-container">
<div class="specific-image-column">
<div class='specific-image-container-element'>
<div class="stickySpecificContainer">
<img class='specific-image' src='https://i.redd.it/1v3x2pxkjy611.png' alt='Random image' />
</div>
</div>
</div>
</div>
92vh is 92% of the view height. vw is used for view width.
.specific-image {
display: block;
max-height: 92vh;
max-width: 92vw;
}
I have the following HTML
.wrapper {
position: relative;
width: 100%;
overflow: hidden;
}
.no-padding {
padding: 0 !important;
}
.home-slider img {
margin-right: 6px;
float: left;
width: 35px;
position: relative;
top: -4px;
}
.home-slider-wrap {
position: relative;
}
.home-slider-wrap .bg-img {
height: 500px;
width: auto;
max-width: none;
}
.img-full {
width: 100%;
}
#media (max-width: 767px) {
.home-slider-wrap .bg-img {
min-height: auto;
min-width: 100%;
width: 100%;
height: auto;
}
}
<div class="wrapper">
<div class="container-fluid no-padding">
<div class="home-slider-wrap">
<div class="home-slider">
<div>
<img src="https://g5-assets-cld-res.cloudinary.com/image/upload/q_auto,f_auto,fl_lossy/g5/g5-c-1t2d31r8-berkshire-communities/g5-cl-i2pbvvuq-creekstone/uploads/pet-friendly.jpg" class="bg-img img-full ing-responsive" alt="">
</div>
</div>
</div>
</div>
</div>
I am trying to resize this image but at the same time also keep a minimum height for devices less than 768px; However as you can see in the demo below, this ain't working out.
The portion of the cat and dog isn't visible when the page is resized for a mobile device.
Demo
How do I fix this? Any help is appreciated.
You could try using a media query
Maybe you can try this css:
background-size: cover;
background-position: center;
background-repeat: no-repeat;
You can use media query to target below 768px width devices to define style like below -
#media (max-width:767px){
.home-slider-wrap .bg-img {
min-height: auto;
min-width: 100%;
width: 100%;
height: auto;
}
}
I have a logo on the right side of the page. On resizing(making window smaller) I want to move the logo to the center of the page.
Here's my CSS
.headerlogo {
position: relative;
float: right;
margin-right: 5%;
margin-top: 50px;
z-index: 999;
}
.getapp-nav-img{
height: 60px;
margin: auto;
}
Here's my HTML
<div class="headerlogo" style="">
<div class="social-nav">
<a href='#'><img class="getapp-nav-img" src='img/logo.png'/></a>
</div>
</div>
Its not moving by this. How can I achieve this?
Remove the float and use text-align to center the img. You need to make those changes within a media query like this:
#media (max-width: 768px) {
.social-nav {
text-align: center;
}
.headerlogo {
float: none;
}
}
Link to jsFiddle: https://jsfiddle.net/AndrewL32/e0d8my79/108/
You can use media queries like this:
.headerlogo {
width: 50px;
position: relative;
float: right;
margin: 50px 5% 0 auto;
z-index: 999;
}
.getapp-nav-img {
height: 60px;
margin: auto;
}
#media (max-width: 480px) {
.headerlogo {
float: none;
text-align: center;
margin: 50px auto 0 auto;
}
}
<div class="headerlogo" style="">
<div class="social-nav">
<a href='#'><img class="getapp-nav-img" src='https://cdn0.iconfinder.com/data/icons/black-icon-social-media/256/099280-blinklist-logo.png'/></a>
</div>
</div>
Here is a fiddle for easier testing: https://jsfiddle.net/ajjr3u3n/2/
In the code below I want the following conditions to hold:
The pink div always spans the viewport.
The pink div's text is always centered in the viewport.
The blue div floats to the right when the screen is "sufficiently wide."
The blue div stacks below the pink div when the screen is not "sufficiently wide."
The blue div spans the viewport and its text is centered when stacked.
The solution should be pure CSS.
Here's my current pass:
<!DOCTYPE html>
<html>
<head>
<style>
#parent {
position: relative;
background-color: white;
width: 100%;
height: 20px;
}
#center {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
background-color: pink;
text-align: center;
}
#placeholder {
position: relative;
height: 20px;
width: 500px;
}
#right {
position: relative;
float: right;
background-color: blue;
}
</style>
</head>
<body>
<div id="parent">
<div id="center">This text should always be centered in the VIEWPORT</div>
<div id="right">this text should float to the right</div>
<div id="placeholder"></div>
</div>
</body>
</html>
Here's what it currently looks like when the screen is wide (correct):
Here's what it looks like when the screen is narrow (incorrect):
Here's what it should look like when the screen is narrow:
Are you looking for something like this? https://jsfiddle.net/DIRTY_SMITH/v7k4oky8/4/
edited fiddle for proper text align
body{margin: 0;}
#parent {
position: relative;
background-color: white;
width: 100%;
height: 20px;
}
#center {
float: left;
margin: auto;
width: calc(100% - 500px);
background-color: pink;
padding-left: 250px;
}
#right {
float: left;
background-color: blue;
width: 250px;
}
#media (max-width: 610px){
#right {width: 100%; text-align: center;}
#center {width: 100%;}
}
This has worked for me to keep a spinning image in the same location on each side of the screen. Adjust left / right and top to position each div on either side.
<div class="col" style="overflow: none; z-index: 9999;">
<div id="spinning-circle" class="row" style="position:absolute; top:750px; left:-25px; z-index:1; width: auto!important;">
<img src="../certdb/images/left-bubble.png">
</div>
<div id="spinning-circle" class="row" style="position:absolute; top:250px; right:-145px; z-index:1; width: auto!important;">
<img src="../certdb/images/right-bubble.png">
</div>
</div>
BODY ->
.Site {
display: flex;
min-height: 100vh;
flex-direction: column;
}
Page Container ->
.Site-content {
flex: 1;
margin: auto;
margin-top: 5%;
max-width: 1500px;
min-height: 80%;
https://jsfiddle.net/znLv6peg/11/
Here is my solution. I don't know if this is best. For one thing, it requires you to set explicit heights. I set the defaults for mobile and altered for large screens per a best practice I read somewhere. I noticed that if you put this in JSFiddle it doesn't work properly, but it does if you use it in a browser (only Firefox tested).
<!DOCTYPE html>
<html>
<head>
<style>
body{margin: 0;}
#parent {
position: relative;
width: 100%;
height: 40px;
text-align:center;
}
#center {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
background-color: pink;
}
#right {
position: absolute;
top: 20px;
bottom: 0;
right: 0;
left: 0;
margin: auto;
background-color: #00FFFF;
}
#media only screen and (min-width: 480px) {
#parent {
height: 20px;
}
#right {
position: relative;
float: right;
top: 0;
}
}
</style>
</head>
<body>
<div id="parent">
<div id="center">This text should always be centered in the VIEWPORT</div>
<div id="right">this text should float to the right</div>
</div>
</body>
</html>
I have 2 divs in a container, one in the center and one to the right. I want the width of the right div to be responsive. Currently, only the max-width on the centered one works.
See this jsFiddle.
How do I make the right div responsive too?
HTML:
<div id="container">
<div id="middle">Centered</div>
<div id="right">Make me responsive</div>
</div>
CSS:
#container {
width: 100%;
text-align: center;
position: relative;
}
#middle {
background: #ddd;
margin: 0 auto;
position: relative;
width: 100%;
max-width:300px;
height:300px;
display: inline-block;
vertical-align: top;
}
#right {
background:yellow;
width:100%;
max-width:300px;
display: inline-block;
vertical-align: top;
position: absolute;
}
#media screen and (max-width: 350px) {
#right {
display: none;
}
}
The idea is to use flexbox. And add a pseudo element for left column, in order to make the middle one in the center with your existing markup.
JSFiddle Demo
#container {
display: flex;
}
#container:before, #middle, #right {
border: 1px solid red;
flex: 1 1 0;
}
#container:before {
content:"";
}
#middle {
max-width: 100px;
}
<div id="container">
<div id="middle">Centered</div>
<div id="right">Responsive</div>
</div>
You can accomplish what you want by doing something like this: JSFiddle
Only problem is your middle div has to have a fixed width but using media queries you can forget about that. Keep in mind that calc browser support could be better (although there are polyfills).
#middle {
position: relative;
margin: 0 auto;
height: 300px;
width: 340px;
background: #ddd;
text-align: center;
}
#right {
position: absolute;
top: 0; right: 0;
width: calc(50% - 170px);
background: red;
}
#media screen and (max-width: 340px) {
#middle {
width: auto;
max-width: 340px;
}
#right {
display: none;
}
}
BEFORE EDIT
max-width is not working on elements where position is set to absolute.
What exactly do you want do accomplish with absolute and also, what kind of layout do you want to get in the end?
remove the max-width from right div. also you have to set a percent less than 100% but totally 100% to make sense to responsive divs:
#container {
width: 100%;
text-align: center;
position: relative;
}
#middle {
background: #ddd;
margin: 0 auto;
position: relative;
width: 80%;
max-width: 300px;
height: 300px;
display: inline-block;
vertical-align: top;
}
#right {
background: yellow;
width: 20%;
display: inline-block;
vertical-align: top;
position: absolute;
}
#media screen and (max-width: 350px) {
#right {
display: none;
}
#middle {
width: 100%;
}
}
<div id="container">
<div id="middle">Centered</div>
<div id="right">Make me responsive</div>
</div>