简体   繁体   中英

Getting width of HTML document to resize with the browser window

I am new to web development and currently building a site for a friend that is being modeled after this one: http://fulton-demo.squarespace.com/

While I have most of the elements into code and styled, I cannot figure out how to get the images and content to fill 100% of the width AND resize when the browser window is resized. Like, take the first image on the link I provided for example...I would like it to look like this, meaning to not have any margins on either side and fill the browser window....and I can get it to do that, but it never shows 100% of the image and when I resize the window, nothing moves. Does that make sense?

I know this is probably a very elementary question, but I would love some insight on this. I can post any and all code if necessary. Thanks in advance guys!

EDIT: Here is my code:

HTML:

<!doctype html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<link rel="stylesheet" type="text/css" href="slick/slick.css"/>
<meta charset="utf-8">
</head>
<body>
<main id="mainContent" role="main">
<article role="article">
    <section>
        <header>
            <div class="container">
                <div class="single-item-rtl" dir="rtl">
                    <div><img src="img/6.jpg" height="600px" width="1400px" align= center/></div>
                    <div><img src="img/6.jpg"height="600px" width="1400px" align= center/></div>
                    <div><img src="img/6.JPG" height="600px" width="1400px" align= center/></div>
                    <div><img src="img/6.jpg" height="600px" width="1400px" align= center/></div>
                </div>
                <div id=logo><img src="img/SJ_WHT.png" height="170px" width="220x" align=center</div>
                <div id=text-top-carousel>
                    <h1>a better way to book creative spaces</h1>
                </div>
            </div>
        </header>
    </section>
    <section id="info">
        <div class="info">
            <div class="icon"></div>
            <h2>unique spaces <br> that inspire</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod temor incididunt ut labore et                       dolore magna aliqua</p>
        </div>
        <div class="info">
            <div class="icon"></div>
            <h2>hassle free <br> booking</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod temor incididunt ut labore et                        dolore magna aliqua</p>
        </div>
        <div class="info">
            <div class="icon"></div>
            <h2>share your <br>creative space</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod temor incididunt ut labore et                        dolore magna aliqua</p>
        </div>
        <div class="motto">
            <h1>unleash your creativity</h1>
            <p>We focus on your artistic expression at Studio Junkey. We believe that your creative process is                              limited when the necessary resources are not available to execute your vision. <br></nr> We want to                          ensure that you find the studio space that has the tools you need to express yourself and your vision</p>
        </div>
    </section>
    <section id="contactForm">
        <div class="form">
            <h3>Want to list a studio space?</h3>
            <p>We are looking for more studios. 
               Send us your information so we can connect.</p>
        </div>
    </section>
    <footer role="footer">
    </footer>
</article>
</main>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-migrate-1.2.1.min.js">      </script>
<script type="text/javascript" src="slick/slick.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('.single-item-rtl').slick({
        rtl: true,
        autoplay: true,
        autoplaySpeed: 3000,
    });
});
</script>
</body>
</html>

CSS:

@font-face {
font-family: "Brandon Grotesque";
src: url("fonts/Brandon_Grotesque/Brandon_reg.otf") format("opentype");
}

html, body {
height: 100%;
width: 100%;;
padding:0;
margin: 0;
}

body {
font-family:"Brandon Grotesque";
}

#mainContent {
background: white;
width:1500px;
}

.container {
width: 100%;
max-width: 1400px;
height:600px;
text-align:center;
margin: 0 auto;
}

#logo {
position:relative;
top:-595px;
left:0em;
}

#text-top-carousel h1 {
position:relative;
top:-15px;
left:0em;  
color:white;
font-size:55px;
padding: 10px;
}

#info {
margin: 0px;
clear:both;
}

.info {
width:466px;
height:400;
padding:10px;
background:white;
text-align: center;
color:#333333;
margin: 0px;
float:left;
clear: none;
}

.info.icon {
background:black;
border:1px solid white;
width:100px;
height:100px;
padding:10px;
margin-bottom: 25px;
}


.info h2 {
padding:300px 48px 10px 48px;
font-size: 45px;
margin-bottom: 0px;
margin-top: 0px;
line-height: 1em;
}

.info p {
padding:15px 50px 45px 50px;
margin: 0px;
font-size: 20px;
}

.motto {
background-image:url("img/6.jpg");
text-align: center;
color: white;
clear: both;
width:1400px;
margin:0 auto;
margin-bottom:0px;
height: 600px;
}

.motto h1 {
font-size: 60px;
padding-top: 90px;
margin-bottom: 20px;
}

.motto p {
font-size: 30px;
padding: 15px 100px 90px 100px;
}  

#contactForm {
background: #EDEFED;
margin-top:0px;
width: 1400px;
height: 600px;
margin: 0 auto;
clear: both;
}

.form {
text-align: center;
margin: 0;
width:50%;
height:500px;
color:#333333;
clear:both;
}

.form h3 {
margin: 0;
font-size: 40px;
padding: 115px 185px 50px 185px;
}

EDIT 2: THANK YOU for all the help thus far everyone!....For those following along in the comments, the issue that I'm having now can be shown by this screenshot . The image carousel seems to be filling the left side completely fine, but the right side still isn't being filled at all, there's still some space between the right edge of the img carousel and the browser window when I scroll to the right.

Try adding this to your CSS..

.single-item-rtl img {
  width: 100%;
  height: auto;
  max-height: 600px;
  margin: auto;
}

Also remove the height width and align from the image tag or they'll override the CSS.

Slick tries to add arrows to the left and right side of the slider which is what is causing the issue. Since we're taking up 100% of the screen they have no place to go.

$('.single-item-rtl').slick({
  rtl: true,
  arrows: false
});

Edit:

Remove the width from #mainContent to make .container 's with take up 100% of the screen.

Enclosing your content inside another element is helpful.

Note that you have to separate between enclosing elements required for your script to work, and those used to enchance your layout.

Also my solution implies you will ever be able to specify your image width in percent only . You can also add maximum and minimum properties.

.outer {
  width: 5cm; // arbitrary
}

.full-width {
  width: 100%;
}

.full-width img {
  width: 15%;
  max-width: 2cm;
  min-width: 5mm;
}
<div class="outer">
  <div class="full-width">
    <img src="http://cdn.sstatic.net/stackoverflow/img/favicon.ico"/>
  </div>
</div>

Use Percentage widths!!!!

Something simple like this would do:

.myImageClass{
  width: 50%;
  /*by not setting height, it will auto scale*/
}

DEMO:

 html,body{ margin:0; padding:0; } .myFullImg{ width:100%; } .myHalfImage{ width:50%; } 
 <img class="myFullImg" src="http://placekitten.com/g/200/200" alt=""/> <img class="myHalfImage" src="http://placekitten.com/g/200/400" alt=""/> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM