div不允许作为按钮的子元素 [英] div not allowed as child element of button

查看:51
本文介绍了div不允许作为按钮的子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几个主题,但仍然不了解有效的替代方法,它看起来像我想要的一样,但是我遇到验证错误,而且我不知道如何更改它.这是我正在使用的简单版本:

I've read several topics on this and still don't understand a valid alternative.Visually it appears just like I want it, but I'm getting validation errors and I don't know how to change it. Here's a simple version of what I'm using:

<button type="submit" onclick="window.location.href='events.html'">
    <div id="box1" class="eventContainer">
    <h3>CLICK ON ME!</h3>
    <p>Description</p>
    <img>
    </div>
</button> 

推荐答案

问题是按钮只能包含内联元素,而div是块元素.替代方法是使用跨度

The issue is that a button can contain only Inline Elements, and div is a Block Element. alternative is to use span

<button type="submit" onclick="window.location.href='events.html'">
    <span id="box1" class="eventContainer">
       <h3>CLICK ON ME!</h3>
       <p>Description</p>
       <img>
    </span>
</button> 

块级元素块级元素总是从新行开始,并占据可用的全部宽度(尽可能向左和向右伸展).

Block-level Elements A block-level element always starts on a new line and takes up the full width available (stretches out to the left and right as far as it can).

该元素是一个块级元素.

The element is a block-level element.

Examples of block-level elements:

<div>
<h1> - <h6>
<p>
<form>


内联元素内联元素不是从新行开始,而是仅占用必要的宽度.


Inline Elements An inline element does not start on a new line and only takes up as much width as necessary.

这是段落内的内联元素.
内联元素的示例:

This is an inline element inside a paragraph.
Examples of inline elements:

<span>
<a>
<img>

<div>元素

该元素是一个块级元素,通常用作其他HTML元素的容器.

The < div > Element

The element is a block-level element that is often used as a container for other HTML elements.

该元素没有必需的属性,但是样式和类是常见的.

The element has no required attributes, but style and class are common.

与CSS一起使用时,该元素可用于设置内容块的样式:

When used together with CSS, the element can be used to style blocks of content:

示例

<div style="background-color:black; color:white; padding:20px;">

<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>

</div>

可以在此处

这篇关于div不允许作为按钮的子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