无法设置我的网站的正确位置和宽度。

huangapple go评论69阅读模式
英文:

Unable to set the correct position and width for my site

问题

Sure, here are the translated parts of your code:

HTML Code (index.html):

<!DOCTYPE html>
<html>
<head>
    <title>Disusa</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <link rel="stylesheet" href="test.css">
</head>
<main>
<header class="header">
    <div class="navbar">
        <div class="search-container">
            <input type="text" placeholder="Que voulez vous comparer...">
            <button type="submit"><i class="fa fa-search"></i></button>
        </div>
        <div class="icons-container">
            <a href="#profile" class="icon-link"><i class="fa fa-user"></i></a>
            <a href="#panier" class="icon-link"><i class="fa fa-shopping-cart"></i></a>
        </div>
    </div>
    <nav class="nav">
        <ul>
            <li><a href="#home" id="home">Accueil</a></li>
            <li><a href="#allproducts" id="project">Tout les produits</a></li>
            <li><a href="#settings" id="about">Paramètres</a></li>
            <li><a href="#contact" id="how">Nous contacter</a></li>
        </ul>
    </nav>
</header>
<body>
    <div class="imgs_home">
        <figure class="img_home">
            <img class="img3" src="./Picture/pc premonter.jpg" alt="PC Prémonter" />
            <figcaption>
                <h3>PC <span>Prémonter</span></h3>
            </figcaption>
            <a href="#pc-premonter"></a>
        </figure>
        <figure class="img_home img_poupout">
            <img class="img1" src="./Picture/pc montage.jpg" alt="PC Custom" />
            <figcaption>
                <h3>PC <span>Custom</span></h3>
            </figcaption>
            <a href="#custom"></a>
        </figure>
        <figure class="img_home">
            <img class="img2" src="./Picture/pc portable.jpg" alt="PC Portable" />
            <figcaption>
                <h3>PC <span>Portable</span></h3>
            </figcaption>
            <a href="#pc-protable"></a>
        </figure>
    </div>
</main>
<script src="main.js"></script>
</body>
</html>

CSS Code (style.css):

/* Styles for navigation bar, icons, and search container */
.navbar {
    /* ... (existing CSS) ... */
}

/* Styles for icons */
.icon-link {
    /* ... (existing CSS) ... */
}

.fa-user, .fa-shopping-cart {
    /* ... (existing CSS) ... */
}

.fa-shopping-cart:hover, .fa-user:hover {
    /* ... (existing CSS) ... */
}

/* Styles for search container */
.search-container {
    /* ... (existing CSS) ... */
}

.search-container input[type=text] {
    /* ... (existing CSS) ... */
}

.search-container button {
    /* ... (existing CSS) ... */
}

.fa-search {
    /* ... (existing CSS) ... */
}

/* Media query for smaller screens */
@media screen and (max-width: 576px) {
    .search-container {
        /* ... (existing CSS) ... */
    }
}

/* Styles for other elements (main_title, imgs_home, etc.) */
/* ... (existing CSS) ... */

CSS Code (test.css):

/* ... (existing CSS) ... */

JavaScript Code (main.js):

// JavaScript code is not translated as it does not contain text to be translated.

Please note that I've only translated the relevant parts of your HTML and CSS code. The JavaScript code does not contain any text to be translated.

英文:

Hello I want to put the header on the whole width of the screen and the images align but I could not, how to do ?

I have already tried to add to the header width:100%; and position: static; but nothing changes

