This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
flexible or centered page HTML CSS
I need a flexible or centered page design that works even for users with screen resolutions of 800*600. (CSS + HTML)
Should I use % or px for width and height?
Could you please give any example link?
<div id="content">
</div>
#content {
width:800px; (or width: 80%;)
margin:0 auto;
}
example: http://jsfiddle.net/UyUFa/
Related
This question already has answers here:
CSS Image size, how to fill, but not stretch?
(18 answers)
Closed 4 years ago.
really basic question, but I do marketing for a client so don't know too much besides basics HTML, CSS.
I've got an image slider in the URL below, what should I do so the image occupies the full space of the container (as there are bars on either side of the image). Do I just remove the padding or is there something more efficient to put in the stylesheet. Thanks heaps for your help
https://www.vibrantrealestate.com.au/property/outstanding-warehouse-space-style-on-the-citys-edge/
Try to add this rule in your CSS file :
.inspiry_property_portrait_slider .flex-viewport ul li a img{
width: 100% !important;
}
Here is the result :
Use the following css
div
{
background-image:url(http://placekitten.com/200/300);
width:300px;
height:100px;
background-repeat:no-repeat;
background-size: cover;
}
<div>a</div>
This question already has answers here:
How to Create Grid/Tile View? [duplicate]
(8 answers)
Closed 6 years ago.
I'm writing a a layout in CSS and HTML where I want the expected layout to be rendered out from left to right, top to bottom like this:
Each box has different height but the same width. I don't know how many boxes there are, it can vary from 2 to 20. I've tried float: left, but then you will get empty space depending on the size of the boxes. I've also tried column in CSS3, but It behaves very randomly, both on browser type, number of boxes and the size of the boxes. Does anyone know a smart trick to make it look like this, and preferably without the use of Javascript.
Masonry does this: http://masonry.desandro.com/ - That's with JS though
You could achieve this with pure CSS. Use the column-width property and for the spacing a combination of column-gap and padding
HTML
<section>
<img src="path" />
<img src="path" />
<img src="path" />
</section>
CSS
section{
column-width: 300px;
column-gap: 5px;
padding: 5px;
}
section img{
width: 100%;
}
Demo
Pen
This question already has answers here:
How to use css media queries correctly for responsive design
(2 answers)
Closed 6 years ago.
I've seen on a few websites in the past where a background image on a big DIV (say 100vh and 100vw) will stretch as the browser grows, but when a certain lower threshold is met (e.g. 800px), the background image doesn't stay at 100%, but starts clipping the background image instead.
I can't find those pages anymore now that I need to do it myself. CSS solution?
You can still use 100vh and 100vw something like below -
body {
margin:0; /* reset any browser-default margins */
height:100vh;
width:100vw;
}
img {
height: 100vh;
width: 100vw;
}
<body>
<img src="https://www.gstatic.com/webp/gallery3/1.png" />
</body>
Hope this will help you in some way (y).
This question already has an answer here:
How to change CSS of website if accessed through a mobile browser [closed]
(1 answer)
Closed 7 years ago.
I wanted to know how a html /css design can be made responsive so that (if that's what responsive means) the div are arranged according to the screen size(in case of desktop browser being resized manually at runtime).
for example :
i have div1, div2, div3 set as float left. they appear as 3 columns in my browser. Now if i resize(to a smaller size) my browser i want the div1 to come on top. div2 below it and div 3 below div2.
similarly, if i resize my web page fully i want the divs to again appear as 3 columns.
apart from the normal defalut behavior , is there any way through which changes can be specified separately?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="div1" style="width:500px;height:200px;background-color:red;float:left;"></div>
<div id="div2" style="width:500px;height:200px;background-color:yellow;float:left;"></div>
<div id="div3" style="width:400px;height:200px;background-color:green;float:left;"></div>
</body>
</html>
please any help would be greatly appreciated. I am completely new to responsive design layout.
This is mainly achieved with CSS3 Media queries. You can use a CSS frameworks and follow the grid system to reduce your workload.
CSS3 #media Rule
Frontend Frameworks
Twitter Bootstrap
Foundation
Semantic UI
Pure
Duplicate of following stack overflow questions
How do I make a website responsive?
How to create a responsive web design?
The basics of a responsive layout are the use of percentage insteed of pixels and adding breakpoints with media queries.
In your example, you have 3 divs floating so the css should look like this:
#div1, #div2, #div3 {
float:left;
height:200px;
}
#div1 {
background-color:red;
width:40%;
}
#div2 {
background-color:yellow;
width:40%;
}
#div3 {
background-color:green;
width:20%;
}
Always making the sum of all your floating widths 100%.
Then add a breaking point (or as many as you need) like this:
#media (max-width: 600px) {
#div1, #div2, #div3 {width:100%;}
}
where you tell your browser to change the css properties of your divs when window width is 600px or lower. In this case you make each div 100% width so they will stack as you want keeping the html order.
JSFIDDLE
You have to use percentage instead of fixed pixel-values. This is called "making the design fluid".
Have a look at this: https://teamtreehouse.com/community/pixel-to-percentage-conversion
There will be points (when the width becomes to small) at which you're layout doesn't work anymore. Then you use media-queries to re-structure your layout.
This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 8 years ago.
How do you center a div or anything else horizontally, so that on both sides the empty spaces are equal? And the div is exactly in the middle? No matter the size of the objects.
Take for example: the Stackoverflow site itself.
Except for the black header on the top of this site, everything is in the middle and the empty spaces on both sides are equal to each other.
I've searched for a long time, but I only encountered the wrong answers or vague answers.
Please help and thank you!
In css, you can use margin: auto;
A common pattern is to wrap your content in a container with a fixed width and add margin: auto; to it.
try this. here is why
margin: 0 auto;
The common way is using margin:0px auto. Look at the following example.
HTML
<div id="wrapper">
<div class="test">
This is my content Div.
</div>
</div>
CSS
.test
{
width:60%;
border:1px solid #ccc;
margin:0px auto;
}
DEMO