HTML section produces unexpected outcome

Hey there, I'm relatively new to the world of HTML and CSS. I have a question about using sections to display images on my website. I've noticed that when I use a div element in my HTML code, everything looks great. However, if I try to only use the section element instead, things start to look strange. Can anyone help me figure out how to make my HTML work with just the section element and not the div? Here is the CSS code I am working with:


#content2{
 margin: 30px 0;
 background: white;
 padding: 20px;
 clear: both;
 box-shadow: 0px 1px 1px #999;
 text-align: center;
 overflow:hidden;
}

.section {
 display: inline-block;
 margin: 0 10px;
}

.section a {
 color: orange;
 font-weight:bold;
 font-size: 1.5em;
 line-height: 1em;
 text-align: center;
 display: block;
}

.section p {
 color: black;
 font-weight:bold;
 font-size: 1.5em;
 line-height: 1em;
 text-align: center;
 display: block;
 padding-bottom: 2em;
}

Here is an example of my HTML code:

<div id="content2">
    <h4>Our Products</h4>
    <section class="section">
        <a href="../html/clothing.html#Pika"> Pika Blanket</a>
        <a href="../html/clothing.html#Pika"><img src="../images/NB1.jpg" /></a>
        <p>$19.99</p>
    </section>
    <section class="section">
        <a href="../html/clothing.html#City">City Boy</a>
        <a href="../html/clothing.html#City"><img src="../images/toddler1.jpg" /></a>
        <p>$249.99</p>
    </section>
    <section class="section">
        <a href="../html/clothing.html#Classy">Classy Girl</a>
        <a href="../html/clothing.html#Classy"><img src="../images/toddler9.jpg" /></a>
        <p>$244.99</p>
    </section>
     <section class="section">
        <a href="../html/clothing.html#Outdoors">Outdoors</a>
        <a href="../html/clothing.html#Outdoors"><img src="../images/girl1.jpg" /></a>
        <p>$129.99</p>
    </section>

</div>

Any assistance would be greatly appreciated!

Answer №1

Start by ensuring that you include <!DOCTYPE html> at the beginning of your page to specify the use of HTML5 (especially important for IE browsers).

Additionally, remember that <section> is not a block-level element like <div>.

To address this issue, include the following in your CSS for the .section class:

display: block

By doing this, your <section> element will function similarly to a <div>, resolving any display problems you may encounter.

Answer №2

Ensure that you have included the <!DOCTYPE html> declaration in your HTML file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Showing the overflow scroll bar on both iOS and Android mobile devices

Is it possible to make the overflow scrollbar visible on mobile devices, specifically iPhones, Samsungs, and Safari browsers? The scrollbar is currently visible on desktops but not on mobile devices. I need a solution for this issue. Here is the current c ...

Swap the particular term within the href attribute to .data()

Is there a way to dynamically update the CSS file being linked in my website based on radio button selections? Here's an example of what I am trying to achieve: <link id="custom-css" href="mysite/css/color1.css" rel="stylesheet" type="text/css"/&g ...

custom checkbox is not being marked as checked

I've been attempting to customize my checkboxes, following various tutorials without success. Despite trying multiple methods, I still can't get the checkboxes to check or uncheck. Here is the code I have so far: https://jsfiddle.net/NecroSyri/ ...

jquery is unable to fetch the input value from a dynamically generated field inside a function

Something peculiar keeps happening to me when I utilize jQuery, which is different from what others have encountered in the forums. Whenever I make an ajax call and generate an input element (on success), like so: Start Date: <input type="text" id="gr ...

Devices are not displaying media queries as expected

@media screen (max-width: 750px) or (screen and (max-width: 750px) (-webkit-min-device-pixel-ratio: 2),(min-resolution: 192dpi)) { div.body, div.body div.links, div.body div.links div, div.footer, div.footer div { display: block ...

Show a background picture while hovering on the main image

Is there a way to make the background image appear when hovering over the original image and disappear when no longer hovering? Below is a snippet of my HTML and CSS. Is there a straightforward CSS command to hide the original image or show the background ...

Safari displaying elements without following font styling specified in CSS

I have a select element in my web page, and I've customized the font using CSS: @font-face { font-family: myFont; src: url('myFont.woff'); } body select{ font-family: myFont; } After testing in Chro ...

How to Keep Bootstrap 3 Accordion Open Even When Collapsed

I am in the process of building an accordion group with bootstrap 3. Here is the code I have so far: <div id="accordion" class="panel-group"> <div class="panel panel-default"> <div class="panel-heading"> <div class ...

"Marquee animation functions correctly on the emulator but fails to display on the physical

Greetings! I recently incorporated a marquee tag into my application, and it functions properly in the Android simulator. However, once I install it on my device, the marquee does not display. Below is the code I used for the marquee: <marquee behavi ...

Triple-decker Angular Table CSS Layout

Please take a look at the code below, it is currently working properly. <div ng-repeat="download in productDownloads" class="container"> <div class="row"> <div class="cell"> <strong>{{download.productName}}</strong> </di ...

What is the best method to eliminate the 2px flaws on the right edge?

Issue only observed on small screens using Android Chrome (Nexus 5x, Nexus 6) with Android 5+. Cannot replicate problem on a Nexus 4. Utilizing basic bootstrap setup and angular; unsure if related. Experiencing artifacts up to 2px wide on the right side o ...

What is the best way to utilize :focus while simultaneously applying properties through Javascript?

When styling an input element with JavaScript, it seems that any properties set this way are ignored in a :focus rule. An example is provided to illustrate this: Initially, the background and border of the input element matches the surrounding element ( ...

picture located in the top corner of the page within the diva triangle shape

Is there a way to position my photo on the same level as a div and have it overlap slightly? <div id='triangle-topleft'> <img id="photo" src="photo.png"> </div> #triangle-topleft { width: 0; heigh ...

jqwidgets combobox not displaying correct colors

Looking at the image above, I am utilizing the default combo box of jqwidgets with jqx.base.css as the CSS file. The arrow mark on the combo is visible and the check boxes of the elements are checked in black color. I have tested this in IE10 and Chrome 21 ...

modify rectangular section in drupal rather than numerical block

Currently, I am attempting to modify blocks within my Drupal 7.x website using the Zen base theme. While I have been successful in adjusting the CSS styles of the blocks based on their numbers in the block.css file, I find this method quite confusing. Is ...

Aligning items in several columns

Setting up a grid layout where the content is centered can be tricky, but I've found a solution that works well. Take a look at the code snippet below: .outer { width: 100%; height: 100px; margin-top: 10px; m ...

Expansive HTML body width (exceeding 100%)

I am currently in the process of designing a horizontal webpage and I am aiming to create a dynamic body that expands based on the content it contains. You can view the website I am working on here: While everything is functioning as intended, I am strug ...

What is the best way to set the keyframes CSS value for an element to 0%?

Would like to create a progress indicator div using CSS animations? Check out the JSBin link provided. The desired behavior is to have the div width increase from 30% to 100% when the user clicks on stage3 after stage1, rather than starting from 0%. Althou ...

Conceal a Component within an Embedded Frame

Hey there! I've been attempting to hide a header within an iframe, but it seems like my code isn't doing the trick. Could someone take a look and help me diagnose why the header is still visible? Thanks in advance! <iframe id="booking_iframe" ...

A time-tracking counter that tallies the amount of time users spend on the webpage

I'm currently working on a code that tracks the time spent on a page starting from when it was clicked. My challenge now is figuring out how to capture the time when the submit button is clicked and store it in the database. < script > var ...