CSS实现DIV定位:Web应用my-ad样式问题求助(字体与边框报错)
Hey Sanjay, let's get that my-ad div styled exactly like you need! I’ve put together a targeted CSS solution that fixes the font and border issues you mentioned, while hitting all your requirements:
Full CSS Code
.my-ad { /* Define border with explicit width, style, and color (adjust values as needed) */ border: 1px solid #333; /* Add 10px padding around the text to space it from the border */ padding: 10px; /* Set Tahoma as primary font, with a fallback for compatibility */ font-family: Tahoma, sans-serif; /* Optional tweaks to match your design (adjust as needed) */ font-size: 16px; color: #000; }
Breakdown of Fixes & Details:
- Padding: The
padding: 10px;rule adds 10px of space on all sides between the "Hello Coder" text and the div's border—this directly addresses your spacing requirement. - Tahoma Font Issue: I added
sans-serifas a fallback because if a user’s system doesn’t have Tahoma installed, the browser will default to a system sans-serif font instead of ignoring the rule entirely. If you still don’t see Tahoma rendering, check if another CSS rule (like one with higher specificity) is overriding this font setting. You can temporarily add!importantto the font-family line to test this, but aim to adjust selector weights long-term instead. - Border Width Problem: Borders won’t display properly unless you define all three properties: width, style, and color. The shorthand
border: 1px solid #333;takes care of this—swap1pxfor your desired width,solidfor other styles likedashedordotted, and#333for your preferred color.
Example HTML Structure
Make sure your div uses the correct class name:
<div class="my-ad"> Hello Coder </div>
内容的提问来源于stack exchange,提问作者Sanjay
相关产品推荐
相关产品推荐

