Work with html-element width when change scale of browser [closed] - html

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have the folowing html-murkup structure:
<div class="wrapper">
<div class="my_line"></div>
</div>
Wrapper has width 1200 px. I want to make div.my_line to has width 100% of screen when user change scale of screen. How can I do this? I try to use background-repeat, I am new in frontend, can somebody help me?

So just guessing here but you want the my_line div to stretch 100% of the width once the screen is at 1200px?
If so you'd use this:
/* Check the screen width, in this case looking for the screen to reach 1200px or below. Then extend the my_line div to 100% */
#media (max-width: 1200px) {
.wrapper .my_line {
width: 100%;
}
}

So, if you want the my_line to be the same size as the wrapper and shrink when you resize the window use this approach :
.wrapper {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.wrapper .my_line {
width: 100%;
}
That way wrapper will have 100% of the browser but be limited and always centered. While the my_line will inherit the full width.
So, when you resize, to less than 1200px the wrapper and my_line will shrink with the window.
EDIT:
If you want the my_line to be bigger than the wrapper, why placing it inside the wrapper ? Just place it above or underneath of the wrapper.
The solution you got works anyways if you change the HTML. The problem with your solution is that if you later add position: relative to the wrapper it won't work. While if you change the HTML structure so that my_line is direct children of the body it will still work.

Thanks guys, I do this and it help:
.my_line {
position:absolute;
width: 100%;
left:0;
right:0;
height: 3px;
}

Related

How to make image dimensions shrink according to container? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have this blogspot blog: sourcewing.blogspot.com
Now if you go to drawings tab, you'll notice the electric bulb image is not aligned center of the post. What I want to say is that it is taking its original width and height. If the width would be 1200px, it would go out of the tbody (Please check the HTML of this image).
What I want is that it should shrink automatically (maintaining the proportions), according to the width of div class="post-body entry-content"... element (you'd find by inspect element). This should apply on the all images that have more width than this div.
Also, I would like to know why isn't it automatically shrinking, while the text is automatically aligned?
Remove the fixed height and width attributes from the img element.
You can then add a class eg .auto-contain or whatever with the following css:
.auto-contain {
display: block;
height: auto;
max-width: 100%;
width: 100%;
}
This will force the image to always have the same width as the container, but the height will grow in proportion.
So you are missing a few things.
height: auto;
max-width: 100%;
box-sizing: border-box;
This will achieve exactly what you are after.
Just to explain:
height: auto; - This will make sure your picture remains in proportion.
max-width: 100%; - Your image will behave responsively but wont break it's own natural sizing.
box-sizing: border-box; - Because you have padding you don't want to break the width this will keep padding but not break out of your container.
First remove the width and height attribute from your img tag.
To solve the problem :
img {
height: 90%;
width: 90%;
}
if you set height and width 100% normally your image would be as big as the parent. But in your case this does not work. 90% however looks better.

CSS Resize images to fit in a container [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to fit images in a container with different images size like this :
Example :
1. Full size in a container with bigger size.
2. Middle in a container with horizontal size.
3. Middle in a container with vertical size.
Check out an example from this link
As Gautam said, you need to use
max-height:100%;
max-width: 100%;
So you can define a class for the containers
.container
{
display:flex;
align-items:center;
justify-content:center;
border:1px solid black;
background-color: #ffffff;
width: 50px;
height: 50px;
}
And a class for the images
.maxsize
{
max-height:100%;
max-width: 100%;
}
The display:flex; property makes the container easier to config, so you can center the contents faster. You can remove the border property, it's only for easier viewing of the container edges.
Hope it helps.
Updated jsfiddle
Just set this property on the parent container.
background-size : contain;
background-repeat: no-repeat;
This tells the browser to make sure that the image does not exceed the size of the parent container.
this is easy to do
just align your image to the center and
use
max-height:100%
and
max-width:100%
As Robert mentioned:
background-size : contain;
background-repeat: no-repeat;
But be sure to add:
background-position: center;
Then it will remain within the boundaries of the container and be centered.

Is it allowed/recommended to use height in responsive websites? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I saw somewhere that it wasn't recommended to use height and use padding instead, why that? The height and the padding produces the same results - at least in my trials -... is there a reason for me be to be using padding only instead of height?
To answer your question - of course you can use height in responsive websites without a problem.
I think where you may have read about using padding in place of height is for keeping the aspect ratio of an element the same since percentage based padding is relative to the width of the element and percentage based height is relative to it's container.
A common use case for this is embedding a YouTube video in a responsive wesbite.
HTML
<div class="video-container">
<iframe src="//www.youtube.com/embed/k_d5jWvBirU?wmode=opaque&rel=0&showinfo=0&modestbranding=1&controls=2&autohide=1" frameborder="0" allowfullscreen=""></iframe>
</div>
CSS
.video-container {
position: relative;
width: 100%;
height: 0;
padding-bottom: 56.25%;
background: #000;
}
.video-container iframe {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
}
Fiddle here: http://jsfiddle.net/84wm08k7/
As you can see the height of the video-container is set to 0 and the padding-bottom is set to 56.25%. This restricts this element to being a 16:9 aspect ratio for video and is responsive.
well to start if you use padding then the page will stretch itself to fit the screen leaving the given amount of border (padding). If you use a specified height (in pixels per say) the page will always be the same height regardless the resolution of the screen. If you are using height as a percentage or some analogous value, than it shouldn't matter other than that the amount of space (padding) will vary depending on the screen.
It depends on what you're doing. For a lot of my work, I'll set a min-height or max-height that way the element grows or shrinks depending on the content.
Padding would work as well, if for instance you have an element with text that would be centered vertically, you can use padding to control height as well. It's all up to the site design, and what you're trying to accomplish.
this is a code example you can check w3schools.com for further information, I've chosen the example in which you can manipulate the dom
function myFunction() {
document.getElementById("myBtn").style.height = "50px";
}
<!DOCTYPE html>
<html>
<body>
<button type="button" id="myBtn" onclick="myFunction()">Change the height of this button</button>
</body>
</html>

HTML5 positioning [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
is possible to make a specific element about 5px longer that it would automatically be? because my article element has a video element which sticking out of the given space a bit, while I could just set the height manually I thought it would be better to have it set itself automatically (like it normally does) only adding about 5px. Any Help?
I'm not sure I understand the question, but have you tried giving it a padding-bottom of 5px?
Try using a dynamic width to set the width of your contained element.
Eg.
article {
width:300px;
}
contained-element{
width:95%;
}
Just give padding-bottom:5px to your <article> elements, & make height:auto for both elements, then <article> element will expand as per height with 5px at bottom.
Am not very much sure what are you asking about but if it's regarding fitting your video in a div for that you can create a wrapper class such as
.wrapper-div {
position: relative;
padding-bottom: 20%;
height: 0;
}
then have the child element inside it
.element-to-load{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
I assume you want to the div to expand if the video is larger than the article.
To do this you just need to:
1) Give the Outer Div a height:auto - and a min-height:
2) Give the Inner Div a margin-bottom of 5px
Check out this Fiddle Demo
Does this answer your question?
Just set the CSS for that element be (use the actual pixel width and height):
height: 25px;
width: 50px;
and the height and the width will be forced to be that height and width.
Although if possible try to use 'em' so that it is automatically responsive.

pre tag width:100% or max-width:100% overflow:auto is not flexible [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Here is a link to an example:
http://whiterootmedia.com/database/dusty_arlia/the_img_tag_and_its_attributes.html
My tag element will contain long lines of code. Whenever its container changes to a width:auto (below 1200px width) the tag will not shrink in width. I would like the window to keep shrinking and the element to have a scroll bar for the width.
Currently I have this css:
pre {overflow:auto; max-width:100%}
I added this css to my display:table; container:
table-layout:fixed;
width: 100%;
CSS display:table layouts are harder to style. If you're just starting out, just use float to position divs in a container.
You have fixed values in your css files, look at the styles of pre when < 1200px
article_two_column.css:101
#media only screen and (min-width: 336px) {...
article_two_column.css:103
pre {
max-width: 260px;
}
article_two_column.css:87
#media only screen and (min-width: 728px) { ...
article_two_column.css:89
pre {
max-width: 652px;
}
Set the values to % and you will get a fluid result (remember you can also set decimals not only int's).