2

Web サイトの作成を開始しました。バナーをナビゲーション バーの下に配置したいと考えています。最初は両方の div を希望どおりに配置していましたが、サイズを変更すると、右の div が左の div の下に移動しました。どちらも float:left と float:right を使用して配置されています。

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Welcome </title>
<link rel="stylesheet" type="text/css" href="Style1.css">
</head>

<body>
<div id="wrapper">
<div id="header">
<div id="topHeader">
<div id="logo">
<img src="Images/HeaderLogo.png"  alt="Logo for Matt Meadows">
</div>

</div> <!--End of topHeader -->
</div> <!--End of Header -->
<nav>
<div id="nav-links">
<ul>
<li>Home</li>
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>

</nav>
<div id="contentHeaderContainer">
<div id="contentHeader">
<img src="Images/HomePageContentHeader.png">
<div id="headerText">
<h1 id="welcome">WELCOME</h1>
<p class="Text1">The Way Website Development should be...</p>
<p class="Text2">UNIQUE</p>
<p class="Text5">CONCISE</p>
<p class="Text3">VIBRANT</p>
<p class="Text4">PROFESSIONAL</p>
<p class="Text6">SIMPLE</p>
</div> <!--End of headerText -->
</div> <!--End of contentHeader -->
</div> <!--End of contentHeaderContainer -->
</div> <!--End of wrapper -->
</body>
</html>

CSS:

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

#wrapper
{
margin-left: auto;
margin-right: auto;
}

#topHeader
{
width: 100%;
height:75px;
background: rgb(36,36,36); /* Old browsers */
background: -moz-linear-gradient(top,  rgba(36,36,36,1) 0%, rgba(52,52,52,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(36,36,36,1)), color-stop(100%,rgba(52,52,52,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  rgba(36,36,36,1) 0%,rgba(52,52,52,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  rgba(36,36,36,1) 0%,rgba(52,52,52,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  rgba(36,36,36,1) 0%,rgba(52,52,52,1) 100%); /* IE10+ */
background: linear-gradient(to bottom,  rgba(36,36,36,1) 0%,rgba(52,52,52,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#242424', endColorstr='#343434',GradientType=0 ); /* IE6-9 */
}

#logo
{
margin-left: 50px;
padding-top: 10px;
}

nav
{
float:left;
width: 100%;
height: 45px;
background: url('Images/NavBG.png');
-webkit-box-shadow: 0px 7px 15px rgba(20, 20, 20, 0.5);
-moz-box-shadow:    0px 7px 15px rgba(20, 20, 20, 0.5);
box-shadow:         0px 7px 15px rgba(20, 20, 20, 0.5);
}

#nav-links
{
margin: 0 auto;
}

ul
{
margin:0 auto;
padding:0;
list-style:none;
width: 700px;
}

li
{
display:inline;
float:left;
padding: 10px 55px 10px 55px;
font-size: 20px;
font-family: Arial, Helvetica, sans-serif;
color: #CCCCCC;
-webkit-transition: background 0.5s ease;
-moz-transition: background 0.5s ease;
-o-transition: background 0.5s ease;
transition: background 0.5s ease;
}

li:hover
{
background: #4d4c4c;
color: #FFF;
}

#contentHeaderContainer
{
height: 450px;
margin-left: auto;
margin-right: auto;
background: rgb(36,36,36); /* Old browsers */
background: -moz-linear-gradient(top,  rgba(36,36,36,1) 0%, rgba(52,52,52,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(36,36,36,1)), color-stop(100%,rgba(52,52,52,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  rgba(36,36,36,1) 0%,rgba(52,52,52,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  rgba(36,36,36,1) 0%,rgba(52,52,52,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  rgba(36,36,36,1) 0%,rgba(52,52,52,1) 100%); /* IE10+ */
background: linear-gradient(to bottom,  rgba(36,36,36,1) 0%,rgba(52,52,52,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#242424', endColorstr='#343434',GradientType=0 ); /* IE6-9 */
-webkit-box-shadow: 0px 7px 15px rgba(20, 20, 20, 0.5);
-moz-box-shadow:    0px 7px 15px rgba(20, 20, 20, 0.5);
box-shadow:         0px 7px 15px rgba(20, 20, 20, 0.5);
}


#contentHeader img
{
float:left;
margin-top: 50px;
}


#headerText
{
float:right;
width: 700px;
height: 300px;
}

#welcome
{
font-family: "Myriad Pro", Myriad, "Liberation Sans", "Nimbus Sans L", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #cccccc
}

p
{
font-family: "Myriad Pro", Myriad, "Liberation Sans", "Nimbus Sans L", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.Text1
{
color: #999999;
font-size: 20px;
font-weight: bold;
}

.Text2
{
color:#8d9999;
font-size: 22px;
font-weight: bold;
margin-left: 100px;
margin-top: 50px;
}

.Text3
{
color:#8d9999;
font-size: 22px;
font-weight: bold;
margin-left: 350px;
margin-top: 50px;
}

.Text4
{
color:#8d9999;
font-size: 22px;
font-weight: bold;
margin-left: 100px;
margin-top: 50px;
}

.Text5
{
float:right;
color:#8d9999;
font-size: 22px;
font-weight: bold;
margin-top:-50px;
}

.Text6
{
float:right;
color:#8d9999;
font-size: 22px;
font-weight: bold;
margin-top:-50px;
}

編集: http://jsfiddle.net/w6qxU/

サイズを変更しても、 #contentHeaderContainer 内の両方の子 div を完全に静止させたいと思います。たとえば、ウィンドウのサイズを変更すると、ウィンドウの境界が移動しますが、コンテンツは完全に静止したままです。

4

3 に答える 3

3

headerText画像を並べて表示したい場合は、画像に十分なスペースを与える必要があります。に適切な幅を追加します#wrapper

#wrapper {
    margin-left: auto;
    margin-right: auto;
    width:960px;
}

JSFiddle (ラッパー/幅)

常に幅全体を占有したい場合は、min-width代わりに使用してください

#wrapper {
    margin-left: auto;
    margin-right: auto;
    min-width:960px;
}

JSFiddle (ラッパー/最小幅)

于 2013-05-10T22:45:31.860 に答える
0

ブラウザー ウィンドウのサイズを変更するときにコンテンツが移動しないようにするには、絶対測定単位 (ピクセル) の使用を避け、パーセンテージ % とビューポート単位 vw のみを使用する必要があります。これは私にとって完璧に機能しました。私はこれらのスタイルを Div に使用しました。

.centercolumn {
float: left;
width: 50%;
padding: 1%;
background-color: #f8df67;
height: 80vh;
margin-top: 1%;
margin-left: 0px;
margin-right: 1%;}


.sidecolumn {
float: left;
width: 20%;
padding: 1%;
margin-top: 1%;
margin-left: 0px;
margin-bottom: 1%;
height: 80vh;}
于 2020-09-30T09:34:10.737 に答える