HTML Code ( index.html ) :

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Disusa&lt;/title&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;test.css&quot;&gt;
&lt;/head&gt;
&lt;main&gt;
&lt;header class=&quot;header&quot;&gt;
&lt;div class=&quot;navbar&quot;&gt;
&lt;div class=&quot;search-container&quot;&gt;
&lt;input type=&quot;text&quot; placeholder=&quot;Que voulez vous comparer...&quot;&gt;
&lt;button type=&quot;submit&quot;&gt;&lt;i class=&quot;fa fa-search&quot;&gt;&lt;/i&gt;&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;icons-container&quot;&gt;
&lt;a href=&quot;#profile&quot; class=&quot;icon-link&quot;&gt;&lt;i class=&quot;fa fa-user&quot;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;a href=&quot;#panier&quot; class=&quot;icon-link&quot;&gt;&lt;i class=&quot;fa fa-shopping-cart&quot;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;nav class=&quot;nav&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#home&quot; id=&quot;home&quot;&gt;Accueil&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#allproducts&quot; id=&quot;project&quot;&gt;Tout les produits&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#settings&quot; id=&quot;about&quot;&gt;Param&#233;tres&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#contact&quot; id=&quot;how&quot;&gt;Nous contacter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/nav&gt;
&lt;/header&gt;
&lt;body&gt;
&lt;div class=&quot;imgs_home&quot;&gt;
&lt;figure class=&quot;img_home&quot;&gt;
&lt;img class=&quot;img3&quot; src=&quot;./Picture/pc premonter.jpg&quot; alt=&quot;PC Premonter&quot; /&gt;
&lt;figcaption&gt;
&lt;h3&gt;PC &lt;span&gt;Pr&#233;monter&lt;/span&gt;&lt;/h3&gt;
&lt;/figcaption&gt;
&lt;a href=&quot;#pc-premonter&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;
&lt;figure class=&quot;img_home&quot; class=&quot;img_poupout&quot;&gt;
&lt;img class=&quot;img1&quot; src=&quot;./Picture/pc montage.jpg&quot; alt=&quot;PC Custom&quot; /&gt;
&lt;figcaption&gt;
&lt;h3&gt;PC &lt;span&gt;Custom&lt;/span&gt;&lt;/h3&gt;
&lt;/figcaption&gt;
&lt;a href=&quot;#custom&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;
&lt;figure class=&quot;img_home&quot;&gt;
&lt;img class=&quot;img2&quot; src=&quot;./Picture/pc portable.jpg&quot; alt=&quot;PC Portable&quot; /&gt;
&lt;figcaption&gt;
&lt;h3&gt;PC &lt;span&gt;Portable&lt;/span&gt;&lt;/h3&gt;
&lt;/figcaption&gt;
&lt;a href=&quot;#pc-protable&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;
&lt;/div&gt;
&lt;/main&gt;
&lt;script src=&quot;main.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt; 

