使用HTML/CSS实现图片按钮对齐时,最右侧按钮错位问题求助
Hey there! Let's get that last button aligned properly. After checking your code, I found a few straightforward issues that are causing the misalignment:
- Unclosed HTML Tag: Your third
.columndiv isn't closed, which means the fourth column is nested inside it instead of being a sibling element. That's the biggest reason for the misalignment. - Incorrect Image Width: The last image has
style="width:200%;"set, which makes it way larger than its container and throws off the layout. - Style Conflicts & Typos:
- You have both a CSS rule setting
body { background: url('realheckindoggopupper.png') }and an inlinestyle="background-color:black"on the body tag—pick one to avoid confusion. text-sizeisn't a valid CSS property; you wantfont-sizefor your<h1>.- The
<br>tag doesn't need a closing</br>(it's self-closing in HTML:<br/>or just<br>).
- You have both a CSS rule setting
Corrected HTML & CSS
* { box-sizing: border-box; } body { background: url('realheckindoggopupper.png'); background-color: black; /* Fallback if image doesn't load */ margin: 0; /* Remove default body margin to avoid extra space */ } div { padding: 5px; background-color: black; box-sizing: border-box; } .column { float: left; width: 25%; padding: 1px; } .row::after { content: ""; clear: both; display: table; }
<body> <div> <h1 style="color:blue;font-size:50px;">Welcome to the Mamiya Mansion!</h1> <p style="color:white;"> This is a place where I put all my thoughts. I talk about all my different interests here, from retrogaming, to retro-anime, linguistics, and philosophy. I don't have much here yet, more is on the way (including better CSS!), <br> but these buttons will allow you to access different parts I'm working on. </p> </div> <div class="row"> <div class="column"> <a href="retrostuff.html"> <img src="retrostuff.png" style="width:100%;"> </a> </div> <div class="column"> <a href="creations.html"> <img src="creations.png" style="width:100%;"> </a> </div> <div class="column"> <a href="pseudstuff.html"> <img src="pseudstuff.png" style="width:100%;"> </a> </div> <!-- Fixed: closed this column div --> <div class="column"> <a href="misc.html"> <img src="misc.png" style="width:100%;"> <!-- Fixed: changed to 100% width --> </a> </div> </div> </body>
A quick breakdown of the fixes:
- Closed the third
.columndiv so all four columns are properly side-by-side in the.row - Set the last image's width to 100% to match the others
- Fixed the
font-sizetypo on the heading - Cleaned up the
<br>tag and removed the redundant inline body background color (added a fallback in CSS instead) - Added
margin:0to the body to eliminate default browser spacing that might cause unexpected layout shifts
内容的提问来源于stack exchange,提问作者Blauheim44
相关产品推荐
相关产品推荐