CSS Code ( style.css ) :

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: #ccc;
}
/* Style de la barre de navigation */
.navbar {
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
background: rgb(0, 0, 0);
}
/* Style des ic&#244;nes */
.icon-link {
margin-left: 10px;
margin-right: 30px;
font-size: 25px;
}
.fa-user, .fa-shopping-cart {
color: rgb(255, 255, 255); /* Rendre les ic&#244;nes noir */
}
.fa-shopping-cart:hover, .fa-user:hover { /* faire changer de couleur lors de son survol */
color: rgb(214, 214, 214);
}
/*                   ---- barre de recherche ----           */
.search-container { 
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
transition: width 0.5s ease; /* transition fluide de la largeur */
width: 75% ;
}
.search-container input[type=text] {
width:  450px;
padding: 12px;
border: none;
border-radius: 10px 0px 0px 10px;
}
.search-container button {
padding: 12px;
border: none;
border-top-right-radius: 15px;
border-bottom-right-radius: 15px;
background: rgb(255, 255, 255);
color: rgb(0, 0, 0);
}
.search-container button:hover{
background: rgb(214, 214, 214);
}
.fa-search {
border-radius: 20px; /* Ajouter cette propri&#233;t&#233; pour rendre l&#39;ic&#244;ne de recherche arrondi */
}
@media screen and (max-width: 576px) {
.search-container {
width: 60%; /* largeur r&#233;duite pour les fen&#234;tres plus petites */
}
}
/*                   ---- barre de recherche ----           */
.main_title{
text-align: center;
margin-top: 15px;
}
#welcome{ 
font-size: 24px;
font-family:Verdana, Geneva, Tahoma, sans-serif;
}
.img1{
width: 370px;
height: 208px;
width: 100%;
}
.imgs_home{
text-align: center;
}
@import url(https://fonts.googleapis.com/css?family=Roboto:100,700;);
.img_home {
background-color: rgb(41, 46, 57);
color: #fff;
display: inline-block;
font-family: &#39;Roboto&#39;, sans-serif;
font-size: 24px;
margin: 10px;
max-width: 370px;
min-width: 230px;
overflow: hidden;
position: relative;
text-align: center;
width: 100%;
}
.img_home * {
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: all 0.45s ease;
transition: all 0.45s ease;
}
.img_home:before,
.img_home:after {
background-color: rgba(46, 52, 64,  0.5);
border-top: 50px solid rgba(46, 52, 64, 0.5);
border-bottom: 50px solid rgba(46, 52, 64, 0.5);
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
content: &#39;&#39;;
-webkit-transition: all 0.3s ease;
transition: all 0.3s ease;
z-index: 1;
opacity: 0;
}
.img_home:before {
-webkit-transform: scaleY(2);
transform: scaleY(2);
}
.img_home:after {
-webkit-transform: scaleY(2);
transform: scaleY(2);
}
.img_home img {
vertical-align: top;
max-width: 100%;
backface-visibility: hidden;
}
.img_home figcaption {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
align-items: center;
z-index: 1;
display: flex;
flex-direction: column;
justify-content: center;
line-height: 1.1em;
opacity: 0;
z-index: 2;
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
.img_home h3 {
font-size: 1em;
font-weight: 400;
letter-spacing: 1px;
margin: 0;
text-transform: uppercase;
}
.img_home h3 span {
display: block;
font-weight: 700;
}
.img_home a {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 3;
}
.img_home:hover &gt; img {
opacity: 0.7;
}
.img_home:hover:before,
.img_home:hover:after {
-webkit-transform: scale(1);
transform: scale(1);
opacity: 1;
}
.img_home:hover figcaption {
opacity: 1;
-webkit-transition-delay: 0.1s;
transition-delay: 0.1s;
}
@media screen and (max-width: 100px) {
.img_home {
width: 50%; /* largeur r&#233;duite pour les fen&#234;tres plus petites */
}
.search-container {
width: 40%; /* largeur r&#233;duite pour les fen&#234;tres plus petites */
}
}

CSS Code ( test.css ) base code as scss and transform to css code :

@font-face {
font-family: &quot;Mona Sans&quot;;
src: url(&quot;https://assets.codepen.io/64/Mona-Sans.woff2&quot;) format(&quot;woff2 supports variations&quot;), url(&quot;https://assets.codepen.io/64/Mona-Sans.woff2&quot;) format(&quot;woff2-variations&quot;);
font-weight: 100 1000;
}
@layer properties {
@property --after-bg-position {
syntax: &quot;&lt;number&gt;&quot;;
inherits: true;
initial-value: 0;
}
@property --after-radial-bg-position {
syntax: &quot;&lt;number&gt;&quot;;
inherits: true;
initial-value: 0;
}
@property --after-bg-width {
syntax: &quot;&lt;number&gt;&quot;;
inherits: true;
initial-value: 100;
}
@property --after-bg-opacity {
syntax: &quot;&lt;number&gt;&quot;;
inherits: true;
initial-value: 20;
}
@property --after-shadow-offset {
syntax: &quot;&lt;number&gt;&quot;;
inherits: true;
initial-value: 15;
}
@property --after-scale {
syntax: &quot;&lt;number&gt;&quot;;
inherits: true;
initial-value: 0.85;
}
@property --li-before-opacity {
syntax: &quot;&lt;number&gt;&quot;;
inherits: true;
initial-value: 0;
}
}
:root {
/* -- Colors: */
--body-bg-color: hsl(221deg 16% 6%);
/* -- Background */
--bg-position: 0;
/* -- misc */
--debug: 0;
--trs-easing: cubic-bezier(.41,-0.09,.55,1.09);
--trs-timing: 300ms;
--trs-delay: 80ms;
}
*,
*:before,
*:after {
box-sizing: border-box;
/* debug */
outline: calc(var(--debug) * 1px) dashed rgba(255, 0, 0, 0.5);
}
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
body {
background: var(--body-bg-color);
display: grid;
place-items: center;
font-family: &quot;Mona Sans&quot;, sans-serif;
}
main {
width: 100%;
max-width: 700px;
color: rgb(255, 255, 255);
}
main header {
text-align: center;
margin-bottom: 6em;
}
.nav {
transition: --after-bg-position var(--trs-timing) var(--trs-easing) 0.2s, --after-radial-bg-position var(--trs-timing) var(--trs-easing) 0.2s, --after-bg-width var(--trs-timing) var(--trs-easing) 0.2s, --after-bg-opacity var(--trs-timing) var(--trs-easing) 0.2s, --li-before-opacity var(--trs-timing) var(--trs-easing) 0.2s;
background: var(--body-bg-color);
border-radius: 100px;
position: relative;
}
.nav:before {
content: &quot;&quot;;
display: block;
position: absolute;
width: calc(var(--after-bg-width) * 1px - 8px);
height: 100%;
background: rgb(255 255 255/calc(var(--after-shadow-offset) * 1%));
border-radius: 100px;
filter: blur(20px);
left: 0;
top: 0;
transform: translateX(calc(var(--after-bg-position) * 1px)) scale(1.1);
}
.nav ul {
position: relative;
padding: 0;
margin: 0;
list-style: none;
display: flex;
justify-content: space-between;
height: 80px;
border-radius: 100px;
background-position: center center;
background-image: radial-gradient(ellipse 150px 100px at calc(var(--after-radial-bg-position) * 1px) bottom, rgb(255, 255, 255) 0%, rgba(255, 255, 255, 0.2) 100%);
/*
&amp;:has(li.active:hover):after {
--after-bg-opacity: 50;
--after-shadow-offset: 10;
}
*/
/* 
Some :has() goodness to control the 
nav:after border-radius hihihi 
*/
}
.nav ul:active {
--after-scale: 0.75 ;
}
.nav ul:before {
content: &quot;&quot;;
display: block;
position: absolute;
width: calc(100% - 2px);
height: calc(100% - 2px);
background: var(--body-bg-color);
top: 1px;
left: 1px;
border-radius: 100px;
}
.nav ul:after {
content: &quot;&quot;;
display: block;
position: absolute;
z-index: 1;
width: calc(var(--after-bg-width) * 1px - 12px);
height: calc(100% - 12px);
background: linear-gradient(to bottom, rgb(255 255 255/calc(var(--after-bg-opacity, 0) / 10 * 1%)), rgba(255, 255, 255, 0.1));
box-shadow: inset 0 -6px calc(var(--after-shadow-offset, 0) * 1px) rgb(255 255 255/calc(var(--after-bg-opacity) * 1%));
left: 6px;
top: 6px;
transform: translate(calc(var(--after-bg-position) * 1px), 0);
border-radius: 100px 12px 12px 100px;
transition: --after-bg-opacity var(--trs-timing) var(--trs-easing) var(--trs-delay), --after-shadow-offset var(--trs-timing) var(--trs-easing) var(--trs-delay), border-radius var(--trs-timing) var(--trs-easing) var(--trs-delay);
pointer-events: none;
}
.nav ul li {
padding: 1em;
height: 100%;
width: 100%;
position: relative;
transform-style: preserve-3d;
perspective: 800px;
}
.nav ul li:not(.active):hover {
--li-before-opacity: 0.3;
}
.nav ul li:before {
content: &quot;&quot;;
display: block;
position: absolute;
z-index: 1;
background: rgba(255, 0, 0, 0.1);
width: 100%;
height: 100%;
top: 0;
left: 0;
border-radius: 8px;
pointer-events: none;
user-select: none;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.35));
opacity: var(--li-before-opacity);
transform: scale(var(--after-scale)) rotateY(calc(var(--tilt-bg-y) * 3 * -1deg)) rotateX(calc(var(--tilt-bg-x) * 3 * 1deg)) translateZ(15px);
transition: --li-before-opacity var(--trs-timing) var(--trs-easing), --after-scale calc(var(--trs-timing) / 2) var(--trs-easing) calc(var(--trs-delay) / 2);
}
.nav ul li:first-of-type:before {
border-radius: 100px 12px 12px 100px;
}
.nav ul li:last-of-type:before {
border-radius: 12px 100px 100px 12px;
}
.nav ul li a {
display: block;
color: inherit;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
position: relative;
z-index: 10;
}
.nav ul:has(li.active:first-of-type a):after {
border-radius: 100px 12px 12px 100px;
}
.nav ul:has(li.active:last-of-type a):after {
border-radius: 12px 100px 100px 12px;
}
.nav ul:has(li.active:nth-child(n+2):nth-child(-n+3) a):after {
border-radius: 100px;
}

JavaScript Code ( main.js ) :

var snippet = [].slice.call(document.querySelectorAll(&#39;.hover&#39;));
if (snippet.length) {
snippet.forEach(function (snippet) {
snippet.addEventListener(&#39;mouseout&#39;, function (event) {
if (event.target.parentNode.tagName === &#39;figure&#39;) {
event.target.parentNode.classList.remove(&#39;hover&#39;)
} else {
event.target.parentNode.classList.remove(&#39;hover&#39;)
}
});
});
}
function inverseMousePosition(element, event) {
const rect = element.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const res = {
x1: -(x - rect.width / 2) / 20, // top left
y1: -(y - rect.height / 2) / 20,
x2: -(x - rect.width / 2) / 20, // top right
y2: (y - rect.height / 2) / 20,
x3: (x - rect.width / 2) / 20, // bottom left
y3: -(y - rect.height / 2) / 20,
x4: (x - rect.width / 2) / 20, // bottom right
y4: (y - rect.height / 2) / 20
};
const resKey =
&quot;x&quot; + (x &lt; rect.width / 2 ? 1 : 2) + (y &lt; rect.height / 2 ? 1 : 3);
const tilt = res;
return tilt !== undefined ? tilt : 0; // default to 0 if undefined
}

Thanks in advance...

答案1

得分: 1

你可能在寻找类似这样的内容:

#header
{
  width:100%;
  height:20%;   // 所需的高度
  position:absolute;
  top:0;
  left:0;
  background-color:blue;
}

我认为 position:absolute 是你所寻找的。参考链接:
https://stackoverflow.com/questions/22551730/how-to-change-header-and-footer-to-full-width

英文:

You may be looking for something like this:

#header
{
width:100%;
height:20%;   // the desired height
position:absolute;
top:0;
left:0;
background-color:blue;
}

I believe position:absolute is what you're looking for. See:
https://stackoverflow.com/questions/22551730/how-to-change-header-and-footer-to-full-width

huangapple
  • 本文由 发表于 2023年6月12日 18:55:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455955.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定